1、MVC
2、SpringMVC
1、導(dǎo)包;
2、添加spring的配置文件;
3、配置DispatcherServlet(與web.xml中配置);
4、寫Controller(處理器);
5、寫JSP;
1、導(dǎo)包
使用maven導(dǎo)包,在maven配置文件pom.xml配置如下(使用阿里云的mavev):
4.0.0
cn.qiuuuu
springmvc
0.0.1-SNAPSHOT
war
junit
junit
4.10
test
org.statefulj.framework
statefulj-framework-binders-springmvc
2.1
javadoc
導(dǎo)包完成后,會在Maven Dependencies中多出maven基礎(chǔ)依賴包
2、添加spring配置文件
在項目的src/main/resources中新建一個xml文件來作為spring的配置文件,命名為:spring.xml,寫入:
3、配置DispatcherServlet
在項目的web.xml中配置一個servlet:
springmvc
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc.xml
1
springmvc
*.do
4、寫Controller
package test;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class ControllerHello implements Controller{
public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
System.out.println("handleRequest()");
return new ModelAndView("hello");
}
}
5、寫一個JSP
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
Insert title here
Hello SpringMVC!
6、再次配置spring.xml
helloController
將springhello部署到tongcat服務(wù)器,然后在瀏覽器中輸入http://localhost:8089/hellospring/hello.do 訪問
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。