Skip to content

Commit

Permalink
Merge pull request #2 from hzuapps/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
YanghaoZYH authored Oct 24, 2016
2 parents e3ee0aa + 39b68e9 commit 71331a1
Show file tree
Hide file tree
Showing 287 changed files with 49,723 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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package edu.hzu.javaweb.labs.se1414080902134;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletContext;
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 java.util.Enumeration;
import java.util.Iterator;

//import edu.hzu.javaweb.bean.se1414080902134.UserData;
import javafx.application.Application;

/**
* Servlet implementation class Se1414080902134Servlet
*/
@WebServlet("/1414080902134")
public class Se1414080902134Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public Se1414080902134Servlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
ServletContext application=this.getServletContext();
application.setAttribute("message","only dear with post method .");
response.sendRedirect("/1414080902134/Home.jsp");
// PrintWriter out = response.getWriter();
// UserData ud = new UserData();
// Enumeration<String> iter_ = (request.getParameterNames());
// while (iter_.hasMoreElements()) {
// String key = iter_.nextElement();
// ud.setAttribute(key,request.getParameter(key));
// }
// if (ud.getQuickCode().equals("")) {
// if (!ud.isComplete()) {
// out.write("Information is not full .");
// } else {
// if (ud.getUserName().isEmpty()) {
// out.write("Welcome , " + ud.getEmail());
// } else {
// out.write("Welcome , " + ud.getUserName());
// }
// }
// } else {
// out.write("QuickCode = " + ud.getQuickCode());
// }
//
// out.flush();
//response.getWriter().append("Served at: ").append(request.getContextPath());
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
ServletContext application=this.getServletContext();
boolean isLogin = false;
PrintWriter out = response.getWriter();
UserData ud = new UserData();
Enumeration<String> iter_ = (request.getParameterNames());
while (iter_.hasMoreElements()) {
String key = iter_.nextElement();
ud.setAttribute(key,request.getParameter(key));
}
if (ud.getQuickCode().equals("")) {
if (!ud.isComplete()) {
out.write("Information is not full .");
} else {
if (ud.getUserName().isEmpty()) {
out.write("Welcome , " + ud.getEmail());
isLogin = true;
} else {
out.write("Welcome , " + ud.getUserName());
isLogin = true;
}
}
} else {
out.write("QuickCode = " + ud.getQuickCode());
//isLogin = true;
}
if (ud.isComplete()) {
if (isLogin) {
application.setAttribute("UserData",ud);
response.sendRedirect("1414080902134/HomeUser.jsp");
} else {
//TO DO
//SEARCH SOMETHING FROM DATABASE BY THE QUICKCODE
}
} else {
response.sendRedirect("1414080902134/Home.jsp");
}
out.flush();
}

}
80 changes: 80 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902134/UserData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package edu.hzu.javaweb.bean.se1414080902134;

public class UserData {
private String UserName;
private String Email;
private String Password;
private String QuickCode;
private boolean Remeber;
public UserData(){
UserName = "";
Email = "";
Password = "";
QuickCode = "";
Remeber = false;
}
public String getUserName() {
return UserName;
}
public void setUserName(String userName) {
UserName = userName;
}
public String getEmail() {
return Email;
}
public void setEmail(String email) {
Email = email;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
Password = password;
}
public String getQuickCode(){
return QuickCode;
}
public void setQuickCode(String qc){
QuickCode = qc;
}
public boolean getRemeber() {
return Remeber;
}
public void setRemeber(boolean reamber) {
Remeber = reamber;
}
public void setAttribute(String key,String value){
//System.out.println(key + " +++ " + value);
if (key.toLowerCase().equals("username")) {
setUserName(value);
} else if (key.toLowerCase().equals("email")) {
setEmail(value);
} else if (key.toLowerCase().equals("password")) {
setPassword(value);
} else if (key.toLowerCase().equals("quickcode")) {
setQuickCode(value);
} else if (key.toLowerCase().equals("Remeber")) {
if (value.toLowerCase().equals("on")) {
setRemeber(true);
}
}
}
public boolean isComplete(){
//System.out.println(Password + "\t" + UserName + "\t" + Email);
if (QuickCode.equals("")) {
if (Password.equals("")) {
System.out.println("Password false");
return false;
} else {
if (UserName.equals("") && Email.equals("")) {
System.out.println("UserName false");
return false;
} else {
return true;
}
}
} else {
return true;
}
}
}
Loading

0 comments on commit 71331a1

Please sign in to comment.