Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6 #106 #660

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
46 changes: 46 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902141/FilterTest.java
Original file line number Diff line number Diff line change
@@ -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

}

}
90 changes: 90 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902141/denglu.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<%@ page language="java" contentType="text/html; charset="ISO-8859-1" 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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h3><center>欢迎你,已成功登录贩卖机管理系统</center></h3>

<form action="success.jsp" method="post">

<p>现在你可以对以下商品进行更新:</p>
<select>
<c:if test="${number>=0&&number<=10} }">现在需要增加矿泉水的数量:</c:if>
<option>5瓶</option>
<option>10瓶</option>
<option>15瓶</option>
<option>20瓶</option>
</select>
<c:if test="${number>=20}">现在的矿泉水数量充足,不需要增加</c:if>

<select>
<c:if test="${number>=0&&number<=10}">现在需要增加宝矿力饮品的数量:</c:if>
<option>5瓶</option>
<option>10瓶</option>
<option>15瓶</option>
<option>20瓶</option>
</select>
<c:if test="${number>=20}">现在的宝矿力饮品数量充足,不需要增加</c:if>

<select>
<c:if test="${number>=0&&number<=10}">现在需要增加加多宝饮品的数量:</c:if>
<option>5瓶</option>
<option>10瓶</option>
<option>15瓶</option>
<option>20瓶</option>
</select>
<c:if test="${number>=20}">现在的加多宝饮品数量充足,不需要增加</c:if>

<select>
<c:if test="${number>=0&&number<=10}">现在需要可乐饮品的数量:</c:if>
<option>5瓶</option>
<option>10瓶</option>
<option>15瓶</option>
<option>20瓶</option>
</select>
<c:if test="${number>=20}">现在的可乐饮品数量充足,不需要增加</c:if>

<select>
<c:if test="${number>=0&&number<=10}">现在需要增加雪碧饮品的数量:</c:if>
<option>5瓶</option>
<option>10瓶</option>
<option>15瓶</option>
<option>20瓶</option>
</select>
<c:if test="${number>=20}">现在的雪碧饮品数量充足,不需要增加</c:if>

<select>
<c:if test="${number>=0&&number<=10}">现在需要增加果粒橙饮品的数量:</c:if>
<option>5瓶</option>
<option>10瓶</option>
<option>15瓶</option>
<option>20瓶</option>
</select>
<c:if test="${number>=20}">现在的果粒橙饮品数量充足,不需要增加</c:if>

<select>
<c:if test="${number>=0&&number<=10}">现在需要增加芬达饮品的数量:</c:if>
<option>5瓶</option>
<option>10瓶</option>
<option>15瓶</option>
<option>20瓶</option>
</selcet>
<c:if test="${number>=20}">现在的芬达饮品数量充足,不需要增加</c:if>

<select>
<c:if test="${number>=0&&number<=10}">现在需要增加咖啡饮品的数量:</c:if>
<option>5瓶</option>
<option>10瓶</option>
<option>15瓶</option>
<option>20瓶</option>
</select>
<c:if test="${number>=20}">现在的咖啡饮品充足,不需要增加</c:if>
<p>
<input type="submit" name="以修改" value="确认修改" >
</p>
</form>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -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. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* 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("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println("using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}

/**
* The doPost method of the servlet. <br>
*
* 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("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println("using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}

}
44 changes: 44 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902141/show.jsp
Original file line number Diff line number Diff line change
@@ -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+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>展示贩卖机管理系统的主页面</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<% Calendar rightNow=Calendar.getInstance();
Integer Hour=new Integer(rightNow.get(Calendar.HOUR_OF_DAY));
request.setAttribute("hour",Hour);
%>
<h3><center>欢迎来到贩卖机管理系统界面</center></h3>
<c:if test="${hour>=0&&hour<=10}"><center>欢迎你,早上好!</center></c:if>
<c:if test="${hour>10&&hour<=19}"><center>欢迎你,下午好!</center></c:if>
<c:if test="${hour>19&&hour<=24}"><center>欢迎你,晚上好!</center></c:if>

<form action="denglu.jsp" method="post">
<p>请输入你的员工号:
<input type="test" name="你的账号">
</p>
<p>请输入你的登录密码:
<input type="submit" name="你的密码" value="登录">
</p>
</form>
</body>
</html>
16 changes: 16 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902141/success.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="show.jsp" method="post">
<h2><center>恭喜你,你已成功完成本次任务,请下次及时对商品进行补充!</center></h2>
<p>你将返回登录界面</p>
<input type="submit" value="返回">
</form>
</body>
</html>
46 changes: 46 additions & 0 deletions labs/se1414080902141/FilterTest.java
Original file line number Diff line number Diff line change
@@ -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

}

}
20 changes: 20 additions & 0 deletions labs/se1414080902141/README.md
Original file line number Diff line number Diff line change
@@ -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
Loading