-
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 #517 from 1414080902208/master
- Loading branch information
Showing
4 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
jweb/src/edu/hzu/javaweb/labs/se1414080902208/EncodeFilter.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,42 @@ | ||
package edu.hzu.javaweb.labs.se1414080902208; | ||
|
||
|
||
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; | ||
|
||
/** | ||
* Servlet Filter implementation class EncodeFilter | ||
*/ | ||
@WebFilter(filterName="EncodeFilter",urlPatterns="/*") | ||
public class EncodeFilter implements Filter { | ||
|
||
public EncodeFilter() { | ||
|
||
} | ||
|
||
|
||
public void destroy() { | ||
|
||
} | ||
|
||
|
||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
|
||
System.out.println("±àÂë¹ýÂË..."); | ||
request.setCharacterEncoding("UTF-8"); | ||
|
||
response.setContentType("text/html;charset=UTF-8"); | ||
|
||
chain.doFilter(request, response); | ||
} | ||
|
||
public void init(FilterConfig fConfig) throws ServletException { | ||
System.out.println("ͳһ±àÂë..."); | ||
} | ||
|
46 changes: 46 additions & 0 deletions
46
jweb/src/edu/hzu/javaweb/labs/se1414080902208/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,46 @@ | ||
package edu.hzu.javaweb.labs.se1414080902208; | ||
|
||
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="LoginFilter",urlPatterns="/login.jsp") | ||
public class LoginFilter implements Filter { | ||
|
||
public LoginFilter() { | ||
|
||
} | ||
public void destroy() { | ||
|
||
} | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
|
||
HttpServletRequest req = (HttpServletRequest) request; | ||
HttpServletResponse resp = (HttpServletResponse) response; | ||
|
||
HttpSession session = req.getSession(); | ||
String path=req.getContextPath(); | ||
String basePath=req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+path; | ||
String userName=(String)session.getAttribute("username"); | ||
if (userName==null) { | ||
resp.sendRedirect(basePath+"/faile.jsp"); | ||
} else { | ||
chain.doFilter(request, response); | ||
} | ||
} | ||
public void init(FilterConfig fConfig) throws ServletException { | ||
System.out.println("µÇ¼¹ýÂË..."); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
jweb/src/edu/hzu/javaweb/labs/se1414080902208/Se1414080902208Servlet.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,55 @@ | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
@WebServlet("/1414080902208") | ||
public class Se1414080902208Servlet extends HttpServlet { | ||
|
||
request.setCharacterEncoding("gb2312"); | ||
response.setCharacterEncoding("gb2312"); | ||
PrintWriter out = response.getWriter(); | ||
String Score = new String(request.getParameter("score")); | ||
String Comment = new String(request.getParameter("comment")); | ||
HttpSession session=request.getSession(true); | ||
String msg = ""; | ||
if (Score.equals("")) { | ||
out.println("评分不能为空"); | ||
msg = "评分不能为空"; | ||
} else if (Comment.equals("")) { | ||
out.println("评论不能为空"); | ||
msg = "评论不能为空"; | ||
} else { | ||
boolean flat = true; | ||
char[] str=Score.toCharArray(); | ||
for (int i = 0;i < Score.length();i++) { | ||
int x = str[i] - '0'; | ||
if (!(x >= 0 && x <= 10)) { | ||
// 评分最大为10分 | ||
out.println("请输入正确的评分"); | ||
msg = "请输入正确的评分"; | ||
flat = false; | ||
break; | ||
} | ||
|
||
for (int i = 0;i < Amount.length();i++) { | ||
int x = sstr[i] - '0'; | ||
if (!(x >= 0 && x <= 100)) { | ||
|
||
//评论字数最多为100 out.println("请在字数范围内输入评论"); | ||
msg = "请在字数范围内输入评论"; | ||
flat = false; | ||
break; | ||
} | ||
} | ||
} | ||
if (flat) out.println("评价成功"); | ||
if (flat) msg = "评价成功"; | ||
} | ||
System.out.println(msg); | ||
request.setAttribute("message", msg); | ||
request.getRequestDispatcher("/index.jsp").forward(request, response); | ||
|
||
session.setAttribute("message", msg); | ||
|
||
|
||
|
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,50 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> | ||
<link href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"> | ||
|
||
<center>Now time is: | ||
<%=new java.util.Date()%> | ||
</center> | ||
<form id="register" action="servlet/Se1414080902208Servlet" method="post"> | ||
<form id="register" action="/LabForTwo/servlet/Se1414080902208Servlet" method="post"> | ||
<div class="form-group"> | ||
<label for="score">Score *</label> | ||
<input type="text" id="Score" class="form-control" /> | ||
|
||
</div> | ||
<div class="form-group"> | ||
<label for="comment">Comment *</label> | ||
<input type="text" id="Comment" class="form-control"/> | ||
|
||
<c:if test="${!empty sessionScope.message}"> | ||
<c:out value="${sessionScope.message}"></c:out> | ||
</c:if> | ||
</div> | ||
<div style = "text-align:right;"> | ||
<button type="button" class="btn btn-default">Confirm</button> | ||
<button type="submit" class="btn btn-default">Confirm</button> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
</body> | ||
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script> | ||
<!-- <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script> | ||
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> | ||
<script type="text/javascript"> | ||
$( ".btn" ).click(function() { | ||
@@ -42,9 +46,10 @@ ATM Transfer | ||
type : "post", | ||
datatype:"html", | ||
success: function(data){ | ||
alert(data); | ||
//alert(data); | ||
}}); | ||
}); | ||
</script> | ||
--> | ||
|
||
</html> |