java web session,JAVA web页面刷新和session有关问题

JAVA web页面刷新和session问题

框架是ssi  在登录后到了某个界面,如果按下刷新的话会提示是否要重新发送信息

可是在csdn这种网页 登陆后刷新某页也没有这种提示啊

另外  如果过了一段时间  再刷新会直接报500错误

The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.NullPointerException

cn.xiaozhi.service.LoginService.loginVali(LoginService.java:34)

cn.xiaozhi.action.LoginProcess.execute(LoginProcess.java:46)

sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)

sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

java.lang.reflect.Method.invoke(Unknown Source)

com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)

。。。。。

web.xml为:

Struts Blank

contextConfigLocation

/WEB-INF/applicationContext.xml

org.springframework.web.context.ContextLoaderListener

org.springframework.web.context.request.RequestContextListener 

struts2

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

struts2

/*

index.html

能告诉我这个是怎么个情况?session超时的话 应该怎么修改

------解决方案--------------------

实例功能:当用户登陆后,session超时后则返回到登陆页面重新登陆。

为了更好的实现此功能我们先将session失效时间设置的小点,这里我们设置成2分钟

修改web.xml?

?2

在这里要注意了,所有经过拦截器的action类都必须实现Action接口或者继承自ActionSupport父类,如果不继承将会报500错误

Struts2自定义拦截器实例—登陆权限验证

实现自定义拦截器类

package org.hongfei.interceptor;

import java.util.Map;

import org.hongfei.entity.User;

import org.hongfei.web.action.AdminLoginAction;

import org.hongfei.web.action.UserLoginAction;

import com.opensymphony.xwork2.Action;

import com.opensymphony.xwork2.ActionInvocation;

import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class SessionInterceptor extends AbstractInterceptor {

private static final long serialVersionUID = 1L;

@Override

public String intercept(ActionInvocation actionInvocation) throws Exception {

// TODO Auto-generated method stub

//获取session

Map session=actionInvocation.getInvocationContext().getSession();

//获取拦截器对象

Object action = (Action) actionInvocation.getAction();

//如果获取的拦截器为 AdminLoginAction或者UserLoginAction,则不进行拦截

if(action instanceof AdminLoginAction

------解决方案--------------------

action instanceof UserLoginAction){

return actionInvocation.invoke();

}

//得到session中的用户

User user=(User) session.get("user");

//如果用户为空则跳到LOGIN页面,否则退出拦截

if(user==null){

return Action.LOGIN;

}else{

return actionInvocation.invoke();

}

}

}

struts.xml中定义并使用此拦截器

struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

"http://struts.apache.org/dtds/struts-2.0.dtd">

image/bmp,image/png,image/gif,image/jpeg,image/jpg

/admin/testError.jsp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值