怎么回事,我用JB9写一个简单的过滤SERVELT,没有效果!

skyboy0720 2005-10-05 03:12:46
我建立WEB应用程序,跟目录下有个login.jsp
跟目录下有个manage目录,在manage目录下有test1.test2两个文件
然后再创建一个filter servlet
代码如:
package dqh.filter;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class SignonFilter extends HttpServlet implements Filter {
private FilterConfig filterConfig;
String LoginPage="login.jsp";
//Handle the passed-in FilterConfig
public void init(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
}
//Process the request/response pair
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
HttpServletRequest hreq=(HttpServletRequest)request;
HttpServletResponse hres=(HttpServletResponse)response;
HttpSession session=hreq.getSession();
String isLogin="";
try {
isLogin=(String)session.getAttribute("isLogin");
if(isLogin.equals("true")){
System.out.println("OK");
filterChain.doFilter(request, response);
}
else{
hres.sendRedirect(LoginPage);
System.out.println("Error");
}
}
catch(ServletException sx) {
filterConfig.getServletContext().log(sx.getMessage());
}
catch(IOException iox) {
filterConfig.getServletContext().log(iox.getMessage());
}
}
//Clean up resources
public void destroy() {
this.filterConfig=null;
}
}


然后运行/manage/test1.jsp,它并没有转向login.jsp文件,怎么回事???
...全文
75 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
skyboy0720 2005-10-05
  • 打赏
  • 举报
回复
楼上的,不知道你用过JB9没,你手动加上去,当你运行的时候,这段代码就不见了
它的WEB-INF里的一些配置是动态的

其实当你用JB建立Filter Servelt的时候,会让你填写url-pattern,可问题是建完以后
web-inf里却没有上面那段代码
UPCCPU 2005-10-05
  • 打赏
  • 举报
回复
<filter-mapping>
<filter-name>signonfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
skyboy0720 2005-10-05
  • 打赏
  • 举报
回复
我查看了web-inf的配置文件,它没有自动生成filter-mapping这个配置,
只有
<filter>
<filter-name>signonfilter</filter-name>
<filter-class>dqh.filter.SignonFilter</filter-class>
</filter>
可是我手动加上去以后,再运行,我加的东西也没有,它自动生成其他一些
如 <load-on-startup>3</load-on-startup>等等

请教老鸟,不知道我说清楚没有!

81,115

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧