楼主是不是只允许在iframe内页访问,
如果是这样的话,可以在访问的页面用js简单处理一下。<script>
window.onload = function(){
if(window.location == top.location){
alert('禁止访问');
window.self.close();
}
}
</script>
如果是这样的话,可以在访问的页面用js简单处理一下。<script>
window.onload = function(){
if(window.location == top.location){
alert('禁止访问');
window.self.close();
}
}
</script>
在每个表单页面建个隐藏域,在隐藏域里赋值,再建一个filter,过滤所有action,在该filter内用request获取隐藏域的值,若该值为空,可自定义跳转页面。否则跳转到相应action
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest)arg0;
HttpServletResponse response =(HttpServletResponse)arg1;
String url = request.getRequestURI();
if(url.endsWith(".action")){
response.getWriter().print("<script>window.location.href="你的登录地址"</script>");
}else{
arg2.doFilter(arg0, arg1);
}
}}
*.action
------------------------
用户必须通过你的链接来访问?建议:链接地址加一个KEY
还是你的ACTION还是屏蔽非登录用户?建议:这个不用说了吧,大家都懂!
这样的话,我自己项目中所跳转的action也被拦截了。我只想拦截从地址栏输入的action
http://localhost:8080/ss/Article/article!getCategory.action 这样的action
就是让他不显示,用户看不到也就不会去直接输入action的名字了。求助~!
++1浏览器地址栏输入url访问服务器资源都输入get提交,
你在过滤器中这样写,就把所有get提交给禁止了:if ("GET".equalsIgnoreCase(request.getMethod())) {
....// 这里做跳转处理
}
<struts>
<!-- 定义权限拦截器 -->
<package name="author" extends="struts-default">
<!-- 拦截器 -->
<interceptors>
<!-- 定义权限拦截器 -->
<interceptor name="Authority"
class="com.mas.web.interceptor.AuthorityInterceptor"></interceptor>
<interceptor name="Permission"
class="com.mas.web.interceptor.PermissionInterceptor"></interceptor>
<!-- 定义拦截器栈 -->
<interceptor-stack name="default">
<!-- 引用默认拦截器 -->
<interceptor-ref name="defaultStack"></interceptor-ref>
<!-- 引用权限拦截器 -->
<interceptor-ref name="Authority"></interceptor-ref>
<interceptor-ref name="Permission"></interceptor-ref>
<!-- -->
</interceptor-stack>
</interceptors>
</package>
</struts>其中com.mas.web.interceptor.AuthorityInterceptor是自定义拦截器,在里面进行校验就可以了。
可以使用url rewrite或者使用拦截器,拦截未登录的用户。我就是这两种方式来实现的。
我请教个问题,就是如何在action中判断请求是否直接来自浏览器地址栏。 就是那个action 是要通过iframe访问的。所以想屏蔽地址栏直接访问。