嗯,如果需要登陆的才能进行的操作页面可以加一个这样的验证,如果验证不通过,自动调转到登陆页面。可以把这个代码写到一个jsp里面,然后需要登陆的页面引用这个jsp即可。也可以用更复杂的spring struts等等。
解决方案 »
- NoSuchMethodError 我知道是调用不存在的类 但是我后来删了差不多东西还是出来这个。。。大家帮我看看谢谢了!我已经删了没多少代码了
- 这段代码看不懂,帮忙看看咯
- 关于StringBuilder 的 请高手 解答!!!!
- 求如何将iText生成的条码IMAGE保存为图像文件
- 树状分航栏
- 怎样替换文件里的内容呢?
- weblogic为什么总是拒绝我,不能登陆!
- 关于Strut1.1+Tomcat5.0的问题!!!
- 谁有在struts结构中使用action操作数据库的例子 ?
- 关于JBuilder 7 WebLogic 6.X 详细配置的问题!!!!
- web services 学习
- [有关Tomcat如何调试]问一个看似很简单的问题,可能真的很简单
或者可以写一个servlet监听器,对登录的session进行监听。
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.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import cc.hotel.login.vo.Person;public class ControlFilter implements Filter {
private FilterConfig config = null; private String encoding = null; private String forword = null; private String path = null; private boolean bl = true; public void destroy() {
config = null;
encoding = null;
forword = null;
path = null;
bl = true;
} public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpRequest.setCharacterEncoding("gb2312"); // 改变请求编码方式
httpResponse.setCharacterEncoding("gb2312"); // 改变响应编码方式
path = httpRequest.getServletPath(); // 获得请求路径
System.out.println(path);
/*---------------------------权限控制----------------------------------*/
if (path.endsWith(".jsp") || path.endsWith(".do")) {
if (path.endsWith("login.jsp") || path.endsWith("login.do")) {
} else {Person admin = (Person) httpRequest.getSession()
.getAttribute("person");
if (admin == null) {
bl = false;
}
}
}
/*---------------------------权限控制 end----------------------------------*/
if (bl) {
chain.doFilter(request, response);
} else { // 非法进入系统,返回登陆页面
bl = true;
httpRequest.getRequestDispatcher(forword).forward(httpRequest,
httpResponse);
}
}
public void init(FilterConfig config) throws ServletException {
this.config = config;
encoding = config.getInitParameter("gb2312");
forword = config.getInitParameter("forword");
}
}
同样也谢谢其他人。