struts2 页面跳转控制传参问题
2012-02-23 16:23
357 查看
之前网站做的基本差不错了,客户有其他的活动需求,考虑可以用struts2的拦截器实现
拦截器代码:
applicationContext.xml文件中引入拦截器配置文件
interceptorContext.xml文件内容:
拦截器代码:
package org.main.manage.interceptor.temp; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext; import org.main.common.util.PropertyUtil; import org.main.manage.dict.OrderDict; import org.main.manage.entity.TSecond; import org.main.manage.entity.TUser; import org.main.manage.service.OrderService; import org.main.manage.service.SecondService; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; public class TaiAnCBCSecTempInterceptor implements Interceptor { private static final long serialVersionUID = -2578561479301489061L; private SecondService secondService; private OrderService orderService; public OrderService getOrderService() { return orderService; } public void setOrderService(OrderService orderService) { this.orderService = orderService; } public SecondService getSecondService() { return secondService; } public void setSecondService(SecondService secondService) { this.secondService = secondService; } public void destroy() { } public void init() { System.out.println("拦截器初始化完毕"); } public String intercept(ActionInvocation invocation) throws Exception { ActionContext ctx = invocation.getInvocationContext(); Map session = ctx.getSession(); TUser user = (TUser)session.get("user"); if(null == user){ return "login"; } HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST); String secNo = request.getParameter("secNo"); if(不符合逻辑){ //提示页面 return "no_role_taian"; } //执行action return invocation.invoke(); } }
applicationContext.xml文件中引入拦截器配置文件
<import resource="interceptorContext.xml"/>
interceptorContext.xml文件内容:
<!-- 活动Struts拦截器struts过滤器测试 --> <bean id="taiAnCBCSecTempInterceptor" class="org.main.manage.interceptor.temp.TaiAnCBCSecTempInterceptor"> 调用service注入配置 <property name="orderService" ref="orderService"></property> <property name="secondService" ref="secondService"></property> </bean>在second.xml配置文件中设置拦截器栈:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="second" extends="default"> <interceptors> <interceptor name="taiAnCBCSecTempInterceptor" class="taiAnCBCSecTempInterceptor" /> <interceptor-stack name="cbcSecTempInterceptorStack"> <interceptor-ref name="defaultStack"/> <interceptor-ref name="params"/> <!-- 活动Struts拦截器struts过滤器测试 --> <interceptor-ref name="taiAnCBCSecTempInterceptor" /> </interceptor-stack> </interceptors> <!--//// WEB \\\\--> <action name="show_second" class="secondWeb" method="show_second"> <interceptor-ref name="cbcSecTempInterceptorStack"></interceptor-ref> <result name="no_role" type="redirect">/no_role.jsp</result> <result name="no_role_taian" type="redirect">/no_role_taian.jsp</result> //${secNo}接受后台传过来的值 <result name="login" type="redirect">/login_user.action?url=show_second.action?secNo=${secNo}</result> </action> <!--\\\\ WEB ////--> </package> </struts>
相关文章推荐
- struts2 页面跳转控制传参问题
- 关于使用struts2时子窗体页面跳转后在父窗体打开的问题以及Session过期后的页面跳转问题
- 关于struts2中checkbox勾选被处理又跳转回原页面的问题
- struts2中页面跳转问题个人小结(一)
- Angular 页面跳转时传参问题
- 新手学EXT问题 页面单独运行没有问题 但是一经过struts2跳转 就出现问题了(转)
- struts2使用action跳转后的页面路径如果是相对路径的话会出现css、js以及图片等无法加载问题
- Struts2文件上传 超过大小限制无法跳转至指定input页面问题,浏览器提示连接已重置?根本原因
- jsp页面之间跳转传参及中文乱码问题
- Struts2中ActionError与ActionMessage的互转,解决不同action不同页面的跳转问题
- 关于页面跳转同时传参,存于session或拼接与URL中?安全问题?
- js函数在window.location.href跳转页面传参由于空格引发的一个小问题
- struts2中action跳转后页面的css或是js失效的问题
- 404等错误页面跳转问题--基于struts2和原生
- Struts2 拦截器控制jsp页面跳转
- struts2中jsp页面跳转问题
- Shiro中Session过期页面跳转回登录页面处理问题
- Struts2透过自定义拦截器实现登录之后跳转到原页面
- S4.5_Struts2_ActionAdvance 使用action通配符捕获错误跳转到错误页面
- 网页页面跳转问题