springMVC学习记录
2013-11-26 11:13
351 查看
general.jsp
hello.jsp
index.jsp
template.jsp
web.xml
test-servlet.xml
CommandTestController.java(控制器)
package controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import entity.User;
import global.Common;
@Controller
@RequestMapping(value="/d3")
public class CommandTestController{ //extends AbstractCommandController{
@RequestMapping(value={"/info","/general"}, method = RequestMethod.POST)
public ModelAndView test(HttpServletRequest req, HttpServletResponse resp, User user) {
Common.print(this);
ModelAndView mv = new ModelAndView();
mv.addObject("user", user);
boolean a = mv.hasView();
mv.setViewName("hello");
return mv;
}
}
<%@ page language="java" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <c:set var="project_name" scope="session">zshの白老鼠</c:set> <c:set var="project_url" scope="session">http://localhost:8080/Kata</c:set> <c:set var="encoding" scope="session">UTF-8</c:set>
hello.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ include file="general.jsp" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>${project_name}</title> </head> <body> ${user.userName} <br /> ${user.userPwd} </body> </html>
index.jsp
<%@ page language="java" pageEncoding="UTF-8"%> <%@ include file="general.jsp" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=${encoding}"> <title>${project_name}</title> <style> .border{border:1px solid red;} .center{text-align:center;} #mainBody{margin:auto auto;width:1024px;height:768px;} #box1{margin:auto auto;width:400px;height:200px;} </style> </head> <body> <div id="mainBody" class="border"> <div id="box1" class="border"> <form action="${project_url}/d3/info" method="post"> <table> <tr> <td>账号</td> <td><input type="text" name="userName" /></td> </tr> <tr> <td>密码</td> <td><input type="password" name="userPwd" /></td> </tr> <tr> <td colspan="2" class="center"><input type="submit" value="登录" /></td> </tr> </table> </form> </div> </div> </body> </html>
template.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ include file="general.jsp" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>${project_name}</title> </head> <body> 这是hello.jsp<br /> ${message} <br /> version : ${version} </body> </html>
web.xml
<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>Kata</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- filter --> <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- filter_end --> <!-- servlet --> <servlet> <servlet-name>test</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>test</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- servlet_end --> </web-app>
test-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> <!-- HandlerMapping --> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/> <!-- HandlerAdapter --> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/> <!-- ViewResolver --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/"/> <property name="suffix" value=".jsp"/> </bean> <!-- 处理器 --> <bean class="controller.CommandTestController" /> </beans>
CommandTestController.java(控制器)
package controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import entity.User;
import global.Common;
@Controller
@RequestMapping(value="/d3")
public class CommandTestController{ //extends AbstractCommandController{
@RequestMapping(value={"/info","/general"}, method = RequestMethod.POST)
public ModelAndView test(HttpServletRequest req, HttpServletResponse resp, User user) {
Common.print(this);
ModelAndView mv = new ModelAndView();
mv.addObject("user", user);
boolean a = mv.hasView();
mv.setViewName("hello");
return mv;
}
}
相关文章推荐
- SpringMVC学习记录(五)--表单标签
- SpringMVC学习记录1
- SpringMVC学习记录5
- SpringMVC学习记录2
- springmvc学习记录----springmvc的文件上传和下载
- SpringMVC学习记录(六)--Validator验证
- springMVC注解学习记录
- SpringMVC学习记录
- SpringMVC学习记录4
- SpringMVC学习记录--Validator验证分析
- SpringMVC学习记录(八)--开发中的小问题
- SpringMVC学习记录(七)--拦截器的使用
- SpringMVC学习记录(七)--拦截器的使用
- SpringMVC学习记录(六)--Validator验证
- SpringMVC学习记录(六)--Validator验证
- SpringMvc学习记录
- SpringMVC学习记录(七)--拦截器的使用
- SpringMVC学习记录(六)--Validator验证
- SpringMVC学习记录
- 只是简单记录自己学习的springmvc