Younger brother newly Spring3mvc, prawn please detour.
The development environment is as follows:
Os:windows
ide:eclipse3.7.2 First step, create a new Web project:
in the second step, add the Springframework dependent jar package:
Where Commons-logging-1.1.1.jar is the spring log-dependent jar package, Jstl-api-1.2.jar and Jstl-impl-1.2.jar are Oracle's official JSTL interface and implementation, if you choose Apche. The third step is to modify Web. XML to achieve Spring control:
<?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xmlns:web= "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi: schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id= "Webapp_ ID "version=" 2.5 "> <display-name>Spring3mvc</display-name> <!-- Add SPRING3 Controller and mapping rules- <servlet> <servlet-name>spring3mvc</ servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet </servlet-class> <load-on-startup>1</load-on-startup> < /servlet> <servlet-mapping> <servlet-name>spring3mvc</ servlet-name> <url-pattern>/app/*</url-pattern> &NBSp </servlet-mapping> <!--by default jump to the root of the page, here is index.jsp----- < welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
Fourth Step, add the spring configuration file whose file name matches the name in <servlet-name></servlet-name> in Web. 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:p= "http://www.springframework.org/schema/p" 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.0.xsd http://www.springframework.org/schema/ Context http://www.springframework.org/schema/context/spring-context-3.0.xsd /http
WWW.SPRINGFRAMEWORK.ORG/SCHEMA/MVC Http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd > <!--default scanned package path-- <context:component-scan base-package= "Cn.org.s Partacus.spring "/> <!--add note drivers- <mvc:annotation-driven/> &NBsp <!--define the prefix of the jump file-- <bean id= "Viewresolver" class= " Org.springframework.web.servlet.view.InternalResourceViewResolver "> <property name = "prefix" value= "/web-inf/jsp/"/> <property name= "suffix" value= ". jsp"/> &NB Sp </bean> </beans>
Fifth step, complete the front and rear code:
First, create a new JSP package under Web-inf, corresponding to the values in the prefix above, and create a new JSP file within the package, name whatever, here I call it success.jsp.
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Secondly, write the background code, the package path is usually the company domain name, I write here casually, as follows:
/**
* Project name: SPRING3MVC Demo
* copyright©2010-2012 spartacus.org.cn All rights Reserved */
package
cn.org.spartacus.spring;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;
/** *
Description:todo
* @author Hankaibo
* @date 2012-11-4
* @version v1.0
* * @Controller
@RequestMapping ("index") public
class Indexcontroller {
@RequestMapping ("HelloWorld")
public String HelloWorld () {
//return "success";//Jump to Success page
return "index";
}
}
sixth step, verify.
First write the root directory of the index.jsp page, and implement the jump, the file content is as follows:
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%>
<% @taglib prefix=" C "uri=" Http://java.sun.com/jsp/jstl/core "%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Finally, open the browser, enter the address, verify.
The test was successful, ^_^.