spring MVC demo
spring mvc 的简单配置示例 1、配置web.xml <servlet> <servlet-name>dispatcherContext</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherContext</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> 2、在web.xml同路径下配置servlet-name一直的servlet-xml文件 dispatcherContext-servlet.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!-- 处理器映射器,使用处理器名字作为URL --> <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean> <bean name="/hello.do" class="com.linkage.justone4.test.SpringMvcAction"> <property name="name" value="cheng ren yin" /> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </beans> 3、action实现 AbstractController public class SpringMvcAction extends AbstractController { private String name ; @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("come on ... spring mvc config ...."); return new ModelAndView("MyJsp","name",name); } public String getName() { return name; } public void setName(String name) { this.name = name; } } 4、MyJsp.jsp 在/WEB-INF/jsp/MyJsp.jsp 目录下,增加jstl的jar包 jsp - <from action="hell.do" ..... 返回 MyJsp.jsp
相关推荐
yupi0 2020-10-10
spring 2020-08-18
编程点滴 2020-07-29
幸运小侯子 2020-07-05
itjavashuai 2020-07-04
qingjiuquan 2020-06-29
shushan 2020-06-25
小鱿鱼 2020-06-22
咻pur慢 2020-06-18
melonjj 2020-06-17
qingjiuquan 2020-06-13
neweastsun 2020-06-05
小鱿鱼 2020-06-05
mxcsdn 2020-05-31
吾日五省我身 2020-05-27
牧场SZShepherd 2020-05-27
sweetgirl0 2020-05-14