From 8920c73a35ab1457d501a05e546fa6a105740921 Mon Sep 17 00:00:00 2001 From: zhantaojava Date: Wed, 23 Sep 2015 17:18:47 -0400 Subject: [PATCH 01/19] =?UTF-8?q?1.=E8=B7=B3=E8=BD=AC=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=202.userBeanProcess=20=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=203.login=20work?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_Web_System/WebRoot/index.jsp | 6 ++++++ 1_Web_System/WebRoot/login.jsp | 5 +++-- 1_Web_System/src/model/UserBeanProcess.java | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 1_Web_System/src/model/UserBeanProcess.java diff --git a/1_Web_System/WebRoot/index.jsp b/1_Web_System/WebRoot/index.jsp index ee20dc3..c255771 100644 --- a/1_Web_System/WebRoot/index.jsp +++ b/1_Web_System/WebRoot/index.jsp @@ -23,6 +23,12 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. This is my JSP page.
+ <% + if(request.getAttribute("erro")!=null){ + out.println(request.getAttribute("erro")); + } %> + + ${message } diff --git a/1_Web_System/WebRoot/login.jsp b/1_Web_System/WebRoot/login.jsp index 74abc52..88beb9f 100644 --- a/1_Web_System/WebRoot/login.jsp +++ b/1_Web_System/WebRoot/login.jsp @@ -25,8 +25,9 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
Spring Test
-
- UserName:
+ + UserName:
+ PassWord:
diff --git a/1_Web_System/src/model/UserBeanProcess.java b/1_Web_System/src/model/UserBeanProcess.java new file mode 100644 index 0000000..1871a64 --- /dev/null +++ b/1_Web_System/src/model/UserBeanProcess.java @@ -0,0 +1,15 @@ +package model; + +public class UserBeanProcess { + public boolean CheckUser(String username,String password){ + boolean b=false; + + if(username.equals("szt")&&password.equals("123")){ + b=true; + } + + return b; + + + } +} From 1403bd607204428ff0dad0fd79f93ad5ee79a686 Mon Sep 17 00:00:00 2001 From: zhantaojava Date: Wed, 23 Sep 2015 23:34:15 -0400 Subject: [PATCH 02/19] =?UTF-8?q?1.Form=20method=20post=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E4=BF=A1=E6=81=AF=E9=87=8F=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=B8=94=E9=9A=90=E8=97=8F=E4=BA=86=E4=BF=A1=E6=81=AF=E5=86=85?= =?UTF-8?q?=E5=AE=B9=202.=E8=B7=B3=E8=BD=AC=E5=90=8E=E9=99=84=E5=B8=A6?= =?UTF-8?q?=E4=BA=86error=20=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_Web_System/WebRoot/index.jsp | 5 --- 1_Web_System/WebRoot/login.jsp | 6 ++-- 1_Web_System/WebRoot/wel.jsp | 40 +++++++++++++++++++++ 1_Web_System/src/dao/HibernateDao.java | 7 ++-- 1_Web_System/src/model/UserBeanProcess.java | 39 +++++++++++++++----- 1_Web_System/src/test/TestClass.java | 2 +- 6 files changed, 79 insertions(+), 20 deletions(-) create mode 100644 1_Web_System/WebRoot/wel.jsp diff --git a/1_Web_System/WebRoot/index.jsp b/1_Web_System/WebRoot/index.jsp index c255771..035da9d 100644 --- a/1_Web_System/WebRoot/index.jsp +++ b/1_Web_System/WebRoot/index.jsp @@ -23,11 +23,6 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. This is my JSP page.
- <% - if(request.getAttribute("erro")!=null){ - out.println(request.getAttribute("erro")); - } %> - ${message } diff --git a/1_Web_System/WebRoot/login.jsp b/1_Web_System/WebRoot/login.jsp index 88beb9f..dea2842 100644 --- a/1_Web_System/WebRoot/login.jsp +++ b/1_Web_System/WebRoot/login.jsp @@ -25,13 +25,15 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
Spring Test
-
+ UserName:
PassWord:
+

+ ${ErrorMessage }
- + diff --git a/1_Web_System/WebRoot/wel.jsp b/1_Web_System/WebRoot/wel.jsp new file mode 100644 index 0000000..116bb30 --- /dev/null +++ b/1_Web_System/WebRoot/wel.jsp @@ -0,0 +1,40 @@ +<%@ page language="java" import="java.util.*" pageEncoding="US-ASCII"%> +<% +String path = request.getContextPath(); +String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; +%> + + + + + + + My JSP 'wel.jsp' starting page + + + + + + + + + + + +
+ Welcome
+ + <% + HttpSession hs=request.getSession(); + String username=(String)hs.getAttribute("user"); + + if(username!=null){ + out.println("Welcome you: "+username); + } + %> +
+ + + diff --git a/1_Web_System/src/dao/HibernateDao.java b/1_Web_System/src/dao/HibernateDao.java index 790fa4a..9fc8de7 100644 --- a/1_Web_System/src/dao/HibernateDao.java +++ b/1_Web_System/src/dao/HibernateDao.java @@ -22,9 +22,8 @@ public class HibernateDao { * * @param username * @param password - * @return + * @return user */ - @SuppressWarnings("deprecation") public List searchUser(String username) { Configuration configuration = new Configuration(); configuration.configure(); @@ -43,12 +42,12 @@ public List searchUser(String username) { query.setString("name", username); List list = query.list(); - // List list = session.createQuery("from User").list(); - session.getTransaction().commit(); return list; } + + } diff --git a/1_Web_System/src/model/UserBeanProcess.java b/1_Web_System/src/model/UserBeanProcess.java index 1871a64..521a300 100644 --- a/1_Web_System/src/model/UserBeanProcess.java +++ b/1_Web_System/src/model/UserBeanProcess.java @@ -1,15 +1,38 @@ package model; +import java.util.LinkedList; +import java.util.List; + +import org.junit.Test; + +import dao.HibernateDao; + public class UserBeanProcess { - public boolean CheckUser(String username,String password){ - boolean b=false; - - if(username.equals("szt")&&password.equals("123")){ - b=true; + private HibernateDao hibernateDao=new HibernateDao(); + + /** + * + * @param username + * @param password + * @return + */ + public boolean ValidateUser(String username,String password){ + boolean b = false; + + List list = new LinkedList(); + + list = hibernateDao.searchUser(username); + + User user = new User(); + + if (!list.isEmpty()) { + user = list.get(0); + if (user.getPw().equals(password)) { + b = true; + return b; + } } - + return b; - - } } diff --git a/1_Web_System/src/test/TestClass.java b/1_Web_System/src/test/TestClass.java index b9f6542..199ba6d 100644 --- a/1_Web_System/src/test/TestClass.java +++ b/1_Web_System/src/test/TestClass.java @@ -12,7 +12,7 @@ public static void main(String[] args) { HibernateDao h=new HibernateDao(); List list=new ArrayList(); list=h.searchUser("1"); - + System.out.println(list.get(0)); } } From 11f1126caaf76d390ab7f89b2562fcc0c08cf6a4 Mon Sep 17 00:00:00 2001 From: zhantaojava Date: Thu, 24 Sep 2015 00:58:33 -0400 Subject: [PATCH 03/19] =?UTF-8?q?1.=E5=AE=9E=E7=8E=B0=E4=BA=86=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=94=A8=E6=88=B7=E5=8A=9F=E8=83=BD=202.UserBeanProce?= =?UTF-8?q?ss=E5=A2=9E=E5=8A=A0=E4=BA=86AddUser=20method=203.HibernateDao?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=E4=BA=86Add=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用modelandview 实现了传递参数,并且在wel.jsp里用占位符把传递的参数显示出来 --- 1_Web_System/WebRoot/login.jsp | 6 ++- 1_Web_System/WebRoot/register.jsp | 45 +++++++++++++++++++++ 1_Web_System/WebRoot/wel.jsp | 14 ++++++- 1_Web_System/src/dao/HibernateDao.java | 26 +++++++++++- 1_Web_System/src/model/UserBeanProcess.java | 41 ++++++++++++++++++- 5 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 1_Web_System/WebRoot/register.jsp diff --git a/1_Web_System/WebRoot/login.jsp b/1_Web_System/WebRoot/login.jsp index dea2842..e83faba 100644 --- a/1_Web_System/WebRoot/login.jsp +++ b/1_Web_System/WebRoot/login.jsp @@ -28,8 +28,12 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
UserName:
PassWord:
- + +
+
+ +


${ErrorMessage } diff --git a/1_Web_System/WebRoot/register.jsp b/1_Web_System/WebRoot/register.jsp new file mode 100644 index 0000000..c9f754a --- /dev/null +++ b/1_Web_System/WebRoot/register.jsp @@ -0,0 +1,45 @@ +<%@ page language="java" import="java.util.*" pageEncoding="US-ASCII"%> +<% +String path = request.getContextPath(); +String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; +%> + + + + + + + My JSP 'register.jsp' starting page + + + + + + + + + + + +
+ + Please Fill The Form +
+ + + + + + + + + + + +
UserName
PassWord
Age


+
+
+ + diff --git a/1_Web_System/WebRoot/wel.jsp b/1_Web_System/WebRoot/wel.jsp index 116bb30..bec2a8f 100644 --- a/1_Web_System/WebRoot/wel.jsp +++ b/1_Web_System/WebRoot/wel.jsp @@ -33,7 +33,19 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. if(username!=null){ out.println("Welcome you: "+username); } - %> + + + %>
+ + ${statue }

+ + Username:${username }
+ + Age:${age }
+
+ Back + + diff --git a/1_Web_System/src/dao/HibernateDao.java b/1_Web_System/src/dao/HibernateDao.java index 9fc8de7..3ba30eb 100644 --- a/1_Web_System/src/dao/HibernateDao.java +++ b/1_Web_System/src/dao/HibernateDao.java @@ -45,9 +45,31 @@ public List searchUser(String username) { session.getTransaction().commit(); return list; + + } + + /** + * @author suzhantao + * @param user + * : user instance 哈哈 + * @return obj: save的返回值为一个obj,用来判断是否save成功 + */ + public Object save(User user) { + Configuration configuration = new Configuration(); + configuration.configure(); + serviceRegistry = new ServiceRegistryBuilder().applySettings( + configuration.getProperties()).buildServiceRegistry(); + sessionFactory = configuration.buildSessionFactory(serviceRegistry); + + Session session = sessionFactory.getCurrentSession(); + session.beginTransaction(); + + Object obj = session.save(user); + + session.getTransaction().commit(); + + return obj; } - - } diff --git a/1_Web_System/src/model/UserBeanProcess.java b/1_Web_System/src/model/UserBeanProcess.java index 521a300..d1a8736 100644 --- a/1_Web_System/src/model/UserBeanProcess.java +++ b/1_Web_System/src/model/UserBeanProcess.java @@ -1,12 +1,17 @@ package model; +import java.util.Date; import java.util.LinkedList; import java.util.List; import org.junit.Test; import dao.HibernateDao; - +/** + * Function same as Service Layer + * @author suzhantao + * + */ public class UserBeanProcess { private HibernateDao hibernateDao=new HibernateDao(); @@ -35,4 +40,38 @@ public boolean ValidateUser(String username,String password){ return b; } + + public boolean AddUser(String username,String password,int age){ + boolean statue=false; + + + //determine if the user existing + List list = new LinkedList(); + list=hibernateDao.searchUser(username); + + User user=new User(); + user.setName(username); + + boolean userExisting=list.contains(user); + + Date date=new Date(); + + //if user not existing ,execute saving + if(userExisting==false){ + user.setAge(age); + user.setPw(password); + user.setDate(date); + + Object object=hibernateDao.save(user); + statue=true; + return statue; + } + else{ + return statue; + } + + + } + + } From 3656fa30f3350384c97d4d631ab303564cb35110 Mon Sep 17 00:00:00 2001 From: zhantaojava Date: Thu, 24 Sep 2015 17:42:34 -0400 Subject: [PATCH 04/19] =?UTF-8?q?1.=E5=AE=9E=E7=8E=B0wel.jsp=20=E5=B1=95?= =?UTF-8?q?=E7=8E=B0=E8=A7=86=E5=9B=BE=E5=8A=9F=E8=83=BD=202.=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BA=86HibernateDao=E4=B8=AD=20SearchPageCount(pageS?= =?UTF-8?q?ize);?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_Web_System/WebRoot/wel.jsp | 65 +++++++++++++++++++++++++- 1_Web_System/src/dao/HibernateDao.java | 63 +++++++++++++++++++++++++ 1_Web_System/src/test/TestClass.java | 13 +++++- 3 files changed, 138 insertions(+), 3 deletions(-) diff --git a/1_Web_System/WebRoot/wel.jsp b/1_Web_System/WebRoot/wel.jsp index bec2a8f..aad774c 100644 --- a/1_Web_System/WebRoot/wel.jsp +++ b/1_Web_System/WebRoot/wel.jsp @@ -1,4 +1,4 @@ -<%@ page language="java" import="java.util.*" pageEncoding="US-ASCII"%> +<%@ page language="java" import="java.util.*,dao.HibernateDao,model.User" pageEncoding="US-ASCII"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; @@ -46,6 +46,69 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. Back + + + <% + int pageSize = 3; + int pageNow = 1; // default 1st Page + int rowCount = 0; + int pageCount = 0; + + //process pageNow + //fetch user expert pagenow + + String s_pageNow = request.getParameter("pageNow"); + + if (s_pageNow != null) { + // pageNow not null + pageNow = Integer.parseInt(s_pageNow); + + } + + HibernateDao hibernateDao = new HibernateDao(); + + pageCount = hibernateDao.SearchPageCount(pageSize); + %> + + + + + + + + + + + <% + + %> + + <% + ArrayList al = (ArrayList) hibernateDao.searchPage(pageNow, + pageSize); + for (int i = 0; i < al.size(); i++) { + User user = (User) al.get(i); + %> + + + + + + + + <% + } + %> + +
idnamepwagedate
<%=user.getId()%><%=user.getName()%><%=user.getPw()%><%=user.getAge()%><%=user.getDate()%>
+ + <% + for (int i = 1; i <= pageCount; i++) { + + out.println("[" + i + "]"); + + } + %> diff --git a/1_Web_System/src/dao/HibernateDao.java b/1_Web_System/src/dao/HibernateDao.java index 3ba30eb..8c85391 100644 --- a/1_Web_System/src/dao/HibernateDao.java +++ b/1_Web_System/src/dao/HibernateDao.java @@ -18,6 +18,8 @@ public class HibernateDao { private static SessionFactory sessionFactory; private static ServiceRegistry serviceRegistry; + private int pageCount; + private int pageSize ; /** * * @param username @@ -71,5 +73,66 @@ public Object save(User user) { return obj; } + + /** + * + * @return + */ + public int SearchPageCount(int pageSize) { + Configuration configuration = new Configuration(); + configuration.configure(); + serviceRegistry = new ServiceRegistryBuilder().applySettings( + configuration.getProperties()).buildServiceRegistry(); + sessionFactory = configuration.buildSessionFactory(serviceRegistry); + + Session session = sessionFactory.getCurrentSession(); + + session.beginTransaction(); + + List list = session.createQuery("from User").list(); + + session.getTransaction().commit(); + + int rowCount = list.size(); + + if (rowCount % pageSize == 0) { + pageCount = rowCount / pageSize; + } else { + pageCount = rowCount / pageSize + 1; + } + + return pageCount; + + } + + + + /** + * Paging + * + * @param pageNow + * @param pageSize + * @return + */ + public List searchPage(int pageNow, int pageSize) { + Configuration configuration = new Configuration(); + configuration.configure(); + + serviceRegistry = new ServiceRegistryBuilder().applySettings( + configuration.getProperties()).buildServiceRegistry(); + sessionFactory = configuration.buildSessionFactory(serviceRegistry); + + Session session = sessionFactory.getCurrentSession(); + + session.beginTransaction(); + + List list = session.createQuery("from User") + .setFirstResult(pageSize * (pageNow - 1)) + .setMaxResults(pageSize).list(); + + session.getTransaction().commit(); + + return list; + } } diff --git a/1_Web_System/src/test/TestClass.java b/1_Web_System/src/test/TestClass.java index 199ba6d..54d14b5 100644 --- a/1_Web_System/src/test/TestClass.java +++ b/1_Web_System/src/test/TestClass.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import model.User; import dao.HibernateDao; public class TestClass { @@ -11,8 +12,16 @@ public static void main(String[] args) { // TODO Auto-generated method stub HibernateDao h=new HibernateDao(); List list=new ArrayList(); - list=h.searchUser("1"); - System.out.println(list.get(0)); + + //list=h.searchPage(1, 15); + + for(int i=0;i Date: Fri, 25 Sep 2015 15:56:33 -0400 Subject: [PATCH 05/19] update controller --- .../CopyOfLoginProcessController.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 1_Web_System/src/controller/CopyOfLoginProcessController.java diff --git a/1_Web_System/src/controller/CopyOfLoginProcessController.java b/1_Web_System/src/controller/CopyOfLoginProcessController.java new file mode 100644 index 0000000..f169f5a --- /dev/null +++ b/1_Web_System/src/controller/CopyOfLoginProcessController.java @@ -0,0 +1,73 @@ +package controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import model.UserBeanProcess; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; + +/** + * + * @author suzhantao + * + */ +@Controller +public class CopyOfLoginProcessController { + + UserBeanProcess ubp = new UserBeanProcess(); + + ModelAndView mv = new ModelAndView(); + + /** + * + * @param request + * @param username + * @param password + * @return + */ + @RequestMapping(value = "login", method = RequestMethod.POST) + public ModelAndView Login(HttpServletRequest request, + @RequestParam(value = "username") String username, + @RequestParam(value = "password") String password) { + if (ubp.ValidateUser(username, password)) { + mv = new ModelAndView("wel"); + + HttpSession hs = request.getSession(); + hs.setAttribute("user", username); + } else { + mv = new ModelAndView("login"); + mv.addObject("ErrorMessage", "invalid user,please try again"); + } + + return mv; + } + + @RequestMapping(value = "addUser", method = RequestMethod.POST) + public ModelAndView AddUser(HttpServletRequest request, + @RequestParam(value = "username") String username, + @RequestParam(value = "password") String password, + @RequestParam(value = "age") int age) { + + if (ubp.AddUser(username, password, age)) { + mv = new ModelAndView("wel"); + mv.addObject("username", username); + mv.addObject("password", password); + mv.addObject("age", age); + mv.addObject("statue", "Create User Successful"); + + } else { + mv = new ModelAndView("wel"); + mv.addObject("statue", "Create User Failue"); + } + + + return mv; + + } + +} From 28e1502a916b17bd4828e70c7edc2f89ffd049ec Mon Sep 17 00:00:00 2001 From: zhantaojava Date: Fri, 25 Sep 2015 15:58:15 -0400 Subject: [PATCH 06/19] update Controller --- ...fLoginProcessController.java => LoginProcessController.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename 1_Web_System/src/controller/{CopyOfLoginProcessController.java => LoginProcessController.java} (97%) diff --git a/1_Web_System/src/controller/CopyOfLoginProcessController.java b/1_Web_System/src/controller/LoginProcessController.java similarity index 97% rename from 1_Web_System/src/controller/CopyOfLoginProcessController.java rename to 1_Web_System/src/controller/LoginProcessController.java index f169f5a..e76461d 100644 --- a/1_Web_System/src/controller/CopyOfLoginProcessController.java +++ b/1_Web_System/src/controller/LoginProcessController.java @@ -17,7 +17,7 @@ * */ @Controller -public class CopyOfLoginProcessController { +public class LoginProcessController { UserBeanProcess ubp = new UserBeanProcess(); From 04496927284f71047fb9baa85f97aa32f09ec6c3 Mon Sep 17 00:00:00 2001 From: zhantaojava Date: Sat, 26 Sep 2015 22:11:34 -0400 Subject: [PATCH 07/19] =?UTF-8?q?1.spring=20Di=20=E5=AE=8C=E7=BE=8E?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=202.dispatcher=E2=80=94servlet=20=E4=B8=AD?= =?UTF-8?q?=EF=BC=8C=20component=20scan=20=E6=B7=BB=E5=8A=A0=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E6=89=AB=E6=8F=8F=E7=9A=84=E5=8C=85=203.userbeanProce?= =?UTF-8?q?ss=20=E7=94=A8annotation=E6=A0=87=E6=B3=A8=E4=B8=BAcomponent=20?= =?UTF-8?q?4.LoginController=E4=B8=AD=E7=94=A8autowired=E8=A3=85=E9=85=8Db?= =?UTF-8?q?ean?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebRoot/WEB-INF/dispatcher-servlet.xml | 4 ++- 1_Web_System/WebRoot/WEB-INF/web.xml | 5 +++- 1_Web_System/WebRoot/index.jsp | 17 ++++++++++- .../controller/LoginProcessController.java | 7 +++-- 1_Web_System/src/dao/HibernateDao.java | 2 ++ 1_Web_System/src/model/UserBeanProcess.java | 11 +++++-- 1_Web_System/src/test/TestClass.java | 30 +++++++++++++------ 7 files changed, 60 insertions(+), 16 deletions(-) diff --git a/1_Web_System/WebRoot/WEB-INF/dispatcher-servlet.xml b/1_Web_System/WebRoot/WEB-INF/dispatcher-servlet.xml index 001158a..c907534 100644 --- a/1_Web_System/WebRoot/WEB-INF/dispatcher-servlet.xml +++ b/1_Web_System/WebRoot/WEB-INF/dispatcher-servlet.xml @@ -7,7 +7,9 @@ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - + + + diff --git a/1_Web_System/WebRoot/WEB-INF/web.xml b/1_Web_System/WebRoot/WEB-INF/web.xml index 4aef5bf..808fe9f 100644 --- a/1_Web_System/WebRoot/WEB-INF/web.xml +++ b/1_Web_System/WebRoot/WEB-INF/web.xml @@ -21,7 +21,7 @@ contextConfigLocation - /WEB-INF/dispatcher-servlet.xml + /WEB-INF/dispatcher-servlet.xml @@ -29,4 +29,7 @@ org.springframework.web.context.ContextLoaderListener + + + \ No newline at end of file diff --git a/1_Web_System/WebRoot/index.jsp b/1_Web_System/WebRoot/index.jsp index 035da9d..1fd3098 100644 --- a/1_Web_System/WebRoot/index.jsp +++ b/1_Web_System/WebRoot/index.jsp @@ -1,4 +1,6 @@ <%@ page language="java" import="java.util.*,dao.HibernateDao" pageEncoding="US-ASCII"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> + <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; @@ -22,8 +24,21 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. This is my JSP page.
+ +
+ Java
+ .NET
+${webFrameworkList}
+ PHP
+ C/C++
+ PERL
+ + + + +
- + ${kj } ${message } diff --git a/1_Web_System/src/controller/LoginProcessController.java b/1_Web_System/src/controller/LoginProcessController.java index e76461d..fd15ec9 100644 --- a/1_Web_System/src/controller/LoginProcessController.java +++ b/1_Web_System/src/controller/LoginProcessController.java @@ -5,6 +5,7 @@ import model.UserBeanProcess; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -18,8 +19,10 @@ */ @Controller public class LoginProcessController { - - UserBeanProcess ubp = new UserBeanProcess(); + + @Autowired + UserBeanProcess ubp; + ModelAndView mv = new ModelAndView(); diff --git a/1_Web_System/src/dao/HibernateDao.java b/1_Web_System/src/dao/HibernateDao.java index 8c85391..52523d7 100644 --- a/1_Web_System/src/dao/HibernateDao.java +++ b/1_Web_System/src/dao/HibernateDao.java @@ -12,8 +12,10 @@ import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Repository; +@Component public class HibernateDao { private static SessionFactory sessionFactory; private static ServiceRegistry serviceRegistry; diff --git a/1_Web_System/src/model/UserBeanProcess.java b/1_Web_System/src/model/UserBeanProcess.java index d1a8736..474b735 100644 --- a/1_Web_System/src/model/UserBeanProcess.java +++ b/1_Web_System/src/model/UserBeanProcess.java @@ -5,6 +5,9 @@ import java.util.List; import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import dao.HibernateDao; /** @@ -12,8 +15,11 @@ * @author suzhantao * */ +@Component public class UserBeanProcess { - private HibernateDao hibernateDao=new HibernateDao(); + + @Autowired + private HibernateDao hibernateDao; /** * @@ -72,6 +78,7 @@ public boolean AddUser(String username,String password,int age){ } - + + } diff --git a/1_Web_System/src/test/TestClass.java b/1_Web_System/src/test/TestClass.java index 54d14b5..89a6514 100644 --- a/1_Web_System/src/test/TestClass.java +++ b/1_Web_System/src/test/TestClass.java @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; + import model.User; import dao.HibernateDao; @@ -10,18 +12,28 @@ public class TestClass { public static void main(String[] args) { // TODO Auto-generated method stub - HibernateDao h=new HibernateDao(); - List list=new ArrayList(); - //list=h.searchPage(1, 15); - for(int i=0;i Date: Tue, 29 Sep 2015 00:25:39 -0400 Subject: [PATCH 08/19] =?UTF-8?q?1.controller=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E6=96=B0=E6=96=B9=E6=B3=95=202.getUser=E4=BB=8E?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E6=8B=BF=E5=88=B0username=EF=BC=8C=20?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E8=BF=94=E5=9B=9E=E4=B8=80=E4=B8=AA=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E6=8A=8A=E5=80=BC=E4=BC=A0=E7=BB=99=20=E5=8F=A6?= =?UTF-8?q?=E4=B8=80=E4=B8=AAcontroller=20getUserProfile=E3=80=82=203.getU?= =?UTF-8?q?serProfile=E6=8B=BF=E5=88=B0=E5=80=BC=E4=BB=A5=E5=90=8E?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=8C=E6=8A=8A=E8=BF=94=E5=9B=9E=E5=80=BC?= =?UTF-8?q?=E5=B0=81=E8=A3=85=E5=88=B0modelAndView=E9=87=8C=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=BB=99jsp=E9=A1=B5=E9=9D=A2=204.RetrieveUser(int=20?= =?UTF-8?q?pageSize,=20int=20pageNow)=E5=88=99=E6=98=AF=E6=8B=BF=E5=88=B0?= =?UTF-8?q?=E5=8F=82=E6=95=B0=EF=BC=8C=E5=B9=B6=E5=88=B0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=B0=83=E5=8F=96=E7=9B=B8=E5=BA=94=E7=9A=84data=205.?= =?UTF-8?q?=E6=96=B0=E5=A2=9EloginValidation=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=EF=BC=8C=E8=8B=A5=E7=94=A8=E6=88=B7=E5=90=8D=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E6=88=90=E5=8A=9F=EF=BC=8C=E5=88=99=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E5=88=B0RetrieveUser=E6=8E=A7=E5=88=B6=E5=99=A8=206.?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E4=BF=9D=E7=95=99login=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=99=A8=E3=80=82=E5=85=B1=E6=9C=89=E4=B8=A4=E7=A7=8D=E7=99=BB?= =?UTF-8?q?=E9=99=86=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=B8=80=E7=A7=8D=E6=98=AF?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E4=BB=8Elogin=E9=AA=8C=E8=AF=81=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E5=90=8E=EF=BC=8C=E8=B7=B3=E5=88=B0jsp=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=EF=BC=8C=20=E6=95=B0=E6=8D=AE=E7=94=B1jsp=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E8=B0=83=E7=94=A8hibernateDao=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=BE=97=E5=88=B0=EF=BC=8C=E5=8F=A6=E4=B8=80=E7=A7=8D?= =?UTF-8?q?=E6=98=AF=E5=9C=A8RetrieveUser=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=E4=B8=AD=E6=8A=8A=E6=95=B0=E6=8D=AE=E5=87=86=E5=A4=87=E5=A5=BD?= =?UTF-8?q?=EF=BC=8C=20=E9=80=9A=E8=BF=87ModelAndView=20=E4=BC=A0=E5=80=BC?= =?UTF-8?q?=E7=BB=99jsp=E9=A1=B5=E9=9D=A2=E3=80=82jsp=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E6=8A=8A=E6=95=B0=E6=8D=AE=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=87=BA=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_Web_System/WebRoot/index.jsp | 9 +- 1_Web_System/WebRoot/testPage.jsp | 28 ++++++ 1_Web_System/WebRoot/userProfile.jsp | 34 +++++++ 1_Web_System/WebRoot/wel.jsp | 20 ++++ .../controller/LoginProcessController.java | 98 ++++++++++++++++++- 1_Web_System/src/model/UserBeanProcess.java | 76 +++++++++----- 1_Web_System/src/test/TestClass.java | 16 +-- 7 files changed, 238 insertions(+), 43 deletions(-) create mode 100644 1_Web_System/WebRoot/testPage.jsp create mode 100644 1_Web_System/WebRoot/userProfile.jsp diff --git a/1_Web_System/WebRoot/index.jsp b/1_Web_System/WebRoot/index.jsp index 1fd3098..4256767 100644 --- a/1_Web_System/WebRoot/index.jsp +++ b/1_Web_System/WebRoot/index.jsp @@ -25,7 +25,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. This is my JSP page.
-
+ Java
.NET
${webFrameworkList}
@@ -36,6 +36,13 @@ ${webFrameworkList}
+
+
+
+ UserName:
+ PassWord:
+ +
${kj } diff --git a/1_Web_System/WebRoot/testPage.jsp b/1_Web_System/WebRoot/testPage.jsp new file mode 100644 index 0000000..c58b347 --- /dev/null +++ b/1_Web_System/WebRoot/testPage.jsp @@ -0,0 +1,28 @@ +<%@ page language="java" import="java.util.*" pageEncoding="US-ASCII"%> +<% +String path = request.getContextPath(); +String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; +%> + + + + + + + My JSP 'testPage.jsp' starting page + + + + + + + + + + + + This is my JSP page.
+ + diff --git a/1_Web_System/WebRoot/userProfile.jsp b/1_Web_System/WebRoot/userProfile.jsp new file mode 100644 index 0000000..b195904 --- /dev/null +++ b/1_Web_System/WebRoot/userProfile.jsp @@ -0,0 +1,34 @@ +<%@ page language="java" import="java.util.*,model.User" pageEncoding="US-ASCII"%> +<% +String path = request.getContextPath(); +String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; +%> + + + + + + + My JSP 'userProfile.jsp' starting page + + + + + + + + + + + +
+ View UserProfile
+
+ Name: ${user.getName()}
+ Age: ${user.getAge()}
+ Date: ${user.getDate() }
+
+ + diff --git a/1_Web_System/WebRoot/wel.jsp b/1_Web_System/WebRoot/wel.jsp index aad774c..4a46ee1 100644 --- a/1_Web_System/WebRoot/wel.jsp +++ b/1_Web_System/WebRoot/wel.jsp @@ -109,7 +109,27 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. } %> + + + + + setPage + + + + +







+
+ Get Username: + +
+


+ Username: + [${userList.get(0).getName()}] + [${userList.get(1).getName()}] + [${userList.get(2).getName()}] + diff --git a/1_Web_System/src/controller/LoginProcessController.java b/1_Web_System/src/controller/LoginProcessController.java index fd15ec9..0f75925 100644 --- a/1_Web_System/src/controller/LoginProcessController.java +++ b/1_Web_System/src/controller/LoginProcessController.java @@ -1,12 +1,17 @@ package controller; +import java.util.LinkedList; +import java.util.List; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; +import model.User; import model.UserBeanProcess; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @@ -19,13 +24,30 @@ */ @Controller public class LoginProcessController { - + @Autowired UserBeanProcess ubp; - ModelAndView mv = new ModelAndView(); + @RequestMapping(value = "loginValidation", method = RequestMethod.POST) + public String LoginValidation( + @RequestParam(value = "username") String username, + @RequestParam(value = "password") String password) { + String url=null; + if (ubp.ValidateUser(username, password)) { + System.out.println("loginValidation hit"); + return "redirect:retrieveUser"; + + } else { + url="index"; + } + + return url; + } + + + /** * * @param request @@ -67,8 +89,76 @@ public ModelAndView AddUser(HttpServletRequest request, mv = new ModelAndView("wel"); mv.addObject("statue", "Create User Failue"); } - - + + return mv; + + } + + /** + * call from GetUser + * + * @param username + * @return + */ + @RequestMapping(value = "user/{username}", method = RequestMethod.GET) + public ModelAndView GetUserProfile(@PathVariable String username) { + + mv = new ModelAndView("userProfile"); + System.out.println("uname:" + username); + + User user = new User(); + + user = ubp.GetUserProfile(username); + + mv.addObject("user", user); + + return mv; + + } + + /** + * call GetUserProfile ,path username to user/{username} + * + * @param username + * @return + */ + @RequestMapping(value = "getUser", method = RequestMethod.GET) + public String GetUser(@RequestParam(value = "username") String username) { + + return "redirect:user/" + username; + + } + + /** + * + * @param pageNow + * @param pageSize + * @return + */ + @RequestMapping(value = "retrieveUser", method = RequestMethod.GET) + public ModelAndView RetrieveUser(HttpServletRequest request) { + String s_pageNow = request.getParameter("pageNow"); + System.out.println("s_pageNow:" + s_pageNow); + + int pageNow = 1; + if (s_pageNow != null) { + pageNow = Integer.parseInt(s_pageNow); + } else { + pageNow = 1; + } + + int pageSize = 3; + + System.out.println("retrieveUser"); + + List list = new LinkedList(); + + list = ubp.RetrieveUser(pageNow, pageSize); + + mv = new ModelAndView("wel"); + + mv.addObject("userList", list); + return mv; } diff --git a/1_Web_System/src/model/UserBeanProcess.java b/1_Web_System/src/model/UserBeanProcess.java index 474b735..c461bd3 100644 --- a/1_Web_System/src/model/UserBeanProcess.java +++ b/1_Web_System/src/model/UserBeanProcess.java @@ -10,24 +10,26 @@ import org.springframework.stereotype.Service; import dao.HibernateDao; + /** * Function same as Service Layer + * * @author suzhantao - * + * */ @Component public class UserBeanProcess { - + @Autowired private HibernateDao hibernateDao; - + /** * * @param username * @param password * @return */ - public boolean ValidateUser(String username,String password){ + public boolean ValidateUser(String username, String password) { boolean b = false; List list = new LinkedList(); @@ -46,39 +48,59 @@ public boolean ValidateUser(String username,String password){ return b; } - - public boolean AddUser(String username,String password,int age){ - boolean statue=false; - - - //determine if the user existing + + public boolean AddUser(String username, String password, int age) { + boolean statue = false; + + // determine if the user existing List list = new LinkedList(); - list=hibernateDao.searchUser(username); - - User user=new User(); + list = hibernateDao.searchUser(username); + + User user = new User(); user.setName(username); - - boolean userExisting=list.contains(user); - - Date date=new Date(); - - //if user not existing ,execute saving - if(userExisting==false){ + + boolean userExisting = list.contains(user); + + Date date = new Date(); + + // if user not existing ,execute saving + if (userExisting == false) { user.setAge(age); user.setPw(password); user.setDate(date); - - Object object=hibernateDao.save(user); - statue=true; + + Object object = hibernateDao.save(user); + statue = true; return statue; - } - else{ + } else { return statue; } + + } + /** + * GetUserProfile by username + * @param username + * @return user + */ + public User GetUserProfile(String username) { + List list = new LinkedList(); + + User user = new User(); + + list = hibernateDao.searchUser(username); + + user = list.get(0); + + return user; + } + + + public List RetrieveUser(int pageNow,int pageSize){ + List list = new LinkedList(); + list=hibernateDao.searchPage(pageNow, pageSize); + return list; } - - } diff --git a/1_Web_System/src/test/TestClass.java b/1_Web_System/src/test/TestClass.java index 89a6514..d5bca9d 100644 --- a/1_Web_System/src/test/TestClass.java +++ b/1_Web_System/src/test/TestClass.java @@ -4,7 +4,9 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.servlet.ModelAndView; +import controller.LoginProcessController; import model.User; import dao.HibernateDao; @@ -16,19 +18,11 @@ public static void main(String[] args) { - List list = new ArrayList(); - - list=abc.haha(); - // list=h.searchPage(1, 15); - - for (int i = 0; i < list.size(); i++) { - User u = new User(); - u = (User) list.get(i); - System.out.println(u.getName() + " --- " + u.getAge()); - } + + - //System.out.println(h.SearchPageCount(3)); + } From f4e479d5b6b07c11dd5d9669cf4c1353fcb97f16 Mon Sep 17 00:00:00 2001 From: zhantaojava Date: Tue, 29 Sep 2015 10:04:40 -0400 Subject: [PATCH 09/19] update wel.jsp --- 1_Web_System/WebRoot/wel.jsp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/1_Web_System/WebRoot/wel.jsp b/1_Web_System/WebRoot/wel.jsp index 4a46ee1..838d776 100644 --- a/1_Web_System/WebRoot/wel.jsp +++ b/1_Web_System/WebRoot/wel.jsp @@ -109,11 +109,27 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. } %> +
+
+
+ Spring MVC table:
+ Username:
+ [${userList.get(0).getName()}]
+ [${userList.get(1).getName()}]
+ [${userList.get(2).getName()}]
+
+ <% + for (int i = 1; i <= pageCount; i++) { + + out.println("[" + i + "]"); + + } + %> + - setPage @@ -126,10 +142,8 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.


- Username: - [${userList.get(0).getName()}] - [${userList.get(1).getName()}] - [${userList.get(2).getName()}] + + From 5dea6389f849724acca635e77e7e2c4e8a0adb7c Mon Sep 17 00:00:00 2001 From: zhantaojava Date: Tue, 29 Sep 2015 10:29:09 -0400 Subject: [PATCH 10/19] =?UTF-8?q?1.=20=E5=9C=A8addUser=20=E7=9A=84=20Model?= =?UTF-8?q?AndView=E4=B8=AD=20=E6=9B=B4=E6=94=B9=20mv=20=3D=20new=20ModelA?= =?UTF-8?q?ndView("redirect:retrieveUser");=20=E5=8F=AF=E4=BB=A5=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E8=B7=B3=E8=BD=AC=EF=BC=8CretrieveUser=E7=9A=84reques?= =?UTF-8?q?tMethod=E5=BF=85=E9=A1=BB=E4=B8=BAGET?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_Web_System/WebRoot/wel.jsp | 20 ++++++++++++++----- .../controller/LoginProcessController.java | 20 +++++++++++-------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/1_Web_System/WebRoot/wel.jsp b/1_Web_System/WebRoot/wel.jsp index 838d776..9695e66 100644 --- a/1_Web_System/WebRoot/wel.jsp +++ b/1_Web_System/WebRoot/wel.jsp @@ -112,12 +112,22 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.


+ + Spring MVC table:
- Username:
- [${userList.get(0).getName()}]
- [${userList.get(1).getName()}]
- [${userList.get(2).getName()}]
-
+ + + + + + + + + + + + +
Name:Age:Date:
${userList.get(0).getName()}${userList.get(0).getAge()}${userList.get(0).getDate()}
<% for (int i = 1; i <= pageCount; i++) { diff --git a/1_Web_System/src/controller/LoginProcessController.java b/1_Web_System/src/controller/LoginProcessController.java index 0f75925..bd78de6 100644 --- a/1_Web_System/src/controller/LoginProcessController.java +++ b/1_Web_System/src/controller/LoginProcessController.java @@ -30,24 +30,28 @@ public class LoginProcessController { ModelAndView mv = new ModelAndView(); + /** + * + * @param username + * @param password + * @return + */ @RequestMapping(value = "loginValidation", method = RequestMethod.POST) public String LoginValidation( @RequestParam(value = "username") String username, @RequestParam(value = "password") String password) { - String url=null; + String url = null; if (ubp.ValidateUser(username, password)) { System.out.println("loginValidation hit"); - return "redirect:retrieveUser"; - + return "redirect:retrieveUser"; + } else { - url="index"; + url = "index"; } return url; } - - /** * * @param request @@ -79,14 +83,14 @@ public ModelAndView AddUser(HttpServletRequest request, @RequestParam(value = "age") int age) { if (ubp.AddUser(username, password, age)) { - mv = new ModelAndView("wel"); + mv = new ModelAndView("redirect:retrieveUser"); mv.addObject("username", username); mv.addObject("password", password); mv.addObject("age", age); mv.addObject("statue", "Create User Successful"); } else { - mv = new ModelAndView("wel"); + mv = new ModelAndView("register"); mv.addObject("statue", "Create User Failue"); } From aee47245b97d0abb0fc13d8608abe125415b459e Mon Sep 17 00:00:00 2001 From: zhantaojava Date: Tue, 29 Sep 2015 11:16:56 -0400 Subject: [PATCH 11/19] =?UTF-8?q?1.=E5=9C=A8userProfile.jsp=E4=B8=AD?= =?UTF-8?q?=E6=8B=BF=E5=88=B0=E5=BD=93=E5=89=8D=E7=9A=84=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=90=8D=202.Edit=20Profi?= =?UTF-8?q?le=20=E9=9C=80=E4=BD=BF=E7=94=A8=E9=80=9A=E9=85=8D=E7=AC=A6?= =?UTF-8?q?=20${user.getName()}=20=E6=89=8D=E8=83=BD=E6=8A=8A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=90=8D=E4=BC=A0=E5=88=B0=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=20=E5=BB=BA=E8=AE=AE=E7=94=A8=20=09=20${user.getId()}=E4=BB=A5?= =?UTF-8?q?=E4=BF=9D=E8=AF=81=E4=B8=8D=E6=8B=BF=E5=88=B0=E9=87=8D=E5=90=8D?= =?UTF-8?q?=E7=9A=84=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_Web_System/WebRoot/userProfile.jsp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/1_Web_System/WebRoot/userProfile.jsp b/1_Web_System/WebRoot/userProfile.jsp index b195904..dff924c 100644 --- a/1_Web_System/WebRoot/userProfile.jsp +++ b/1_Web_System/WebRoot/userProfile.jsp @@ -29,6 +29,9 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. Name: ${user.getName()}
Age: ${user.getAge()}
Date: ${user.getDate() }
+ Edit Profile + + From 49be1aa4fa5a89d1780e40f02b133a856847879a Mon Sep 17 00:00:00 2001 From: zhantaojava Date: Tue, 29 Sep 2015 14:17:10 -0400 Subject: [PATCH 12/19] 1.built editUserProfile.jsp fetch data from EditUserProfile Controller, and display it. 2.add EditUserProfile controller,handle http request from userProfile.jsp , then call the UserBeanProcess,do the business procedure --- 1_Web_System/WebRoot/editUserProfile.jsp | 35 +++++++++++++++++++ .../controller/LoginProcessController.java | 19 ++++++++++ 2 files changed, 54 insertions(+) create mode 100644 1_Web_System/WebRoot/editUserProfile.jsp diff --git a/1_Web_System/WebRoot/editUserProfile.jsp b/1_Web_System/WebRoot/editUserProfile.jsp new file mode 100644 index 0000000..77c7e12 --- /dev/null +++ b/1_Web_System/WebRoot/editUserProfile.jsp @@ -0,0 +1,35 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> +<%@ page language="java" import="java.util.*" pageEncoding="US-ASCII"%> +<% +String path = request.getContextPath(); +String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; +%> + + + + + + + Edit + + + + + + + + + + + +
+ Username:
+ Password:
+ Age: + +
+ + diff --git a/1_Web_System/src/controller/LoginProcessController.java b/1_Web_System/src/controller/LoginProcessController.java index bd78de6..fda8f05 100644 --- a/1_Web_System/src/controller/LoginProcessController.java +++ b/1_Web_System/src/controller/LoginProcessController.java @@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -167,4 +168,22 @@ public ModelAndView RetrieveUser(HttpServletRequest request) { } + /** + * EditUserprofile + * @param username + * @return + */ + @RequestMapping(value = "{username}/edit", method = RequestMethod.GET) + public ModelAndView EditUserProfile( + @PathVariable("username") String username) { + System.out.println("uname:" + username); + User user = new User(); + + user = ubp.GetUserProfile(username); + + mv = new ModelAndView("editUserProfile"); + mv.addObject("userProfile", user); + return mv; + } + } From 82d0d55fadf4595921cfe9f7d69d53558fdd16b9 Mon Sep 17 00:00:00 2001 From: zhantaojava Date: Tue, 29 Sep 2015 23:50:00 -0400 Subject: [PATCH 13/19] =?UTF-8?q?1.=E6=95=B0=E6=8D=AE=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E7=BB=88=E4=BA=8E=E6=90=9E=E5=AE=9A=202.Jsp=20=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E4=B8=AD=E7=9A=84=E5=8F=82=E6=95=B0=E5=BF=85=E9=A1=BB?= =?UTF-8?q?=E8=B7=9Fmodel=E7=B1=BB=E4=B8=AD=E7=9A=84=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E5=90=8D=E4=B8=80=E6=A0=B7=EF=BC=8C=20=20User=20class=E4=B8=AD?= =?UTF-8?q?:=20private=20String=20name;=20=20=20private=20String=20pw;=20?= =?UTF-8?q?=20--->=20Username:=20?= =?UTF-8?q?=20name=3D=E5=BF=85=E9=A1=BB=E4=B8=BAname=20=20--->=20Password:?= =?UTF-8?q?=20=20=20=20name=3D=20?= =?UTF-8?q?=E4=B8=BA=20pw?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 3.新增UpdateUser controller 用于去数据库更新用户 --- 1_Web_System/WebRoot/editUserProfile.jsp | 11 ++++++----- .../src/controller/LoginProcessController.java | 11 +++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/1_Web_System/WebRoot/editUserProfile.jsp b/1_Web_System/WebRoot/editUserProfile.jsp index 77c7e12..876cc16 100644 --- a/1_Web_System/WebRoot/editUserProfile.jsp +++ b/1_Web_System/WebRoot/editUserProfile.jsp @@ -25,11 +25,12 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. -
- Username:
- Password:
- Age: - + + + Username:
+ Password:
+ Age:
+
diff --git a/1_Web_System/src/controller/LoginProcessController.java b/1_Web_System/src/controller/LoginProcessController.java index fda8f05..2555d59 100644 --- a/1_Web_System/src/controller/LoginProcessController.java +++ b/1_Web_System/src/controller/LoginProcessController.java @@ -185,5 +185,16 @@ public ModelAndView EditUserProfile( mv.addObject("userProfile", user); return mv; } + + @RequestMapping(value="update",method=RequestMethod.POST) + public ModelAndView UpdateUser(@ModelAttribute("user") User user){ + + System.out.println(user.getId()); + System.out.println(user.getName()); + + mv=new ModelAndView("index"); + + return mv; + } } From 905de7cc65a6cb165ed73bc5f2f5909e77b707dd Mon Sep 17 00:00:00 2001 From: zhantaojava Date: Wed, 30 Sep 2015 17:19:33 -0400 Subject: [PATCH 14/19] =?UTF-8?q?1.Update=20Function=20upgreade=20(=20?= =?UTF-8?q?=E5=9F=BA=E4=BA=8EHQL=EF=BC=89=202.HiberanteDao=20add=20new=20u?= =?UTF-8?q?pdate=20method=203.UserBeanProcess=20add=20new=20update=20metho?= =?UTF-8?q?d=204.controller=20add=20new=20UpdateUser,=20get=20ModelAttribu?= =?UTF-8?q?te=20from=20jsp=20page,=20then=20redirect=20to=20"redirect:user?= =?UTF-8?q?/"=20+=20user.getName()=205.use=20{name}=20to=20redirect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_Web_System/WebRoot/editUserProfile.jsp | 4 +- 1_Web_System/WebRoot/userProfile.jsp | 7 +-- 1_Web_System/WebRoot/wel.jsp | 2 +- .../controller/LoginProcessController.java | 22 +++++++-- 1_Web_System/src/dao/HibernateDao.java | 47 ++++++++++++++++--- 1_Web_System/src/model/UserBeanProcess.java | 24 +++++++++- 1_Web_System/src/test/TestClass.java | 12 ++++- 7 files changed, 98 insertions(+), 20 deletions(-) diff --git a/1_Web_System/WebRoot/editUserProfile.jsp b/1_Web_System/WebRoot/editUserProfile.jsp index 876cc16..5521069 100644 --- a/1_Web_System/WebRoot/editUserProfile.jsp +++ b/1_Web_System/WebRoot/editUserProfile.jsp @@ -25,12 +25,12 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. -
+ Username:
Password:
Age:
- +
diff --git a/1_Web_System/WebRoot/userProfile.jsp b/1_Web_System/WebRoot/userProfile.jsp index dff924c..6afe1c1 100644 --- a/1_Web_System/WebRoot/userProfile.jsp +++ b/1_Web_System/WebRoot/userProfile.jsp @@ -23,15 +23,16 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. -
+ View UserProfile

Name: ${user.getName()}
Age: ${user.getAge()}
- Date: ${user.getDate() }
+ Date: ${user.getDate() }

Edit Profile +
+ -
diff --git a/1_Web_System/WebRoot/wel.jsp b/1_Web_System/WebRoot/wel.jsp index 9695e66..ee74739 100644 --- a/1_Web_System/WebRoot/wel.jsp +++ b/1_Web_System/WebRoot/wel.jsp @@ -148,7 +148,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.







- Get Username: + Search User:



diff --git a/1_Web_System/src/controller/LoginProcessController.java b/1_Web_System/src/controller/LoginProcessController.java index 2555d59..024710a 100644 --- a/1_Web_System/src/controller/LoginProcessController.java +++ b/1_Web_System/src/controller/LoginProcessController.java @@ -1,5 +1,6 @@ package controller; +import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -178,7 +179,7 @@ public ModelAndView EditUserProfile( @PathVariable("username") String username) { System.out.println("uname:" + username); User user = new User(); - + user = ubp.GetUserProfile(username); mv = new ModelAndView("editUserProfile"); @@ -186,13 +187,24 @@ public ModelAndView EditUserProfile( return mv; } - @RequestMapping(value="update",method=RequestMethod.POST) + + //{userId} + /** + * Execute Update User + * @param user + * @return + */ + @RequestMapping(value="{name}",method=RequestMethod.POST) public ModelAndView UpdateUser(@ModelAttribute("user") User user){ - System.out.println(user.getId()); - System.out.println(user.getName()); + Date date=new Date(); + user.setDate(date); + + ubp.UpdateUser(user); + + + mv=new ModelAndView("redirect:user/" + user.getName()); - mv=new ModelAndView("index"); return mv; } diff --git a/1_Web_System/src/dao/HibernateDao.java b/1_Web_System/src/dao/HibernateDao.java index 52523d7..6c182c0 100644 --- a/1_Web_System/src/dao/HibernateDao.java +++ b/1_Web_System/src/dao/HibernateDao.java @@ -21,7 +21,8 @@ public class HibernateDao { private static ServiceRegistry serviceRegistry; private int pageCount; - private int pageSize ; + private int pageSize; + /** * * @param username @@ -49,7 +50,7 @@ public List searchUser(String username) { session.getTransaction().commit(); return list; - + } /** @@ -75,7 +76,7 @@ public Object save(User user) { return obj; } - + /** * * @return @@ -106,9 +107,7 @@ public int SearchPageCount(int pageSize) { return pageCount; } - - - + /** * Paging * @@ -137,4 +136,40 @@ public List searchPage(int pageNow, int pageSize) { return list; } + /** + * Update user by userId + * + * @param user + */ + public int updateUser(User user) { + Configuration configuration = new Configuration(); + configuration.configure(); + + serviceRegistry = new ServiceRegistryBuilder().applySettings( + configuration.getProperties()).buildServiceRegistry(); + sessionFactory = configuration.buildSessionFactory(serviceRegistry); + + Session session = sessionFactory.getCurrentSession(); + + session.beginTransaction(); + Query query = session.createQuery("update User set "+ + "name=:name,"+ + "pw=:pw,"+ + "age=:age,"+ + "date=:date"+ + " where id = :id"); + + System.out.println("name" + user.getName()); + + query.setParameter("name", user.getName()); + query.setParameter("id", user.getId()); + query.setParameter("pw", user.getPw()); + query.setParameter("age", user.getAge()); + query.setParameter("date", user.getDate()); + int modifications = query.executeUpdate(); + + session.getTransaction().commit(); + + return modifications; + } } diff --git a/1_Web_System/src/model/UserBeanProcess.java b/1_Web_System/src/model/UserBeanProcess.java index c461bd3..851cafe 100644 --- a/1_Web_System/src/model/UserBeanProcess.java +++ b/1_Web_System/src/model/UserBeanProcess.java @@ -94,7 +94,12 @@ public User GetUserProfile(String username) { return user; } - + /** + * Retrieve User,and do pagination + * @param pageNow + * @param pageSize + * @return + */ public List RetrieveUser(int pageNow,int pageSize){ List list = new LinkedList(); @@ -102,5 +107,20 @@ public List RetrieveUser(int pageNow,int pageSize){ return list; } - + + + /** + * Update User + * @param user + * @return int modification + */ + public int UpdateUser(User user){ + + int modification=hibernateDao.updateUser(user); + + + return modification; + } + + } diff --git a/1_Web_System/src/test/TestClass.java b/1_Web_System/src/test/TestClass.java index d5bca9d..a362aec 100644 --- a/1_Web_System/src/test/TestClass.java +++ b/1_Web_System/src/test/TestClass.java @@ -1,6 +1,7 @@ package test; import java.util.ArrayList; +import java.util.Date; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; @@ -15,9 +16,18 @@ public class TestClass { public static void main(String[] args) { // TODO Auto-generated method stub + User user=new User(); + Date date=new Date(); + user.setId(229376); + user.setName("aaa"); + user.setPw("123"); + user.setDate(date); + HibernateDao h=new HibernateDao(); + int effect=0; + effect=h.updateUser(user); - + System.out.println(effect); From 37e2c0e85bb234a5eac2879dcefba4e442321041 Mon Sep 17 00:00:00 2001 From: zhantaojava Date: Wed, 30 Sep 2015 17:51:01 -0400 Subject: [PATCH 15/19] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E4=B8=80=E4=BA=9Bjsp?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E8=B7=B3=E8=BD=AC=E6=8C=89=E9=92=AE?= =?UTF-8?q?=EF=BC=8C=20=E8=B7=B3=E8=BD=AC=E5=9B=9E=E4=B8=BB=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_Web_System/WebRoot/userProfile.jsp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/1_Web_System/WebRoot/userProfile.jsp b/1_Web_System/WebRoot/userProfile.jsp index 6afe1c1..fe947ba 100644 --- a/1_Web_System/WebRoot/userProfile.jsp +++ b/1_Web_System/WebRoot/userProfile.jsp @@ -29,7 +29,8 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. Name: ${user.getName()}
Age: ${user.getAge()}
Date: ${user.getDate() }

- Edit Profile + Edit Profile
+ Back to HomePage
From c71810de23ea0c996aa6fa420dc41a988f060a65 Mon Sep 17 00:00:00 2001 From: "szt5238@gmail.com" Date: Wed, 7 Oct 2015 15:58:43 -0400 Subject: [PATCH 16/19] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=BB?= =?UTF-8?q?=E9=A1=B5=202.=E6=9B=B4=E6=94=B9=E4=BA=86=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=B8=BB=E9=A1=B5-login.jsp-loginVa?= =?UTF-8?q?lidation=20Controller=203.=E6=B7=BB=E5=8A=A0=E4=BA=86=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E6=9D=A1=E7=9B=AE=204.User=20model=EF=BC=8Cuser=20hbm?= =?UTF-8?q?.xml=EF=BC=8CHibernateDao=E7=9A=84update=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E9=87=8C=E9=83=BD=E8=A6=81=E6=B7=BB=E5=8A=A0email=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=96=B9=E6=B3=95=E5=92=8C=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_Web_System/WebRoot/Page/main.jsp | 31 +++++++++++ 1_Web_System/WebRoot/WEB-INF/web.xml | 7 ++- 1_Web_System/WebRoot/editUserProfile.jsp | 1 + 1_Web_System/WebRoot/index.jsp | 51 ------------------- 1_Web_System/WebRoot/login(old).jsp | 43 ++++++++++++++++ 1_Web_System/WebRoot/login.jsp | 37 +++++++------- 1_Web_System/WebRoot/userProfile.jsp | 3 +- 1_Web_System/WebRoot/wel.jsp | 24 +++++++-- .../controller/LoginProcessController.java | 18 ++++--- 1_Web_System/src/dao/HibernateDao.java | 4 +- 1_Web_System/src/model/User.hbm.xml | 2 +- 1_Web_System/src/model/User.java | 7 +++ 1_Web_System/src/model/UserBeanProcess.java | 2 +- 1_Web_System/src/test/TestClass.java | 16 +++++- 14 files changed, 160 insertions(+), 86 deletions(-) create mode 100644 1_Web_System/WebRoot/Page/main.jsp delete mode 100644 1_Web_System/WebRoot/index.jsp create mode 100644 1_Web_System/WebRoot/login(old).jsp diff --git a/1_Web_System/WebRoot/Page/main.jsp b/1_Web_System/WebRoot/Page/main.jsp new file mode 100644 index 0000000..bbf11c0 --- /dev/null +++ b/1_Web_System/WebRoot/Page/main.jsp @@ -0,0 +1,31 @@ +<%@ page language="java" import="java.util.*" pageEncoding="US-ASCII"%> +<% +String path = request.getContextPath(); +String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; +%> + + + + + + + My JSP 'Main.jsp' starting page + + + + + + + + + +
+
+ Welcome to my Zone
+
+ Login + +
+ diff --git a/1_Web_System/WebRoot/WEB-INF/web.xml b/1_Web_System/WebRoot/WEB-INF/web.xml index 808fe9f..8a9268f 100644 --- a/1_Web_System/WebRoot/WEB-INF/web.xml +++ b/1_Web_System/WebRoot/WEB-INF/web.xml @@ -1,6 +1,11 @@ - + + Page/main.jsp + + + + Archetype Created Web Application diff --git a/1_Web_System/WebRoot/editUserProfile.jsp b/1_Web_System/WebRoot/editUserProfile.jsp index 5521069..89e8cbd 100644 --- a/1_Web_System/WebRoot/editUserProfile.jsp +++ b/1_Web_System/WebRoot/editUserProfile.jsp @@ -30,6 +30,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. Username:
Password:
Age:
+ Email:
diff --git a/1_Web_System/WebRoot/index.jsp b/1_Web_System/WebRoot/index.jsp deleted file mode 100644 index 4256767..0000000 --- a/1_Web_System/WebRoot/index.jsp +++ /dev/null @@ -1,51 +0,0 @@ -<%@ page language="java" import="java.util.*,dao.HibernateDao" pageEncoding="US-ASCII"%> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> - -<% -String path = request.getContextPath(); -String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; -%> - - - - - - - My JSP 'index.jsp' starting page - - - - - - - - - - This is my JSP page.
- -
- Java
- .NET
-${webFrameworkList}
- PHP
- C/C++
- PERL
- - - - -
-
-
- UserName:
- PassWord:
- - -
- - ${kj } - ${message } - - diff --git a/1_Web_System/WebRoot/login(old).jsp b/1_Web_System/WebRoot/login(old).jsp new file mode 100644 index 0000000..e83faba --- /dev/null +++ b/1_Web_System/WebRoot/login(old).jsp @@ -0,0 +1,43 @@ +<%@ page language="java" import="java.util.*" pageEncoding="US-ASCII"%> +<% +String path = request.getContextPath(); +String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; +%> + + + + + + + My JSP 'helloworld.jsp' starting page + + + + + + + + + + + + +
Spring Test
+
+ UserName:
+ PassWord:
+ + +
+
+ +
+

+ ${ErrorMessage } +
+ + + + diff --git a/1_Web_System/WebRoot/login.jsp b/1_Web_System/WebRoot/login.jsp index e83faba..61d0499 100644 --- a/1_Web_System/WebRoot/login.jsp +++ b/1_Web_System/WebRoot/login.jsp @@ -1,4 +1,6 @@ -<%@ page language="java" import="java.util.*" pageEncoding="US-ASCII"%> +<%@ page language="java" import="java.util.*,dao.HibernateDao" pageEncoding="US-ASCII"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> + <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; @@ -9,8 +11,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. - My JSP 'helloworld.jsp' starting page - + My JSP 'index.jsp' starting page @@ -19,25 +20,21 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. - - +
- -
Spring Test
-
- UserName:
- PassWord:
- - -
-
- -
-

- ${ErrorMessage } -
- + Please Enter You UserName and PassWord
+ +
+
+ UserName:

+ PassWord:

+ + +
+ ${kj } + ${message } +
diff --git a/1_Web_System/WebRoot/userProfile.jsp b/1_Web_System/WebRoot/userProfile.jsp index fe947ba..51f2d7b 100644 --- a/1_Web_System/WebRoot/userProfile.jsp +++ b/1_Web_System/WebRoot/userProfile.jsp @@ -28,7 +28,8 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
Name: ${user.getName()}
Age: ${user.getAge()}
- Date: ${user.getDate() }

+ Date: ${user.getDate() }
+ Email: ${user.getEmail()}
Edit Profile
Back to HomePage diff --git a/1_Web_System/WebRoot/wel.jsp b/1_Web_System/WebRoot/wel.jsp index ee74739..0f921e2 100644 --- a/1_Web_System/WebRoot/wel.jsp +++ b/1_Web_System/WebRoot/wel.jsp @@ -120,11 +120,29 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. Name: Age: Date: + Email: - ${userList.get(0).getName()} - ${userList.get(0).getAge()} - ${userList.get(0).getDate()} + ${userList.get(0).getName()} + ${userList.get(0).getAge()} + ${userList.get(0).getDate()} + ${userList.get(0).getEmail()} + + + ${userList.get(1).getName()} + ${userList.get(1).getAge()} + ${userList.get(1).getDate()} + ${userList.get(1).getEmail()} + + + ${userList.get(2).getName()} + ${userList.get(2).getAge()} + ${userList.get(2).getDate()} + ${userList.get(2).getEmail()} + + + + diff --git a/1_Web_System/src/controller/LoginProcessController.java b/1_Web_System/src/controller/LoginProcessController.java index 024710a..0604542 100644 --- a/1_Web_System/src/controller/LoginProcessController.java +++ b/1_Web_System/src/controller/LoginProcessController.java @@ -110,12 +110,13 @@ public ModelAndView AddUser(HttpServletRequest request, public ModelAndView GetUserProfile(@PathVariable String username) { mv = new ModelAndView("userProfile"); - System.out.println("uname:" + username); User user = new User(); - + user = ubp.GetUserProfile(username); - + + + mv.addObject("user", user); return mv; @@ -162,9 +163,11 @@ public ModelAndView RetrieveUser(HttpServletRequest request) { list = ubp.RetrieveUser(pageNow, pageSize); mv = new ModelAndView("wel"); - + + System.out.println("row Count:"+list.size()); + //TODO fix last page display mv.addObject("userList", list); - + return mv; } @@ -177,7 +180,6 @@ public ModelAndView RetrieveUser(HttpServletRequest request) { @RequestMapping(value = "{username}/edit", method = RequestMethod.GET) public ModelAndView EditUserProfile( @PathVariable("username") String username) { - System.out.println("uname:" + username); User user = new User(); user = ubp.GetUserProfile(username); @@ -200,9 +202,13 @@ public ModelAndView UpdateUser(@ModelAttribute("user") User user){ Date date=new Date(); user.setDate(date); + System.out.println("email:"+user.getEmail()); + + ubp.UpdateUser(user); + mv=new ModelAndView("redirect:user/" + user.getName()); diff --git a/1_Web_System/src/dao/HibernateDao.java b/1_Web_System/src/dao/HibernateDao.java index 6c182c0..82465c0 100644 --- a/1_Web_System/src/dao/HibernateDao.java +++ b/1_Web_System/src/dao/HibernateDao.java @@ -156,7 +156,8 @@ public int updateUser(User user) { "name=:name,"+ "pw=:pw,"+ "age=:age,"+ - "date=:date"+ + "date=:date,"+ + "email=:email"+ " where id = :id"); System.out.println("name" + user.getName()); @@ -166,6 +167,7 @@ public int updateUser(User user) { query.setParameter("pw", user.getPw()); query.setParameter("age", user.getAge()); query.setParameter("date", user.getDate()); + query.setParameter("email", user.getEmail()); int modifications = query.executeUpdate(); session.getTransaction().commit(); diff --git a/1_Web_System/src/model/User.hbm.xml b/1_Web_System/src/model/User.hbm.xml index b02da26..85b2898 100644 --- a/1_Web_System/src/model/User.hbm.xml +++ b/1_Web_System/src/model/User.hbm.xml @@ -15,7 +15,7 @@ - + \ No newline at end of file diff --git a/1_Web_System/src/model/User.java b/1_Web_System/src/model/User.java index d2ba569..e4b5cc1 100644 --- a/1_Web_System/src/model/User.java +++ b/1_Web_System/src/model/User.java @@ -8,6 +8,13 @@ public class User { private int age; private String pw; private Date date; + private String email; + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } public int getId() { return id; } diff --git a/1_Web_System/src/model/UserBeanProcess.java b/1_Web_System/src/model/UserBeanProcess.java index 851cafe..bd484f0 100644 --- a/1_Web_System/src/model/UserBeanProcess.java +++ b/1_Web_System/src/model/UserBeanProcess.java @@ -68,7 +68,7 @@ public boolean AddUser(String username, String password, int age) { user.setAge(age); user.setPw(password); user.setDate(date); - + Object object = hibernateDao.save(user); statue = true; return statue; diff --git a/1_Web_System/src/test/TestClass.java b/1_Web_System/src/test/TestClass.java index a362aec..b8f4447 100644 --- a/1_Web_System/src/test/TestClass.java +++ b/1_Web_System/src/test/TestClass.java @@ -4,6 +4,7 @@ import java.util.Date; import java.util.List; +import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.servlet.ModelAndView; @@ -14,7 +15,6 @@ public class TestClass { public static void main(String[] args) { - // TODO Auto-generated method stub User user=new User(); Date date=new Date(); @@ -34,6 +34,20 @@ public static void main(String[] args) { } + @Test + public void TestGetUser(){ + User user=new User(); + + HibernateDao h=new HibernateDao(); + + + user=(User) h.searchUser("shabi"); + + + + } + + } From 7a84a217bc55ed22f4f4fcacd318b6b46f7bf8a2 Mon Sep 17 00:00:00 2001 From: "szt5238@gmail.com" Date: Thu, 8 Oct 2015 10:48:21 -0400 Subject: [PATCH 17/19] =?UTF-8?q?1.=E6=9B=B4=E6=96=B0=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_Web_System/WebRoot/Page/main.jsp | 2 ++ 1_Web_System/WebRoot/editUserProfile.jsp | 2 +- 1_Web_System/WebRoot/register.jsp | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/1_Web_System/WebRoot/Page/main.jsp b/1_Web_System/WebRoot/Page/main.jsp index bbf11c0..986d7da 100644 --- a/1_Web_System/WebRoot/Page/main.jsp +++ b/1_Web_System/WebRoot/Page/main.jsp @@ -26,6 +26,8 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. Welcome to my Zone

Login +

+ Register diff --git a/1_Web_System/WebRoot/editUserProfile.jsp b/1_Web_System/WebRoot/editUserProfile.jsp index 89e8cbd..e43cc97 100644 --- a/1_Web_System/WebRoot/editUserProfile.jsp +++ b/1_Web_System/WebRoot/editUserProfile.jsp @@ -30,7 +30,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. Username:
Password:
Age:
- Email:
+ Email:

diff --git a/1_Web_System/WebRoot/register.jsp b/1_Web_System/WebRoot/register.jsp index c9f754a..2755d37 100644 --- a/1_Web_System/WebRoot/register.jsp +++ b/1_Web_System/WebRoot/register.jsp @@ -25,7 +25,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
- Please Fill The Form + Please Fill The Form

@@ -37,7 +37,8 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. -


+
+
From b5c8912f740067da28778e3053bd0266b62248d9 Mon Sep 17 00:00:00 2001 From: "szt5238@gmail.com" Date: Thu, 8 Oct 2015 11:44:09 -0400 Subject: [PATCH 18/19] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E4=BA=86testPage.jsp?= =?UTF-8?q?=20&=20TestController=202.=E7=94=A8=E4=BA=8E=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=91=E5=AE=9A=203.dispatcher-servlet.xml?= =?UTF-8?q?=20=E9=9C=80=E8=A6=81=E6=8A=8Acomponent=20scan=20=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=20test=E5=8C=85=EF=BC=8Cmvc=E6=89=8D=E8=83=BD?= =?UTF-8?q?=E6=89=BE=E5=88=B0controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebRoot/WEB-INF/dispatcher-servlet.xml | 2 +- 1_Web_System/WebRoot/testPage.jsp | 31 +++++++++++++++- 1_Web_System/WebRoot/userProfile.jsp | 2 +- .../controller/LoginProcessController.java | 6 +-- 1_Web_System/src/test/TestController.java | 37 +++++++++++++++++++ 5 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 1_Web_System/src/test/TestController.java diff --git a/1_Web_System/WebRoot/WEB-INF/dispatcher-servlet.xml b/1_Web_System/WebRoot/WEB-INF/dispatcher-servlet.xml index c907534..ff646e3 100644 --- a/1_Web_System/WebRoot/WEB-INF/dispatcher-servlet.xml +++ b/1_Web_System/WebRoot/WEB-INF/dispatcher-servlet.xml @@ -7,7 +7,7 @@ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - + diff --git a/1_Web_System/WebRoot/testPage.jsp b/1_Web_System/WebRoot/testPage.jsp index c58b347..60f08f3 100644 --- a/1_Web_System/WebRoot/testPage.jsp +++ b/1_Web_System/WebRoot/testPage.jsp @@ -1,3 +1,5 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> <%@ page language="java" import="java.util.*" pageEncoding="US-ASCII"%> <% String path = request.getContextPath(); @@ -23,6 +25,33 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. - This is my JSP page.
+ int binding
+
+ Int: + +
+ + + + Model Binding & @RequestParam +
+ Name: + Age: + + +
+ + + + ModelAtrribute Binding + +
+ Name: + Age: + + +
+ + diff --git a/1_Web_System/WebRoot/userProfile.jsp b/1_Web_System/WebRoot/userProfile.jsp index 51f2d7b..675afb2 100644 --- a/1_Web_System/WebRoot/userProfile.jsp +++ b/1_Web_System/WebRoot/userProfile.jsp @@ -31,7 +31,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. Date: ${user.getDate() }
Email: ${user.getEmail()}
Edit Profile
- Back to HomePage + Back to HomePage
diff --git a/1_Web_System/src/controller/LoginProcessController.java b/1_Web_System/src/controller/LoginProcessController.java index 0604542..1891e1f 100644 --- a/1_Web_System/src/controller/LoginProcessController.java +++ b/1_Web_System/src/controller/LoginProcessController.java @@ -165,7 +165,7 @@ public ModelAndView RetrieveUser(HttpServletRequest request) { mv = new ModelAndView("wel"); System.out.println("row Count:"+list.size()); - //TODO fix last page display + mv.addObject("userList", list); return mv; @@ -197,7 +197,7 @@ public ModelAndView EditUserProfile( * @return */ @RequestMapping(value="{name}",method=RequestMethod.POST) - public ModelAndView UpdateUser(@ModelAttribute("user") User user){ + public ModelAndView UpdateUser(User user){ Date date=new Date(); user.setDate(date); @@ -214,5 +214,5 @@ public ModelAndView UpdateUser(@ModelAttribute("user") User user){ return mv; } - + } diff --git a/1_Web_System/src/test/TestController.java b/1_Web_System/src/test/TestController.java new file mode 100644 index 0000000..8c82ff1 --- /dev/null +++ b/1_Web_System/src/test/TestController.java @@ -0,0 +1,37 @@ +package test; + +import model.User; +import model.UserBeanProcess; + +import org.springframework.beans.factory.annotation.Autowired; +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.RequestParam; + + +@Controller +public class TestController { + @Autowired + UserBeanProcess ubp; + + + @RequestMapping(value="test1") + public void test1(int count){ + System.out.println(count); + } + + @RequestMapping(value="test2") + public void test2(@RequestParam("aage")int age, User user){ + System.out.println(user.getName()); + System.out.println(age); + + } + + + @RequestMapping(value="test3") + public void test3(@ModelAttribute("u") User user){ + System.out.println(user.getName()); + System.out.println(user.getAge()); + } +} From 498ee57087d2fb93f17c3c6af3199bd29b1382f9 Mon Sep 17 00:00:00 2001 From: "szt5238@gmail.com" Date: Fri, 9 Oct 2015 12:06:00 -0400 Subject: [PATCH 19/19] =?UTF-8?q?1.wel.jsp=E5=A2=9E=E5=8A=A0edit=E9=93=BE?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_Web_System/WebRoot/testPage.jsp | 8 ++++---- 1_Web_System/WebRoot/wel.jsp | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/1_Web_System/WebRoot/testPage.jsp b/1_Web_System/WebRoot/testPage.jsp index 60f08f3..8641584 100644 --- a/1_Web_System/WebRoot/testPage.jsp +++ b/1_Web_System/WebRoot/testPage.jsp @@ -45,12 +45,12 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. ModelAtrribute Binding -
- Name: - Age: + + Name: + Age: - +
diff --git a/1_Web_System/WebRoot/wel.jsp b/1_Web_System/WebRoot/wel.jsp index 0f921e2..4b1fb13 100644 --- a/1_Web_System/WebRoot/wel.jsp +++ b/1_Web_System/WebRoot/wel.jsp @@ -95,7 +95,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. <%=user.getPw()%> <%=user.getAge()%> <%=user.getDate()%> - + ${userList.get(i).getName()} <% } %> @@ -121,26 +121,32 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. Age: Date: Email: + Setting: + ${userList.get(0).getName()} ${userList.get(0).getAge()} ${userList.get(0).getDate()} ${userList.get(0).getEmail()} + Edit ${userList.get(1).getName()} ${userList.get(1).getAge()} ${userList.get(1).getDate()} ${userList.get(1).getEmail()} + Edit ${userList.get(2).getName()} ${userList.get(2).getAge()} ${userList.get(2).getDate()} ${userList.get(2).getEmail()} + Edit +