struts用户拦截器
来源:互联网 发布:新闻资讯源码 作家 编辑:程序博客网 时间:2024/06/10 00:17
1. 所谓登录;拦截器 首先 是
Login.action 和 业务acion 分开,
不能对 登录action 进行 拦截
必须 要 配置在不同的包,
已经配置了的 就是 所有的 包中的action 都拦截
<span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <constant name="struts.locale" value="zh_CN" /> <constant name="struts.objectFactory" value="spring"></constant><constant name="struts.ui.theme" value="simple" /> <package name="defaultxiao" namespace="/" extends="struts-default"> <!-- 将拦截器配置进来 --> <interceptors> <interceptor name="checklogin" class="com.onlineTest.util.CheckLoginIntercepter"></interceptor> <!-- 合为一个栈 --> <interceptor-stack name="myStack"> <interceptor-ref name="checklogin"></interceptor-ref> <!-- Struts默认的 --> <interceptor-ref name="defaultStack"></interceptor-ref> </interceptor-stack> </interceptors> <!-- 设置默认拦截器 --> <default-interceptor-ref name="myStack"></default-interceptor-ref> <global-results> <result name="Login">/index.jsp</result> </global-results> <action name="TestBook_*" class="xiaoTextBookAction" method="{1}"><result name="TextBook_index">/WEB-INF/Jsp/StudentChangeTestBookIndex.jsp</result> <result name="error">index.jsp</result></action></package><package name="defaultxiaod" namespace="/" extends="</span><span style="font-size: 14px; font-family: Arial, Helvetica, sans-serif;">struts-default></span><span style="font-size:14px;"></span><pre name="code" class="html"><span style="font-size: 14px;"></span><action name="login_*" class="ExerciseTestAction" method="{1}">
<span style="font-size: 14px;"><result name="admin_index">/WEB-INF/Jsp/Adminindex.jsp</result></span></action> </package></struts>
d 2. 然后就是 在 Login_login 里面 this.getSession.setAttribute("user",user) ,
<span style="font-size:18px;">package com.onlineTest.util;import java.util.Map;import javax.servlet.http.HttpSession;import org.apache.struts2.ServletActionContext;import com.onlineTest.po.Student;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class CheckLoginIntercepter extends AbstractInterceptor{@Overridepublic String intercept(ActionInvocation invocation) throws Exception {HttpSessionmap= ServletActionContext.getRequest().getSession();Student ss=(Student)map.getAttribute("user"); if (ss==null) { return "Login"; } else { //继续执行 不拦截 return invocation.invoke(); } }}</span><span style="font-size:32px;"></span>
0 0
- struts用户拦截器
- Struts拦截器判断用户是否登陆
- Struts拦截器简单实用--用户是否有效
- struts 拦截器来过滤用户的权限
- Struts 2.0 拦截器
- struts拦截器
- struts 拦截器
- Struts 2拦截器
- Struts拦截器
- Struts 2拦截器
- struts拦截器
- Struts之拦截器
- struts拦截器
- Struts 拦截器
- struts拦截器
- struts 2 拦截器
- struts 拦截器
- struts自定义拦截器
- POJ1163 The Triangle
- C++随笔--A题:括号配对问题
- 自动化运维概述
- MyCat:开源分布式数据库中间件
- 利用后缀做计算器,运算
- struts用户拦截器
- 回过头再看 计算机体系结构5----并发和并行
- 在vim保存时获得sudo权限
- Leetcode--Single Number III
- 深入浅出MFC:MFC中的的RTTI实现
- git的使用
- 特朗普总结自身成功的十大法则
- 11gr1,使用OUI进行预安装必要条件检查,避免出现安装过程中的错误
- iOS CocoaPods组件平滑二进制化解决方案