Skip to content

Commit

Permalink
hzuapps#3 hzuapps#4 hzuapps#5 hzuapps#6 #7提交实验代码
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Nov 27, 2016
1 parent be115f5 commit 8350828
Show file tree
Hide file tree
Showing 12 changed files with 614 additions and 0 deletions.
57 changes: 57 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902235/ErrorFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package edu.hzu.javaweb.labs.se1414080902235servlet;

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.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
* Servlet Filter implementation class LoginFilter
*/
@WebFilter(filterName="ErrorFilter",urlPatterns="/1414080902235")
public class ErrorFilter implements Filter {

/**
* Default constructor.
*/
public ErrorFilter() {
// TODO Auto-generated constructor stub
}

/**
* @see Filter#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
}

/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//获取http请求相关数据
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;

HttpSession session = req.getSession();
if (session.getAttribute("username") == null) {
resp.sendRedirect("login.jsp");
} else {
chain.doFilter(request, response);
}
}

/**
* @see Filter#init(FilterConfig)
*/
public void init(FilterConfig fConfig) throws ServletException {
System.out.println("登录过滤...");
}
}
94 changes: 94 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902235/indexcheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package web;

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 indexcheck extends HttpServlet {

/**
* Constructor of the object.
*/
public indexcheck() {
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 {
String userName=request.getParameter("username");
String userPwd=request.getParameter("userpwd");
request.setAttribute("username", userName);
request.setAttribute("userpwd", userPwd);
if("1414080902235".equals(userName)&&"1414080902235".equals(userPwd))
{

}
else
{
request.getRequestDispatcher("/show.jsp").forward(request, response);
}



}

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

}
84 changes: 84 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902235/registerservlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package web;

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 registerservlet extends HttpServlet {

/**
* Constructor of the object.
*/
public registerservlet() {
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 {
}

/**
* 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 {
String userName=request.getParameter("username");
String userPwd=request.getParameter("userpwd");
String userPwd1=request.getParameter("userpwd1");
String userSex=request.getParameter("usersex");
request.setAttribute("usern",userName);
request.setAttribute("userp",userPwd);
request.setAttribute("users",userSex);
request.setAttribute("power", "0");
if(userName.length()<=0)
request.getRequestDispatcher("/error.jsp").forward(request, response);
else if(userName.length()<6||userPwd.length()<6)
request.getRequestDispatcher("/error.jsp").forward(request, response);
else if(!(userPwd).equals(userPwd1))
request.getRequestDispatcher("/error.jsp").forward(request, response);
else
{
request.setAttribute("power", "1");
request.getRequestDispatcher("/input.jsp").forward(request, response);
}
}

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

}
35 changes: 35 additions & 0 deletions jweb/web/error.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<%@ 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>My JSP 'error.jsp' starting page</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>
<%
String username=(String)request.getAttribute("username");
String userpwd=(String)request.getAttribute("userpwd");
out.println(username+userpwd);
%><br/>
发生错误,请检查用户名与密码是否正确!!!<br/>
<a href="register.jsp">点击返回注册页面</a><br/>
<a href="index.jsp">点击返回登陆页面</a>
</body>
</html>
54 changes: 54 additions & 0 deletions jweb/web/index.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*" %>
<%@ page import="javax.servlet.*,java.text.*" %>
<%
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>
<form action="servlet/indexcheck" method="post">
<table border="1" align="center" width="600">
<tr><td colspan="3" align="center" height="40">登陆</td></tr>
<tr><td align="right">用户名:*</td>
<td><input type="text" name="username"/></td>
<td>输入账号!</td>
</tr>
<tr><td align="right">密码:*</td>
<td><input type="password" name="userpwd"/></td>
<td>输入密码!</td>
</tr>
<tr><td colspan="3" align="center" height="40">
<input type="submit" value="登陆"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="取消"/>
</td>
</tr>
</table>
</form>
<a href="register.jsp">尚未注册?点击前往。</a>
<small>
<%
Date now=new Date();
SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd");
out.print( "现在时间是:"+now + ft.format(now));
%>
</small>
</body>
</html>
29 changes: 29 additions & 0 deletions jweb/web/info.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%@ 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>My JSP 'info.jsp' starting page</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>
<%=request.getAttribute("user") %><br/>
<%=request.getAttribute("info") %>
</body>
</html>
Loading

0 comments on commit 8350828

Please sign in to comment.