diff --git a/jweb/edu/hzu/javaweb/labs/se1414080902229/se1414080902229.java b/jweb/edu/hzu/javaweb/labs/se1414080902229/se1414080902229.java new file mode 100644 index 00000000..fb357a74 --- /dev/null +++ b/jweb/edu/hzu/javaweb/labs/se1414080902229/se1414080902229.java @@ -0,0 +1,21 @@ +package se1414080902229; + +import javax.servlet.annotation.WebServlet; +import java.io.IOException; + +/** + * Created by yuan on 2016/11/7. + */ +@WebServlet(value = "/se1414080902229") +public class se1414080902229 extends javax.servlet.http.HttpServlet { + protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException { + request.setCharacterEncoding("utf-8"); + response.setCharacterEncoding("utf-8"); + response.setContentType("text/html; charset=utf-8"); + response.getWriter().println("servlet 接受成功"); + } + + protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException { + doPost(request,response); + } +} diff --git a/jweb/src/edu/hzu/javaweb/labs/se1414080902229/EncodingFilter.java b/jweb/src/edu/hzu/javaweb/labs/se1414080902229/EncodingFilter.java new file mode 100644 index 00000000..d7fe852e --- /dev/null +++ b/jweb/src/edu/hzu/javaweb/labs/se1414080902229/EncodingFilter.java @@ -0,0 +1,25 @@ +package filter; + +import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import java.io.IOException; + +/** + * Created by yuan on 2016/11/28. + */ +@WebFilter(filterName = "EncodingFilter",urlPatterns = "/*") +public class EncodingFilter implements Filter { + public void destroy() { + } + + public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException { + req.setCharacterEncoding("utf-8"); + resp.setCharacterEncoding("utf-8"); + chain.doFilter(req, resp); + } + + public void init(FilterConfig config) throws ServletException { + + } + +} diff --git a/jweb/src/edu/hzu/javaweb/labs/se1414080902229/LoginFilter.java b/jweb/src/edu/hzu/javaweb/labs/se1414080902229/LoginFilter.java new file mode 100644 index 00000000..36e1b3a0 --- /dev/null +++ b/jweb/src/edu/hzu/javaweb/labs/se1414080902229/LoginFilter.java @@ -0,0 +1,35 @@ +package filter; + +import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; + +/** + * Created by yuan on 2016/11/21. + */ +@WebFilter(filterName = "LoginFilter") +public class LoginFilter implements Filter { + public void destroy() { + } + + public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException { + HttpServletRequest request = (HttpServletRequest)req; + HttpServletResponse response = (HttpServletResponse)resp; + HttpSession session = request.getSession(); + String judge = (String)session.getAttribute("login"); + if(judge!=null&&judge.equals("1")){ + chain.doFilter(req, resp); + }else{ + response.sendRedirect("index.jsp"); + } + } + + public void init(FilterConfig config) throws ServletException { + + } + +} diff --git a/jweb/src/edu/hzu/javaweb/labs/se1414080902229/se1414080902229Servlet.java b/jweb/src/edu/hzu/javaweb/labs/se1414080902229/se1414080902229Servlet.java new file mode 100644 index 00000000..6285cfe4 --- /dev/null +++ b/jweb/src/edu/hzu/javaweb/labs/se1414080902229/se1414080902229Servlet.java @@ -0,0 +1,21 @@ +package se1414080902229; + +import javax.servlet.annotation.WebServlet; +import java.io.IOException; + +/** + * Created by yuan on 2016/11/7. + */ +@WebServlet(value = "/se1414080902229") +public class se1414080902229Servlet extends javax.servlet.http.HttpServlet { + protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException { + request.setCharacterEncoding("utf-8"); + response.setCharacterEncoding("utf-8"); + response.setContentType("text/html; charset=utf-8"); + response.getWriter().println("servlet 接受成功"); + } + + protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException { + doPost(request,response); + } +} diff --git a/labs/1414080902229/index.jsp b/labs/1414080902229/index.jsp new file mode 100644 index 00000000..94395e73 --- /dev/null +++ b/labs/1414080902229/index.jsp @@ -0,0 +1,82 @@ +<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> +<% +String path = request.getContextPath(); +String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; +%> + + + +
+