导航:首页 > 净水问答 > jsp过滤器过滤文件夹下的

jsp过滤器过滤文件夹下的

发布时间:2024-09-13 23:16:51

A. jsp 过滤器拦截URL时,如何把URL后面参数加上

最近在做项目中,发现jsp的过滤器在获取到拦截的URL时,得到的URL没有加入URL后面的参数,这样就造成在用response.sendRedirect时,无法加入后面的参数,本人研究后,发现可以这么解决,希望对大家有所帮助<pString currentURL = req.getRequestURI(); // 取得根目录所对应的绝对路猜衫径: java.util.Enumeration enumParam = req.getParameterNames(); StringBuffer condition = new StringBuffer("?"); boolean isHasCondition = false; while(enumParam.hasMoreElements()){ isHasCondition = true; String paramName = enumParam.nextElement(); condition.append(paramName); condition.append("="); condition.append(request.getParameter(paramName)); condition.append("&"); } if(isHasCondition){ currentURL += condition.toString(); }</p<p </橘兆仔p<圆汪p </p

B. jsp/servlet过滤器和struts2拦截器的有什么区别

拦截器和过滤器的区别:

1、拦截器是基于java的反射机制的,而过滤器是基于函数回调

2、过滤器依赖与servlet容器,而拦截器不依赖与servlet容器

3、拦截器只能对action请求起作用,而过滤器则可以对几乎所有的请求起作用

4、拦截器可以访问action上下文、值栈里的对象,而过滤器不能

5、在action的生命周期中,拦截器可以多次被调用,而过滤器只能在容器初始化时被调用一次

拦截器
:是在面向切面编程的就是在你的service或者一个方法前调用一个方法,或者在方法后调用一个方法比如动态代理就是拦截器的简单实现,在你调用方法前打印出字符串(或者做其它业务逻辑的操作),也可以在你调用方法后打印出字符串,甚至在你抛出异常的时候做业务逻辑的操作。

下面通过实例来看一下过滤器和拦截器的区别:

使用拦截器进行/admin 目录下jsp页面的过滤

[html] view plain

<package name="newsDemo"
extends="struts-default"

namespace="/admin">

<interceptors>

<interceptor name="auth"
class="com.test.news.util.AccessInterceptor" />

<interceptor-stack name="authStack">

<interceptor-ref
name="auth" />

</interceptor-stack>

</interceptors>

<!-- action -->

<action name="newsAdminView!*" class="newsAction"

method="{1}">

<interceptor-ref
name="defaultStack"/>

<interceptor-ref
name="authStack">

</interceptor-ref>

下面是我实现的Interceptor class:

[java] view plain

package com.test.news.util;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

import
com.opensymphony.xwork2.ActionInvocation;

import
com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import
com.test.news.action.AdminLoginAction;

/**

*
@author chaoyin

*/

public class AccessInterceptor
extends AbstractInterceptor {

private static final long
serialVersionUID = -4291195782860785705L;

@Override

public String intercept(ActionInvocation actionInvocation) throws
Exception {

ActionContext actionContext =
actionInvocation.getInvocationContext();

Map session =
actionContext.getSession();

//except login action

Object action = actionInvocation.getAction();

if (action
instanceof AdminLoginAction) {

return
actionInvocation.invoke();

}

//check
session

if(session.get("user")==null ){

return
"logout";

}

return actionInvocation.invoke();//go
on

}

}

过滤器:是在javaweb中,你传入的request,response提前过滤掉一些信息,或者提前设置一些参数,然后再传入servlet或者struts的
action进行业务逻辑,比如过滤掉非法url(不是login.do的地址请求,如果用户没有登陆都过滤掉),或者在传入servlet或者
struts的action前统一设置字符集,或者去除掉一些非法字符。

使用过滤器进行/admin
目录下jsp页面的过滤,首先在web.xml进行过滤器配置:

[html] view plain

<filter>

<filter-name>access
filter</filter-name>

<filter-class>

com.test.news.util.AccessFilter

</filter-class>

</filter>

<filter-mapping>

<filter-name>access filter</filter-name>

<url-pattern>/admin/*</url-pattern>

</filter-mapping>

下面是过滤的实现类:

[java] view
plain

package com.test.news.util;

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
javax.servlet.http.HttpSession;

public class AccessFilter
implements Filter {

/**

* @author chaoyin

*/

public void destroy() {

}

public void doFilter(ServletRequest arg0, ServletResponse arg1,

FilterChain filterChain) throws IOException, ServletException {

HttpServletRequest request = (HttpServletRequest)arg0;

HttpServletResponse response = (HttpServletResponse)arg1;

HttpSession session = request.getSession();

if(session.getAttribute("user")== null &&
request.getRequestURI()。indexOf("login.jsp")==-1 ){

response.sendRedirect("login.jsp");

return ;

}

filterChain.doFilter(arg0, arg1);

}

public void init(FilterConfig arg0) throws ServletException {

}

}
摘自网络--

C. 关于jsp过滤器的问题,为什么把图片都过滤了呢

jsp过滤器主要的作用是保证页面支持中文输入和显示,
或者应用在一些论坛专上过滤一些不文明的词汇等属。
但是图片被过滤了是不可能的。
无非就是路径写错了,不知道楼主写的路径是相对的还是绝对的。
有一个好办法看路径的正误:右键点击X图,属性,查看该图片路径是否与你项目中保存的图片是同一个文件夹下的。
希望能帮的上你。

D. 当定义多个过滤器时,执行的顺序是什么样的

filter和拦截器的区别和执行顺序

1.Filter过滤器只过滤jsp文件不过滤action请求解决回方案

解决办法:在web.xml中将答filter的配置放在struts2配置的前面。

2.拦截器与Filter的区别
Spring的拦截器与Servlet的Filter有相似之处,比如二者都是AOP编程思想的体现,都能实现权限检查、日志记录等。不同的是:

使用范围不同:Filter是Servlet规范规定的,只能用于Web程序中。而拦截器既可以用于Web程序,也可以用于Application、Swing程序中。

规范不同:Filter是在Servlet规范中定义的,是Servlet容器支持的。而拦截器是在Spring容器内的,是Spring框架支持的。

使用的资源不同:同其他的代码块一样,拦截器也是一个Spring的组件,归Spring管理,配置在Spring文件中,因此能使用Spring里的任何资源、对象,例如Service对象、数据源、事务管理等,通过IoC注入到拦截器即可;而Filter则不能。

E. struts2用过滤器过滤非法jsp请求的时候,对于根文件夹下的请求如何过滤

<filter>
<filter-name>authority</filter-name>
<filter-class>com.bstek.test.demo.filter.AuthorityFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>authority</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--可以匹配多个的,不过只要上面那种就回可以拦截所有的了答<filter-mapping>
<filter-name>authority</filter-name>
<url-pattern>/jsp/*</url-pattern>
</filter-mapping>-->

F. 设计用户过滤器 对需要保护的页面过滤 如果已经登录则允许访问 否则跳转到login.jsp

比如你将要需抄要登录后才能访问的页面放在main文件夹下,然后配置过滤器时,将过滤路径设置为/main/*就可以了,login.jsp不能放在main文件夹中,防止login.jsp也被过滤,造成死循环。。。。

G. jsp中为什么加上了过滤器就报错 (HTTP Status 404)

路径配置错误

H. filter过滤器配置如何不过滤一些页面

直接添加多个文件映射啊,为每个需要进行过滤的文件都写个映射标签

I. jsp中过滤器可以拦截请求和响应吗

过滤器可以动态地拦截请求和响应,以变换或使用包含在请求或响应中的信息。

阅读全文

与jsp过滤器过滤文件夹下的相关的资料

热点内容
净水机连清洗口怎么连 浏览:711
纯水机和净水器有什么区别吗 浏览:586
原生质层与半透膜的差异 浏览:598
容声净水器是哪个公司 浏览:553
佛山废水处理证书收费多少 浏览:977
净水机外面滤芯怎么换 浏览:527
反分裂反渗透国旗下讲话 浏览:766
净水器滤芯如何拆装 浏览:34
蒸馏水机的用处 浏览:266
重庆污水处理厂公交站 浏览:464
奥运场馆饮水机多少个 浏览:188
edi软件功能 浏览:966
巫师3蒸馏器零件给不给 浏览:524
污水处理厂大圆盘 浏览:137
250过滤器图片 浏览:994
油污水乳化油怎么去除 浏览:275
泽德污水提升泵microboy 浏览:483
污水厂空压机休眠怎么解决 浏览:927
如何使用卡在小区净水器上技巧 浏览:177
砌筑污水井和雨水井 浏览:225