-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from hzuapps/master
1212152
- Loading branch information
Showing
444 changed files
with
59,290 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+2.36 KB
jweb/build/classes/edu/hzu/javaweb/labs/se12345678/Se12345678Servlet.class
Binary file not shown.
Binary file added
BIN
+137 Bytes
jweb/build/classes/edu/hzu/javaweb/labs/se12345678/package-info.class
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
57
jweb/src/edu/hzu/javaweb/labs/se12345678/Se12345678Servlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
91 changes: 91 additions & 0 deletions
91
jweb/src/edu/hzu/javaweb/labs/se1406070302213/Se1406070302213Servlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package edu.hzu.javaweb.labs.se1406070302213; | ||
|
||
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 Se1406070302213Servlet extends HttpServlet { | ||
|
||
/** | ||
* Constructor of the object. | ||
*/ | ||
public Se1406070302213Servlet() { | ||
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.println(" Hello!Mr Zeng!"); | ||
out.println(" <br>"); | ||
out.println(" My student number is 1406070302213.Thanks!"); | ||
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.println(" Hello!Mr Zeng!"); | ||
out.println(" <br>"); | ||
out.println(" My student number is 1406070302213.Thanks!"); | ||
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 | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
jweb/src/edu/hzu/javaweb/labs/se1414080902108/Se1414080902108Servlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package edu.hzu.javaweb.labs.se1414080902108; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* Servlet implementation class Se1414080902108Servlet | ||
*/ | ||
@WebServlet("/1414080902108") | ||
public class Se1414080902108Servlet extends HttpServlet { | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* @see HttpServlet#HttpServlet() | ||
*/ | ||
public Se1414080902108Servlet() { | ||
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 | ||
|
||
} | ||
|
||
/** | ||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) | ||
*/ | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
// TODO Auto-generated method stub | ||
String subject = request.getParameter("subject"); | ||
String question = request.getParameter("question"); | ||
String answer1 = request.getParameter("answer1"); | ||
String answer2 = request.getParameter("answer2"); | ||
String answer3 = request.getParameter("answer3"); | ||
String answer4 = request.getParameter("answer4"); | ||
String answer = request.getParameter("answer"); | ||
String info = "保存成功"; | ||
|
||
|
||
request.setAttribute("Message", info); | ||
request.setAttribute("subject", subject); | ||
request.setAttribute("question", question); | ||
request.setAttribute("answer1", answer1); | ||
request.setAttribute("answer2", answer2); | ||
request.setAttribute("answer3", answer3); | ||
request.setAttribute("answer4", answer4); | ||
request.setAttribute("answer", answer); | ||
request.getRequestDispatcher("/show.jsp").forward(request, response); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
jweb/src/edu/hzu/javaweb/labs/se1414080902110/EncodingFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package edu.hzu.javaweb.labs.se1414080902110; | ||
|
||
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; | ||
|
||
@WebFilter(filterName = "EncodingFilter", urlPatterns = "/*") | ||
public class EncodingFilter implements Filter { | ||
|
||
@Override | ||
public void destroy() { | ||
// TODO Auto-generated method stub | ||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, | ||
FilterChain chain) throws IOException, ServletException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setCharacterEncoding("UTF-8"); | ||
chain.doFilter(request, response); | ||
} | ||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
// TODO Auto-generated method stub | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
jweb/src/edu/hzu/javaweb/labs/se1414080902110/JDBCconnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package edu.hzu.javaweb.labs.se1414080902110; | ||
|
||
import java.sql.*; | ||
|
||
public class JDBCconnection { | ||
public Connection connection() { | ||
String driverName = "com.mysql.jdbc.Driver"; | ||
String userName = "root"; | ||
String userpwd = "123456"; | ||
String dbName = "musicforum"; | ||
String url1 = "jdbc:mysql://localhost:3306/" + dbName; | ||
String url2 = "?user=" + userName + "&password=" + userpwd; | ||
String url3 = "&useUnicode=true&characterEncoding=UTF-8"; | ||
String url = url1 + url2 + url3; | ||
try { | ||
Class.forName(driverName); | ||
} catch (ClassNotFoundException driver) { | ||
driver.printStackTrace(); | ||
} | ||
try { | ||
Connection connection = DriverManager.getConnection(url); | ||
return connection; | ||
} catch (SQLException sql) { | ||
sql.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
jweb/src/edu/hzu/javaweb/labs/se1414080902110/LoginFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package edu.hzu.javaweb.labs.se1414080902110; | ||
|
||
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; | ||
|
||
@WebFilter(filterName = "LoginFilter", urlPatterns = "/essay/*") | ||
public class LoginFilter 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 req = (HttpServletRequest) request; | ||
HttpServletResponse res = (HttpServletResponse) response; | ||
|
||
HttpSession session = req.getSession(); | ||
if (session.getAttribute("loginUserAccount") != null) { | ||
chain.doFilter(request, response); | ||
} else { | ||
res.sendRedirect("../error.jsp"); | ||
} | ||
} | ||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.