博客
关于我
struts2 session传值 通配符 validate 动态方法调用 倒计时刷新跳转
阅读量:327 次
发布时间:2019-03-04

本文共 1759 字,大约阅读时间需要 5 分钟。

1.通配符*

<action name="login_*" class="com.action.LoginAction" method="Login{1}">

<result name="success">/success.jsp</result>

</action>

 

Login_*:*表示接收任意字符,

{1}:表示第一个通配符*所传递过来的内容,如果*为A,那{1}就代表A,那么method就是LoginA方法

{0}:表示匹配所用action name的内容 例如:login_A

2.DynamicMethodInvocation:动态方法调用

<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>

 

设置是否动态方法调用,value设置为true,就表示为开启状态,允许动态方法调用

 

动态方法如何调用:

        在浏览器地址栏输入要访问的Action名字(name)由!+方法调用,格式为 login!LoginA    表示访问action的name为login的类中LoginA的方法。

 

  1. 如何获取session向Session中存储值(3种方式)
  1. ActionContext上下文获取

ActionContext.getContext().getSession().put(name,value);

  1. ServletActionContext方式获取

HttpServletSession session=ServletACtionContex t.getRequest().getSession();

Session.setAttribute(anme,value);

  1. 通过实现ServletRequestAware里的方法,获取

Class login implements ServletRequestAware{

public void  setServletRequest(HttpServletRequest request) {

// TODO Auto-generated method stub

Request.getSession().Session.setAttribute(a nme,value);

 

} 

}

 

  1. Validate

this.addFieldError("namenull", "用户名或密码不能为空!");  在validate验证方法里,加上这行代码的效果是添加错误字段验证,在前台获取的方式是

1.加载struts2标签,

<%@ page taglib uri=/struts-tags prefix=s%>

  1. 获取字段验证错误信息:

<s:fielderror fieldname=namenull></s:fielderror>

 

  1. 如何在Action类中执行LoginA()方法之前,执行验证LoginA()的方法

1.在类名上继承ActionSupport

Class loginAction extends ActionSupport{

 

}

  1. 添加LoginA()方法

Public String LoginA(){

Return success;

}

  1. 添加验证LoginA的方法(一般都是    validate+XXX(LoginA))例如:

Public void validateLoginA(){

在里面添加判断或者验证错误信息

this.addFieldError("namenull", "用户名或密码不能为空!"); 

}

5.前端网页倒计时刷新跳转

<meta http-equiv="refresh" content="5;url=menu.jsp">

网页5秒后刷新跳转到menu.jsp页面

倒计时代码:

<script type="text/javascript">

$(function(){

var t=5;

function a(){

if (t<0){}else{

$("h2").text(t+" s!");

t--;

setTimeout(a,1000);

}

 

}

a();

})

</script>

 

 

 

大概今天就这么多内容。

 

转载地址:http://esnq.baihongyu.com/

你可能感兴趣的文章
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
no such file or directory AndroidManifest.xml
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>