Skip to content

Commit

Permalink
Merge pull request #2 from hzuapps/master
Browse files Browse the repository at this point in the history
wyz
  • Loading branch information
bestwayr authored Oct 20, 2016
2 parents c69db16 + 9de3163 commit 8b509be
Show file tree
Hide file tree
Showing 268 changed files with 48,581 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

# 实验一:Web基础
https://github.com/hzuapps/java-web/issues/2
# 实验二:Tomcat基础
https://github.com/hzuapps/java-web/issues/3

# 参考资料

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
38 changes: 38 additions & 0 deletions jweb/src/edu/hzu/javaweb/bean/UserData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
*
*/
package edu.hzu.javaweb.bean;

/**
* @author zengsn
* @since 8.0
*/
public class UserData {
private String username;
private String email;
private int age;

public void setUsername(String value) {
username = value;
}

public void setEmail(String value) {
email = value;
}

public void setAge(int value) {
age = value;
}

public String getUsername() {
return username;
}

public String getEmail() {
return email;
}

public int getAge() {
return age;
}
}
7 changes: 7 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* 这里为实验的Java代码。各人的代码放在各自学号的包下。
*
* @author zengsn
* @since 8.0
*/
package edu.hzu.javaweb.labs;
57 changes: 57 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se12345678/Se12345678Servlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package edu.hzu.javaweb.labs.se12345678;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/1st")
public class Se12345678Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public Se12345678Servlet() {
super();
}

public void init(ServletConfig config) throws ServletException {

}

public void destroy() {
}

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 已登录
String login = "zhang3";
// Session
HttpSession session = request.getSession(true);
session.setAttribute("username", login); // 登录之后
String username = (String) session.getAttribute("username");
if (username == null) {

}

session.setMaxInactiveInterval(15);

// 返回HTML
StringBuilder html = new StringBuilder();
html.append("<!DOCTYPE html><html><head>");
html.append("<title>First App</title>");
html.append("</head><body>");
html.append("<a id=\"link\" href=\"www.hzu.edu.cn\">惠州学院</a>");
html.append("</body></html>");
response.setCharacterEncoding("utf-8");
response.getWriter().append(html);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}

}
8 changes: 8 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se12345678/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

/**
* 把 12345678 即为学号。
*
* @author zengsn
* @since 8.0
*/
package edu.hzu.javaweb.labs.se12345678;
42 changes: 42 additions & 0 deletions jweb/src/edu/hzu/javaweb/servlet/FirstServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package edu.hzu.javaweb.servlet;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* 这是学号为12345678同学的Java代码。
*
* @author zengsn
* @since 8.0
*/
@WebServlet("/12345678")
public class FirstServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public FirstServlet() {
super();
}

public void init(ServletConfig config) throws ServletException {

}

public void destroy() {
}

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("doGet() -> 这是 12345678 的后台。");
}

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}

}
1 change: 1 addition & 0 deletions jweb/web/12345678/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
各人创建自己的学号目录。
16 changes: 16 additions & 0 deletions jweb/web/GetName.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<FORM METHOD=POST ACTION="SaveName.jsp">
What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR>
What's your e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20><BR>
What's your age? <INPUT TYPE=TEXT NAME=age SIZE=4>
<P>
<INPUT TYPE=SUBMIT>
</FORM>
</body>
</html>
15 changes: 15 additions & 0 deletions jweb/web/GetName.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<jsp:useBean id="user" class="edu.hzu.javaweb.bean.UserData"
scope="session" />
<HTML>
<BODY>
<FORM METHOD=POST ACTION="SaveName.jsp">
What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20
VALUE="<%=user.getUsername()%>"><BR> What's your
e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20
VALUE="<%=user.getEmail()%>"><BR> What's your age? <INPUT
TYPE=TEXT NAME=age SIZE=4 VALUE=<%=user.getAge()%>>
<P>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
3 changes: 3 additions & 0 deletions jweb/web/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path:

10 changes: 10 additions & 0 deletions jweb/web/NextPage.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<jsp:useBean id="user" class="edu.hzu.javaweb.bean.UserData"
scope="session" />
<HTML>
<BODY>
You entered<BR>
Name: <%= user.getUsername() %><BR>
Email: <%= user.getEmail() %><BR>
Age: <%= user.getAge() %><BR>
</BODY>
</HTML>
8 changes: 8 additions & 0 deletions jweb/web/SaveName.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<jsp:useBean id="user" class="edu.hzu.javaweb.bean.UserData"
scope="session" />
<jsp:setProperty name="user" property="*" />
<HTML>
<BODY>
<A HREF="NextPage.jsp">Continue</A>
</BODY>
</HTML>
Binary file added jweb/web/WEB-INF/lib/jstl-1.2.jar
Binary file not shown.
12 changes: 12 additions & 0 deletions jweb/web/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>jweb</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
14 changes: 14 additions & 0 deletions jweb/web/error.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%@ page isErrorPage="true"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>
<head>
<title><fmt:message key="ServerError" /></title>
</head>
<body bgcolor="white">
<h3>
<fmt:message key="ServerError" />
</h3>
<p>: ${pageContext.errorData.throwable.cause}
</body>
</html>
1 change: 1 addition & 0 deletions jweb/web/footer.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>&copy;<%=new java.util.Date()%> Copy Rights.</p>
1 change: 1 addition & 0 deletions jweb/web/index.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OK
16 changes: 16 additions & 0 deletions jweb/web/scriptlet.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<!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=UTF-8">
<title><%=new Date()%></title>
</head>
<body>
<%=new Date()%>

<hr />
<center><%@ include file="footer.jsp" %></center>
</body>
</html>
30 changes: 30 additions & 0 deletions labs/1406070302213/mpq.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@CHARSET "UTF-8";

#main_special{
margin:80px 0 0 50px;
}
#main_special form input{

height:22px;
margin-bottom:20px;
}
#main_special fieldset{
width:450px;
}
#main_special label{
font-size:15px;

}
#main_special #label4{
width:50px;
}
#main_special form{
margin:20px;
padding:0px;
}
#main_special .submit{
margin:10px 0 0 0px;
}
#main_special img{
margin:0 0 0 80px;
}
38 changes: 38 additions & 0 deletions labs/1406070302213/mpq.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<link rel="stylesheet" type="text/css" href="mpq.css"/>
<title>登录</title>
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="main_special">
<fieldset><legend>登录</legend>
<form action="" method="post">
<label for="label1">用&nbsp; 户&nbsp; 名:</label>
<input type="text" name="name" id="username label1"/><font style="font-size:12px;color:#898983"> *用户名不得超过16位字符</font><br>
<label for="label2">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:</label>
<input type="password" name="pw" id="password label2"/><font style="font-size:12px;color:#898983"> *密码不能超过16位字符</font><br>
<input type="submit" name="submit" class="submit" value="登录"/>
<input type="reset" name="reset" class="submit" value="重置"/>
</form>
</fieldset>
</div>
<script type="text/javascript">
$( ".submit" ).click(function(event) {
alert("登录成功");
$.ajax({
url: "success.json"
}).done(function(data){
if (console&&console.log){
var account = $('#username').value;
var password = $('#password').value;
console.dir(data);
alert(data.msg);
}
})
});
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions labs/1406070302213/success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"msg": "保存成功!"
}
Loading

0 comments on commit 8b509be

Please sign in to comment.