標籤:intern ted jar包下載 val targe cat tco ica star
一、建立java Web 專案
二、添加jar包
spring jar包http://repo.spring.io/release/org/springframework/spring/
2.1、匯入jar包
先不管哪些包的具體作用,直接全部匯入。
三、配置web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app> <display-name>Archetype Created Web Application</display-name> <!-- 所有的請求都會被dispatherservlet捕獲 --> <servlet> <servlet-name>springmvc</servlet-name> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/springmvc-servlet.xml</param-value> </init-param> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping></web-app>
四、建立一個控制器
package springmvc;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.AbstractController;public class welcomeController extends AbstractController {@Overrideprotected ModelAndView handleRequestInternal(HttpServletRequest arg0,HttpServletResponse arg1) throws Exception {// TODO Auto-generated method stubSystem.out.print("hello springmvc");return null;}}
五、建立springmvc-servlet.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean><bean name="/welcome.html" class="springmvc.welcomeController"></bean> <!-- 視圖解釋類 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/JSP/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
六、Look
Java 系列之spring學習--springmvc搭建(四)