diff --git a/jweb/src/edu/hzu/javaweb/labs/se1414080902141/FilterTest.java b/jweb/src/edu/hzu/javaweb/labs/se1414080902141/FilterTest.java new file mode 100644 index 00000000..6a562961 --- /dev/null +++ b/jweb/src/edu/hzu/javaweb/labs/se1414080902141/FilterTest.java @@ -0,0 +1,46 @@ +package se1414080902141; + +import java.io.IOException; + + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +public class FilterTest implements Filter { + + @Override + public void destroy() { + // TODO Auto-generated method stub + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + HttpServletRequest requ=(HttpServletRequest)request; + HttpServletResponse resp=(HttpServletResponse)response; + HttpSession session=requ.getSession(true); + if(session.getAttribute("u_name")==null){ + resp.sendRedirect("login.jsp"); + + }else{ + chain.doFilter(request,response); + } + // TODO Auto-generated method stub + + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + // TODO Auto-generated method stub + + } + +} diff --git a/jweb/src/edu/hzu/javaweb/labs/se1414080902141/denglu.jsp b/jweb/src/edu/hzu/javaweb/labs/se1414080902141/denglu.jsp new file mode 100644 index 00000000..59f8ca53 --- /dev/null +++ b/jweb/src/edu/hzu/javaweb/labs/se1414080902141/denglu.jsp @@ -0,0 +1,90 @@ +<%@ page language="java" contentType="text/html; charset="ISO-8859-1" pageEncoding="utf-8"%> + + + + +Insert title here + + +

欢迎你,已成功登录贩卖机管理系统

+ +
+ +

现在你可以对以下商品进行更新:

+ +现在的矿泉水数量充足,不需要增加 + + +现在的宝矿力饮品数量充足,不需要增加 + + +现在的加多宝饮品数量充足,不需要增加 + + +现在的可乐饮品数量充足,不需要增加 + + +现在的雪碧饮品数量充足,不需要增加 + + +现在的果粒橙饮品数量充足,不需要增加 + + +现在需要增加咖啡饮品的数量: + + + + + +现在的咖啡饮品充足,不需要增加 +

+ +

+
+ + \ No newline at end of file diff --git a/jweb/src/edu/hzu/javaweb/labs/se1414080902141/se1414080902141servlet.java b/jweb/src/edu/hzu/javaweb/labs/se1414080902141/se1414080902141servlet.java new file mode 100644 index 00000000..68cc4a88 --- /dev/null +++ b/jweb/src/edu/hzu/javaweb/labs/se1414080902141/se1414080902141servlet.java @@ -0,0 +1,93 @@ +package se1414080902141; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class Se1414080902141Servlet extends HttpServlet { + + /** + * Constructor of the object. + */ + public se1414080902141servlet() { + super(); + } + + /** + * Destruction of the servlet.
+ */ + public void destroy() { + super.destroy(); // Just puts "destroy" string in log + // Put your code here + } + + /** + * The doGet method of the servlet.
+ * + * This method is called when a form has its tag value method equals to get. + * + * @param request the request send by the client to the server + * @param response the response send by the server to the client + * @throws ServletException if an error occurred + * @throws IOException if an error occurred + */ + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println(""); + out.println(""); + out.println(" A Servlet"); + out.println(" "); + out.print(" This is "); + out.print(this.getClass()); + out.println("using the GET method"); + out.println(" "); + out.println(""); + out.flush(); + out.close(); + } + + /** + * The doPost method of the servlet.
+ * + * This method is called when a form has its tag value method equals to post. + * + * @param request the request send by the client to the server + * @param response the response send by the server to the client + * @throws ServletException if an error occurred + * @throws IOException if an error occurred + */ + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println(""); + out.println(""); + out.println(" A Servlet"); + out.println(" "); + out.print(" This is "); + out.print(this.getClass()); + out.println("using the POST method"); + out.println(" "); + out.println(""); + out.flush(); + out.close(); + } + + /** + * Initialization of the servlet.
+ * + * @throws ServletException if an error occurs + */ + public void init() throws ServletException { + // Put your code here + } + +} diff --git a/jweb/src/edu/hzu/javaweb/labs/se1414080902141/show.jsp b/jweb/src/edu/hzu/javaweb/labs/se1414080902141/show.jsp new file mode 100644 index 00000000..6d661c4d --- /dev/null +++ b/jweb/src/edu/hzu/javaweb/labs/se1414080902141/show.jsp @@ -0,0 +1,44 @@ +<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> +<% +String path = request.getContextPath(); +String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; +%> + + + + + + + 展示贩卖机管理系统的主页面 + + + + + + + + + + + + <% Calendar rightNow=Calendar.getInstance(); + Integer Hour=new Integer(rightNow.get(Calendar.HOUR_OF_DAY)); + request.setAttribute("hour",Hour); +%> +

欢迎来到贩卖机管理系统界面

+
欢迎你,早上好!
+
欢迎你,下午好!
+
欢迎你,晚上好!
+ +
+

请输入你的员工号: + +

+

请输入你的登录密码: + +

+
+ + \ No newline at end of file diff --git a/jweb/src/edu/hzu/javaweb/labs/se1414080902141/success.jsp b/jweb/src/edu/hzu/javaweb/labs/se1414080902141/success.jsp new file mode 100644 index 00000000..35bee4be --- /dev/null +++ b/jweb/src/edu/hzu/javaweb/labs/se1414080902141/success.jsp @@ -0,0 +1,16 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="utf-8"%> + + + + +Insert title here + + +
+

恭喜你,你已成功完成本次任务,请下次及时对商品进行补充!

+

你将返回登录界面

+ +
+ + \ No newline at end of file diff --git a/labs/se1414080902141/FilterTest.java b/labs/se1414080902141/FilterTest.java new file mode 100644 index 00000000..6a562961 --- /dev/null +++ b/labs/se1414080902141/FilterTest.java @@ -0,0 +1,46 @@ +package se1414080902141; + +import java.io.IOException; + + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +public class FilterTest implements Filter { + + @Override + public void destroy() { + // TODO Auto-generated method stub + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + HttpServletRequest requ=(HttpServletRequest)request; + HttpServletResponse resp=(HttpServletResponse)response; + HttpSession session=requ.getSession(true); + if(session.getAttribute("u_name")==null){ + resp.sendRedirect("login.jsp"); + + }else{ + chain.doFilter(request,response); + } + // TODO Auto-generated method stub + + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + // TODO Auto-generated method stub + + } + +} diff --git a/labs/se1414080902141/README.md b/labs/se1414080902141/README.md new file mode 100644 index 00000000..2af38d3f --- /dev/null +++ b/labs/se1414080902141/README.md @@ -0,0 +1,20 @@ +# 高级网页设计(Java Web)实验库 +讲义:http://zeng.shaoning.net/javaweb + +# 实验一:Web基础 +https://github.com/hzuapps/java-web/issues/2 +# 实验二:Tomcat基础 +https://github.com/hzuapps/java-web/issues/3 +# 实验三:Servlet基础 +https://github.com/hzuapps/java-web/issues/4 +# 实验四:Filter基础 +https://github.com/hzuapps/java-web/issues/5 + +# 参考资料 + +Java EE官方教程:http://docs.oracle.com/javaee/6/tutorial/doc/bnadr.html +JDBC官方教程:https://docs.oracle.com/javase/tutorial/jdbc/ +Java Web入门教程:http://www.journaldev.com/1854/java-web-application-tutorial-for-beginners +Spring框架:http://spring.io/ +Hibernate框架:http://www.hibernate.org +Eclipse:http://www.eclipse.org diff --git a/labs/se1414080902141/Se1414080902141Servlet.java b/labs/se1414080902141/Se1414080902141Servlet.java new file mode 100644 index 00000000..68cc4a88 --- /dev/null +++ b/labs/se1414080902141/Se1414080902141Servlet.java @@ -0,0 +1,93 @@ +package se1414080902141; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class Se1414080902141Servlet extends HttpServlet { + + /** + * Constructor of the object. + */ + public se1414080902141servlet() { + super(); + } + + /** + * Destruction of the servlet.
+ */ + public void destroy() { + super.destroy(); // Just puts "destroy" string in log + // Put your code here + } + + /** + * The doGet method of the servlet.
+ * + * This method is called when a form has its tag value method equals to get. + * + * @param request the request send by the client to the server + * @param response the response send by the server to the client + * @throws ServletException if an error occurred + * @throws IOException if an error occurred + */ + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println(""); + out.println(""); + out.println(" A Servlet"); + out.println(" "); + out.print(" This is "); + out.print(this.getClass()); + out.println("using the GET method"); + out.println(" "); + out.println(""); + out.flush(); + out.close(); + } + + /** + * The doPost method of the servlet.
+ * + * This method is called when a form has its tag value method equals to post. + * + * @param request the request send by the client to the server + * @param response the response send by the server to the client + * @throws ServletException if an error occurred + * @throws IOException if an error occurred + */ + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println(""); + out.println(""); + out.println(" A Servlet"); + out.println(" "); + out.print(" This is "); + out.print(this.getClass()); + out.println("using the POST method"); + out.println(" "); + out.println(""); + out.flush(); + out.close(); + } + + /** + * Initialization of the servlet.
+ * + * @throws ServletException if an error occurs + */ + public void init() throws ServletException { + // Put your code here + } + +}