Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<!-- <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.2</version>
</dependency> -->
<!-- <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId>
<version>2.6.2</version> </dependency> -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
Expand All @@ -64,6 +61,17 @@
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
<build>
<finalName>SprinMvc</finalName>
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/cn/lonecloud/controller/ErrorController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cn.lonecloud.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import cn.lonecloud.entity.User;
/**
* @SessionAttribute 中标明了一个名字为user 对象
* @Title: ErrorController.java
* @Package cn.lonecloud.controller
* @Description:
* @author lonecloud
* @date 2017年4月12日 下午8:01:56
*/
@SessionAttributes(value="user",types=String.class)
@Controller
public class ErrorController {

@RequestMapping("/testError")
public String testError(@ModelAttribute("user")User user){
System.out.println("user"+user);
return "testError";
}
}
2 changes: 2 additions & 0 deletions src/main/resources/I18n_en_US.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
i18n.username=username
i18n.password=password
2 changes: 2 additions & 0 deletions src/main/resources/I18n_zh_CN.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
i18n.username=\u7528\u6237\u540D
i18n.password=\u5BC6\u7801
9 changes: 7 additions & 2 deletions src/main/resources/SpringMvc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<!-- 一般会将这个注解加上去 -->
<mvc:annotation-driven />
<mvc:default-servlet-handler />
<!-- 启用spring mvc 注解 -->
Expand Down Expand Up @@ -36,5 +36,10 @@
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean name="/hello" class="cn.lonecloud.controller.HelloController"></bean>
<!-- 配置国际化资源文件 -->
<bean id="resourceBundleMessageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="i18n"></property>
</bean>
<!-- 配置直接转发的页面 -->
<mvc:view-controller path="/success" view-name="user"/>
</beans>
27 changes: 27 additions & 0 deletions src/main/webapp/WEB-INF/jsp/testError.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%@ 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<p>${test }</p>
<form action="${pageContext.request.contextPath }/testUser" method="post">
用户名:<input name="username"><br>
密码:<input name="password"><br>
年龄:<input name="age"><br>
address:<input name="address.city"><br>
<button type="submit">提交</button>
</form>
<p>修改用户</p>
<form action="${pageContext.request.contextPath }/testError" method="post">
用户名:<input name="username" value="${user.username }"><br>
密码:<input name="password" value="${user.password }"><br>
年龄:<input name="age" value="${user.age }"><br>
address:<input name="address.city" value="${user.address.city }"><br>
<button type="submit">提交</button>
</form>
</body>
</html>
5 changes: 3 additions & 2 deletions src/main/webapp/WEB-INF/jsp/user.jsp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
Expand All @@ -17,8 +18,8 @@
</form>
<p>修改用户</p>
<form action="${pageContext.request.contextPath }/testUser" method="post">
用户名:<input name="username" value="${user.username }"><br>
密码:<input name="password" value="${user.password }"><br>
<fmt:message key="i18n.username"></fmt:message>:<input name="username" value="${user.username }"><br>
<fmt:message key="i18n.password"></fmt:message>:<input name="password" value="${user.password }"><br>
年龄:<input name="age" value="${user.age }"><br>
address:<input name="address.city" value="${user.address.city }"><br>
<button type="submit">提交</button>
Expand Down