[英]Populating of list after a redirect action in struts2
我有一個index.jsp
,成功登錄后會重定向到otl_homepage.jsp
。 當用戶登錄時,我需要在otl_homepage.jsp
顯示一個列表。 在我的struts.xml
,如果我type="chain"
或根本不輸入任何類型,則列表將被獲取。 但是,如果我使用type="redirectAction"
,則列表返回null。 我如何獲得此清單? 該列表在我的java操作類中維護。
請在這里找到struts.xml
和Java類
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類:
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;
}
重定向到另一個動作后,您需要在home
動作中再次填充列表。 redirectAction
結果類型重定向到另一個動作。 另一個動作實例化了動作類的新實例。 返回JSP結果之前,應初始化並填充此實例。 在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.