标签:jsp path return ns-3 tps display 业务 work mil
springmvc属于spring框架的后续产品,用在基于MVC的表现层开发,类似于struts2框架
导入springioc,springweb , springmvc相关的jar包
在/WEB-INF/下创建web.xml文件
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>springMVCone</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- 注册springmvc核心控制器 --> <servlet> <servlet-name>DispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 通知DispatcherServlet去指定的目录下加载springmvc.xml配置文件 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:DispatcherServlet-servlet.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>DispatcherServlet</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping> </web-app>
创建HelloAction.java控制器类
/** * 控制器 * @author AdminTC */ public class HelloAction implements Controller{ /** * 业务方法 */ public ModelAndView handleRequest(HttpServletRequest requqest,HttpServletResponse response) throws Exception { ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("message","这是我的第一个springmvc应用程序"); modelAndView.setViewName("/jsp/success.jsp"); return modelAndView; } }
DispatcherServlet-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: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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd "> <bean name="/hello.action" class="a.HellowAction"></bean> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 前置 --> <property name="prefix" value="/WEB-INF/jsp/" /> <!-- 后置 --> <property name="suffix" value=".jsp" /> </bean> </beans>
标签:jsp path return ns-3 tps display 业务 work mil
原文地址:http://www.cnblogs.com/lm970585581/p/7382804.html