Skip to content

Commit 8f0b95c

Browse files
committed
Front page coding using Spring MVC
1 parent 13d245d commit 8f0b95c

File tree

15 files changed

+602
-339
lines changed

15 files changed

+602
-339
lines changed

.idea/artifacts/greenLand_war_exploded.xml

Lines changed: 0 additions & 13 deletions
This file was deleted.

.idea/artifacts/rainbow_war_exploded.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Maven__jstl_jstl_1_2.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 405 additions & 318 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,12 @@
9393
<version>1.8.10</version>
9494
</dependency>
9595

96+
<dependency>
97+
<groupId>jstl</groupId>
98+
<artifactId>jstl</artifactId>
99+
<version>1.2</version>
100+
</dependency>
101+
102+
96103
</dependencies>
97104
</project>

rainbow.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.24" level="project" />
6060
<orderEntry type="library" name="Maven: org.aspectj:aspectjrt:1.8.10" level="project" />
6161
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.8.10" level="project" />
62+
<orderEntry type="library" name="Maven: jstl:jstl:1.2" level="project" />
6263
</component>
6364
<component name="TemplatesService">
6465
<option name="TEMPLATE_FOLDERS">

src/main/java/Utility/RedisCacheImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
@Component("redisCache")
1818
public class RedisCacheImpl <V> implements RedisCache<String, V> {
1919

20-
static{
21-
PropertyConfigurator.configure("log4j.properties");
22-
}
20+
// static{
21+
// PropertyConfigurator.configure("log4j.properties");
22+
// }
2323

2424
private static Logger logger = Logger.getLogger(RedisCacheImpl.class);
2525
private final int EXPIRE_TIME = 3600 * 24;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package controller;
2+
3+
import domain.UserInfo;
4+
import org.apache.log4j.Logger;
5+
import org.springframework.stereotype.Controller;
6+
import org.springframework.ui.ModelMap;
7+
import org.springframework.web.bind.annotation.ModelAttribute;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RequestMethod;
10+
import org.springframework.web.servlet.ModelAndView;
11+
12+
/**
13+
* Created by pengfei on 2017/9/22.
14+
*/
15+
@Controller
16+
public class LoginController {
17+
18+
private final static Logger logger=Logger.getLogger(LoginController.class);
19+
20+
@RequestMapping(value = "/login", method = RequestMethod.GET)
21+
public ModelAndView get(){
22+
logger.info("Inside login get method");
23+
return new ModelAndView("login","command",new UserInfo());
24+
}
25+
26+
@RequestMapping(value = "/loginHere",method=RequestMethod.POST)
27+
public String login(@ModelAttribute UserInfo user, ModelMap model){
28+
logger.info("Login controller begin service");
29+
30+
model.addAttribute("password",user.getPassword());
31+
model.addAttribute("name",user.getName());
32+
33+
if(user.getPassword()==null)
34+
throw new RuntimeException("Password should not be null!");
35+
36+
logger.info("Login controller end service!");
37+
38+
return "homePage";
39+
}
40+
41+
@RequestMapping(value="/toLoginPage",method = RequestMethod.GET)
42+
public String redirect(){
43+
return "redirect:login";
44+
}
45+
46+
@RequestMapping(value = "/visitStaticPage",method = RequestMethod.GET)
47+
public String visitStaticPage(){
48+
49+
return "redirect:/pages/static.html";
50+
}
51+
52+
53+
}

src/main/java/controller/UserController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
*/
1414

1515
@Controller
16-
@RequestMapping()
1716
public class UserController {
1817

1918
@Resource
2019
private UserService userService;
2120

2221
@RequestMapping(value = "/hello")
2322
public ModelAndView helloWorld() {
24-
ModelAndView mv = new ModelAndView("/hello");
23+
ModelAndView mv = new ModelAndView("hello");
2524
UserInfo user = userService.getUserInfo(3);
2625
mv.addObject("message", user.getComment());
2726
return mv;

src/main/java/domain/UserInfo.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ public class UserInfo {
88
private String name;
99
private double salary;
1010
private String comment;
11+
private String password;
12+
13+
public UserInfo() {
14+
15+
}
16+
17+
public UserInfo(int id, String name) {
18+
this.id = id;
19+
this.name = name;
20+
}
1121

1222
public int getId() {
1323
return id;
@@ -41,5 +51,13 @@ public void setComment(String comment) {
4151
this.comment = comment;
4252
}
4353

54+
public String getPassword() {
55+
return password;
56+
}
57+
58+
public void setPassword(String password) {
59+
this.password = password;
60+
}
61+
4462

4563
}

src/main/resources/spring-mvc/spring-servlet.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
<mvc:annotation-driven />
88
<context:component-scan base-package="controller"/>
99

10+
<mvc:resources mapping="/pages/**" location="WEB-INF/pages/" />
11+
1012
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
11-
<property name="prefix" value="/WEB-INF/jsp"></property>
13+
<property name="prefix" value="/WEB-INF/jsp/"></property>
1214
<property name="suffix" value=".jsp"></property>
1315
</bean>
1416

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<%--
2+
Created by IntelliJ IDEA.
3+
User: pengfei
4+
Date: 2017/9/22
5+
Time: 13:13
6+
To change this template use File | Settings | File Templates.
7+
--%>
8+
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
9+
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
10+
<html>
11+
<head>
12+
<title>Horizon WorkSpace Page</title>
13+
</head>
14+
<body>
15+
<h1>Horizon WorkSpace Page!</h1>
16+
<hr>
17+
18+
<table>
19+
<tr>
20+
<td>ID:</td>
21+
<td>${name}</td>
22+
</tr>
23+
<tr>
24+
<td>Name:</td>
25+
<td>${password}</td>
26+
</tr>
27+
<tr>
28+
<td><input type="date"></td>
29+
</tr>
30+
</table>
31+
32+
<div>
33+
<form action="visitStaticPage" method="get">
34+
<br>
35+
<input type="submit" value="Visit Static Page">
36+
</form>
37+
</div>
38+
39+
</body>
40+
</html>

src/main/webapp/WEB-INF/jsp/login.jsp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<%--
2+
Created by IntelliJ IDEA.
3+
User: pengfei
4+
Date: 2017/9/22
5+
Time: 1:04
6+
To change this template use File | Settings | File Templates.
7+
--%>
8+
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
9+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
10+
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
11+
<html>
12+
<head>
13+
<title>Login Page</title>
14+
</head>
15+
<body>
16+
Welcome back! User
17+
<%--${time}--%>
18+
<%--<c:forEach items="${users}" var="user" >--%>
19+
<%--ID: ${user.id} Name:${user.name} <br/>--%>
20+
<%--</c:forEach>--%>
21+
<form:form method="post" action="/loginHere">
22+
<table>
23+
<tr>
24+
<td><form:label path="name">User Name:</form:label></td>
25+
<td><form:input path="name"/></td>
26+
</tr>
27+
<tr>
28+
<td><form:label path="password">Password:</form:label></td>
29+
<td><form:password path="password"/></td>
30+
</tr>
31+
<tr>
32+
<td colspan="2">
33+
<input type="submit" value="Submit">
34+
</td>
35+
</tr>
36+
</table>
37+
</form:form>
38+
39+
</body>
40+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Static Page</title>
6+
</head>
7+
<body>
8+
This is static page!
9+
</body>
10+
</html>

src/main/webapp/index.jsp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
pageEncoding="UTF-8" %>
33
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>
44
<body>
5-
<h2>Hello World!</h2>
6-
<a href="/hello">Say hello</a>
5+
<h2>Horizon Index Page</h2>
6+
Horizon index page, welcome back, user!
7+
<form action="/toLoginPage" method="get">
8+
<br>
9+
<input type="submit" value="Login in here"/>
10+
</form>
711

812
</body>
913
</html>

0 commit comments

Comments
 (0)