我尝试在成功登录后填充select标记,但系统出现以下错误。 以下是代码。
struts.xml中
<package name="default" extends="struts-default">
<action name="LoginAction" class="com.Struts2.Login.MDLogin">
<result name="error">/Login/UILogin.jsp</result>
<result name="success">/Login/UIRegister.jsp</result>
</action>
<action name="RegisterAction" class="com.Struts2.Register.MDRegister">
<result name="error">/Login/UIRegister.jsp</result>
<result name="success">/Login/UIRegisterData.jsp</result>
</action>
<action name="populateAction" method="populatePosition" class="com.Struts2.Register.MDRegister">
<result name="populate">/Login/UIRegister.jsp</result>
</action>
</package>
UIRegister.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=populateAction.action">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1;">
<title>Register</title>
</head>
<body>
<center>
Register Client
</center>
<s:form action="/RegisterAction">
<s:textfield name="txtUser" maxLength="10" size="10" label="User Name"/>
<s:password name="txtPassword" label="Password" maxlength="15" size="15"/>
<s:textarea name="txtAbout" label="About you" col="20" row="3"></s:textarea>
<s:checkbox name="chkUpdate" label="check for the update" fieldValue="true" /
<s:select name="cboSelect" list="cboSelectList" listKey="strKey" istValue="strValue"
multiple="false" label="Position"/>
<s:submit value="submit"></s:submit>
</s:form>
</body>
</html>
MDSelect.java
package com.Struts2.Select;
public class MDSelect
{
private String strKey;
private String strValue;
public String getStrKey() {
return strKey;
}
public void setStrKey(String strKey) {
this.strKey = strKey;
}
public String getStrValue() {
return strValue;
}
public void setStrValue(String strValue) {
this.strValue = strValue;
}
public MDSelect(String strMainKey,String strMainValue)
{
this.strKey=strMainKey;
this.strValue=strMainValue;
}
}
MDRegister.java
package com.Struts2.Register;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Vector;
import com.Struts2.Select.MDSelect;
import com.Struts2.model.MDModel;
import com.opensymphony.xwork2.ActionSupport;
public class MDRegister extends ActionSupport
{
private String txtUser;
private String txtPassword;
private String txtAbout;
private String chkUpdate;
private String MDSelect;
private ArrayList<MDSelect> cboSelectList;
MDModel model=new MDModel();
public String getTxtUser() {
return txtUser;
}
public void setTxtUser(String txtUser) {
this.txtUser = txtUser;
}
public String getTxtPassword() {
return txtPassword;
}
public void setTxtPassword(String txtPassword) {
this.txtPassword = txtPassword;
}
public String getTxtAbout() {
return txtAbout;
}
public void setTxtAbout(String txtAbout) {
this.txtAbout = txtAbout;
}
public String getChkUpdate() {
return chkUpdate;
}
public void setChkUpdate(String chkUpdate) {
this.chkUpdate = chkUpdate;
}
public String getMDSelect() {
return MDSelect;
}
public void setMDSelect(String mDSelect) {
MDSelect = mDSelect;
}
public ArrayList<MDSelect> getCboSelectList() {
return cboSelectList;
}
public void setCboSelectList(ArrayList<MDSelect> cboSelectList) {
this.cboSelectList = cboSelectList;
}
public String populatePosition() throws SQLException
{
Vector cboPosition=(Vector)model.cmbGCode("DPT");
System.out.println("cboPosition>>>>>>>"+cboPosition.size());
cboSelectList=new ArrayList<MDSelect>();
for(int iPos=0;iPos<cboPosition.size();iPos++)
{
Object[] objData=(Object[])cboPosition.elementAt(iPos);
cboSelectList.add(new MDSelect(String.valueOf(objData[0]),
String.valueOf(objData[1])));
}
setCboSelectList(cboSelectList);
System.out.println("In populate register 2 cboPosition>>>>>>>"+cboPosition.size());
return "populate";
}
public String execute()
{
if(getTxtUser().trim().equals(""))
{
addFieldError("txtUser", "User Can not be blank");
return ERROR;
}
if(getTxtPassword().trim().equals(""))
{
addFieldError("txtPassword", "Password can not be blank");
return ERROR;
}
if(getTxtAbout().trim().equals(""))
{
addFieldError("txtAbout", "Please tell us about your self");
return ERROR;
}
return SUCCESS;
}
}
现在当我成功登录系统时,它会显示以下错误。
HTTP Status 500 - tag 'select', field 'list', name 'cboSelect': The requested list
key 'cboSelectList' could not be resolved as a
collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
type Exception report
message tag 'select', field 'list', name 'cboSelect': The requested list key 'cboSelectList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
description The server encountered an internal error that prevented it from fulfilling this request.
答案 0 :(得分:0)
您的应用程序存在一些缺陷。为LoginAction
和RegistrationAction
定义了无方法,因此在这种情况下,将为这两个操作调用 execute()方法!
这是你想要的吗?并且由于你想在成功登录后填充select,它也会失败,因为你没有在execute()中填充cboSelectedList
,你一定会收到错误。
如果您是struts的新手,请立即了解Struts的基础知识!