说明:
以下代码运行环境:jdk1.4,工具JBuilder2005,Servlet2.4,JSP2.0
红色标记为关键代码.由于工程太大,我在这里只放有XML文件、JSP文件、过滤器
具体内容用论坛回复。 顺序为:JSP文件---过滤器---XML文件.
| <%@ page contentType="text/html; charset=GBK" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <% Object str= request.getAttribute("user"); pageContext.setAttribute("user",str); %> <html> <head> <title> |
过滤器
| </title> </head> <body bgcolor="#ffffff"> <h1> |
准备过滤
| </h1> <h1>${pageScope.user}</h1> <form method="post" action="Example1.jsp"> <br> <input type="text" name="user" /> <br> <input type="submit" name="Submit" value="Submit"> <input type="reset" value="Reset"> </form> </body> </html> |
文字
|
<%@ page contentType="text/html; charset=GBK" %> import javax.servlet.*; public class Filter1 extends HttpServlet implements Filter { //Process the request/response pair try { if (user == null || user.equals("")) { } else { } //Clean up resources |
注:此“XML”代码是在运行时出现的,
| <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>Web</display-name> <filter> <filter-name>filter1</filter-name> <filter-class>com.lgx.filtertext.dao.Filter1</filter-class> </filter> <filter-mapping> <filter-name>filter1</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <description>Added by JBuilder to compile JSPs with debug info</description> <servlet-name>debugjsp</servlet-name> <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class> <init-param> <param-name>classdebuginfo</param-name> <param-value>true</param-value> </init-param> <load-on-startup>3</load-on-startup> </servlet> <servlet-mapping> <servlet-name>debugjsp</servlet-name> <url-pattern>*.jsp</url-pattern> </servlet-mapping> </web-app> |
注:这一处代码是配置过滤器的,不过JBuilder2005里面Tomcat容器已自动配置
| <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>Web</display-name> <filter> <filter-name>filter1</filter-name> <filter-class>com.lgx.filtertext.dao.Filter1</filter-class> </filter> <filter-mapping> <filter-name>filter1</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> |
相关专题
- 用JFreeChart增强JSP报表的用户体验 (81次浏览)
- 解析Servlet/JSP会话跟踪机制 (34次浏览)
- 自行开发JSP HTTP服务器的绝对秘籍(二) (19次浏览)
- 整理近几天处理JSP页面中遇到的几个问题 (19次浏览)
- 我们还需要JSP吗? (18次浏览)
- 两级下拉框的JSP简单实现 (17次浏览)
- 在Apache中整合JSP和PHP (14次浏览)
- 深入讲解提升JSP应用程序的七个方法 (11次浏览)
- JSP/Servlet/JSF中对标签库的深入研究 (10次浏览)
- JSP/Servlet:Servlet/JSP会话跟踪机制 (7次浏览)



