[英]Populating of list after a redirect action in struts2
I have a index.jsp
which redirects to otl_homepage.jsp
on successful login. 我有一个index.jsp
,成功登录后会重定向到otl_homepage.jsp
。 When the user logs in, I need to display a list in the otl_homepage.jsp
. 当用户登录时,我需要在otl_homepage.jsp
显示一个列表。 In my struts.xml
, if i give type="chain"
or no type at all, the list is getting fetched. 在我的struts.xml
,如果我type="chain"
或根本不输入任何类型,则列表将被获取。 But if I use type="redirectAction"
, the list is returning null. 但是,如果我使用type="redirectAction"
,则列表返回null。 How do I obtain this list? 我如何获得此清单? The list is maintained in my java action class. 该列表在我的java操作类中维护。
please find the struts.xml
here and the java class 请在这里找到struts.xml
和Java类
struts.xml: struts.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>
<constant name="struts.enable.DynamicMethodInvocation"
value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources" value="MessageResource" />
<constant name="struts.convention.result.path" value="/"></constant>
<package name="default" namespace="/" extends="struts-default">
<interceptors>
<interceptor name="authentication"
class="com.opentext.planning.interceptor.LoginInterceptor"></interceptor>
<interceptor-stack name="authStack">
<interceptor-ref name="authentication"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="authStack"></default-interceptor-ref>
<!-- <global-results>
<result name="login" type="redirect">/home.action</result>
</global-results>
<action name="home">
<interceptor-ref name="defaultStack"></interceptor-ref>
<result>/index.jsp</result>
</action>-->
<action name="login" class="com.opentext.planning.view.OTLAuthentication" >
<result name="success" type="redirectAction">Otl_Homepage</result>
<param name="otlUserList">${otlUserList}</param>
<result name="login">/index.jsp</result>
<result name="failure">/index.jsp</result>
<result name="failure2">/index.jsp</result>
</action>
<action name="Otl_Homepage" class="com.opentext.planning.view.OTLAuthentication" method="home">
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="success">/Otl_Homepage.jsp</result>
<result name="failure">/index.jsp</result>
<result name="failure2">/index.jsp</result>
</action>
Java class: Java类:
public String execute(){
System.out.println("inside execute");
//System.out.println("user is" +user.getUser());
// System.out.println("username is " +user.getUserName());
//if("pankaj".equals(user.getUserName()) && "admin".equals(user.getPassword())){
//System.out.println("inside if");
if (j_username != null) {
System.out.println("inside function");
System.out.println("user name is "+j_username);
// add userName to the session
System.out.println("user name is 2"+j_username);
sessionMap.put("loginId", j_username);
System.out.println("dunno if the will print");
// user.setUserName(user.getUserName());
// sessionMap.put("USER", j_username);
status = otlAuthenticationController.loginAuthentication(j_username,j_password);
if(status == "success")
{
this.otlUserList= otlAuthenticationController.obtainList();
System.out.println("size is"+otlUserList.size());
return "success";
}
}
return status;
}
After redirection to another action you need to populate the list again in the home
action. 重定向到另一个动作后,您需要在home
动作中再次填充列表。 The redirectAction
result type redirects to another action. redirectAction
结果类型重定向到另一个动作。 Another action instantiate a new instance of the action class. 另一个动作实例化了动作类的新实例。 This instance should be initialized and populated before you return a JSP result. 返回JSP结果之前,应初始化并填充此实例。 In JSP the list values retrieved from the ValueStack
which has an action instance that returned a list if the public getter method exists in the action class. 在JSP中,从ValueStack
检索的列表值具有一个动作实例,如果动作类中存在公共getter方法,则该实例返回一个列表。
public String home(){
this.otlUserList= otlAuthenticationController.obtainList();
System.out.println("size is"+otlUserList.size());
return "success";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.