if(existU==null) {
throw new RuntimeException("用户名不存在");
}
if(!existU.getUser_password().equals(user.getUser_password())) {
throw new RuntimeException("密码错误");
}
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.RuntimeException">exception-mapping>
global-exception-mappings>
<result name="error" >/login.jspresult>
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:debug>s:debug>
//拦截器生命周期:随项目的启动而创建,随项目关闭而销毁
public class MyInterceptor implements Interceptor {
//创建方式2: 继承AbstractInterceptor -> struts2的体贴
//帮我们空实现了init 和 destory方法. 我们如果不需要实现这两个方法,就可以只实现intercept方法
public class MyInterceptor2 extends AbstractInterceptor {
//继承:MethodFilterInterceptor 方法过滤拦截器
//功能: 定制拦截器拦截的方法.
// 定制哪些方法需要拦截.
// 定制哪些方法不需要拦截
public class MyInterceptor3 extends MethodFilterInterceptor{
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
//前处理
System.out.println("MyInterceptor3 的前处理!");
//放行
String result = invocation.invoke();
//后处理
System.out.println("MyInterceptor3 的后处理!");
return result;
}
}
<interceptor name="myInter3" class="cn.itcast.a_interceptor.MyInterceptor3">interceptor>
<interceptor-stack name="myStack">
<interceptor-ref name="myInter3">
<param name="includeMethods">add,deleteparam>
interceptor-ref>
<interceptor-ref name="defaultStack">interceptor-ref>
interceptor-stack>
<default-interceptor-ref name="myStack">default-interceptor-ref>
<action name="Demo1Action_*" class="cn.zh.a_interceptor.Demo1Action" method="{1}" >
<interceptor-ref name="myStack">interceptor-ref>
<result name="success" type="dispatcher" >/index.jspresult>
action>
<param name="excludeMethods">add,deleteparam>
<param name="includeMethods">add,deleteparam>
一、获取session
二、从session中获取登录标识
三、判断登录标识
public class LoginInterceptor extends MethodFilterInterceptor {
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
//1.获取session
Map<String,Object> session=ActionContext.getContext().getSession();
//2. 获取登录标识
Object object=session.get("user");
//3.判断标识是否存在
if(object==null) {
return "toLogin";
}else {
//拦截器放行
return invocation.invoke();
}
}
}
一、注册拦截器
二、注册拦截器栈,并导入默认拦截器
三、指定拦截方法
四、指定默认拦截器栈
<interceptors>
<interceptor name="loginInterceptor" class="cn.zh.web.interceptor.LoginInterceptor">interceptor>
<interceptor-stack name="myStack">
<interceptor-ref name="loginInterceptor">
<param name="excludeMethods">loginparam>
interceptor-ref>
<interceptor-ref name="defaultStack">interceptor-ref>
interceptor-stack>
interceptors>
<default-interceptor-ref name="myStack">default-interceptor-ref>
<global-results>
<result name="toLogin" type="redirect" >/login.jspresult>
global-results>
<script type="text/javascript">
window.onload=function(){
if(window.parent!=window){
window.parent.location.href="${pageContext.request.contextPath}/login.jsp";
}
};
</script>
这段代码表示:如果当前页面的父页面不等于他自己,(说明在框架内)那就让其父页面等于他自己,
<%@ taglib prefix="s" uri="/struts-tags" %>
|
if else标签
list长度为4!
list长度为3!
list不3不4!
property标签–数据标签