Skip to content

Commit

Permalink
hzuapps#4 提交实验代码
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestP committed Nov 17, 2016
1 parent 0d28500 commit b5b56d6
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 0 deletions.
36 changes: 36 additions & 0 deletions jweb/web/1414080902137/Info.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<%@ 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>
<div><%=request.getAttribute("outputMessage") %></div>
<script>
//取出传回来的参数error并与yes比较
var errori ='<%=request.getParameter("error")%>';
if(errori=='yes'){
alert("登录失败!");
history.back();
}
</script>
</body>
</html>
60 changes: 60 additions & 0 deletions jweb/web/1414080902137/index.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<%@page language="java" contentType="text/html" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<meta charset="utf-8">
<!-- 网页随屏幕的大小变化而变化 -->
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!-- 支持IE浏览器 -->
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<title>酒店管理系统</title>
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="index.js"></script>

<body >
<div style="background-color:silver;height:150px">
<div class="container">
<div class="row" style="margin-top: 180px">
<div class="col-md-5 col-md-offset-3" style="background-color: LightSteelBlue">
<h1>欢迎登录XX酒店管理系统!</h1>
<form action="se1414080902137" class="form-horizontal" style="margin-top: 20px" method="post">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">账号:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" name="username" placeholder="账号">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">密码:</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" name="password" placeholder="密码">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> 记住账号
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<!-- submit 提交form表单中的数据到action指定的页面
<button type="submit" class="btn btn-default">登录</button> -->
<input type="submit" class="btn btn-default" value="登录"/>
<input type="reset" class="btn btn-default" value="取消"/>
</div>
</div>

</form>
</div>
</div>
</div>
</div>


</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package edu.hzu.javaweb.labs.se1414080902137;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class se1414080902137Servlet extends HttpServlet {


/**
* Constructor of the object.
*/
public se1414080902137Servlet() {
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");
String userName=request.getParameter("username");
String userPwd=request.getParameter("password");
String info="";
if(("abc").equals(userName)&&("123").equals(userPwd)){
info="»¶Ó­Ä㣬"+userName+"!";
request.setAttribute("outputMessage", info);
request.getRequestDispatcher("Info.jsp").forward(request,response);
}else{
response.sendRedirect("Info.jsp?error=yes");

}


}

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

}

0 comments on commit b5b56d6

Please sign in to comment.