這是我Assignemployee.jsp文件代碼錯誤的選擇框
<s:form action="AssignEmployee" name="myForm">
<s:select name="pname" list="projectlist" headerKey="0" label="Select a country" />
<s:submit/>
</s:form>
這是我projectlist.java操作文件
package myPack;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
public class projectlist extends ActionSupport implements ServletRequestAware {
private static final long serialVersionUID = 1L;
HttpServletRequest request;
private List<String> projectlist;
public List<String> getProjectlist() {
return projectlist;
}
public void setProjectlist(List<String> projectlist) {
this.projectlist = projectlist;
}
public void setServletRequest(HttpServletRequest request)
{
this.request = request;
}
public HttpServletRequest getServletRequest(){
return request;
}
public String getDefaultSearchEngine() {
return "yahoo.com";
}
public projectlist()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con=DriverManager.getConnection("jdbc:mysql:///pmt","root","shree");
ps=con.prepareStatement("select * from addproject");
ResultSet res = ps.executeQuery();
while(res.next())
{
projectlist = new ArrayList<String>();
projectlist.add(res.getString("pname"));
}
ps.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public String execute()throws Exception
{
return SUCCESS;
}
public String display() {
return NONE;
}
}
,這是struts.xml的
<action name="AssignEmployee" class="myPack.projectlist" method="display">
<result name="success">assignemployee.jsp</result>
</action>
當我正在運行的應用程序,我得到一個錯誤,如
SEVERE:servlet [jsp]在路徑[/ PTMS]上下文中拋出異常[tag'select',field'list',名稱'pname':請求的列表鍵'projectlist'可以不能被解析爲一個集合/數組/映射/枚舉/迭代器類型。示例:人員或人員。{name} - [unknown location]]帶有根本原因 標記'select',字段'list',名稱'pname':請求的列表鍵'projectlist'無法解析爲集合/數組/ map/enumeration/iterator類型。例如:人或人。{name} - [unknown location]
如何解決這個錯誤?
問題出現在顯示JSP的頁面,而不是表單提交(除非存在驗證錯誤)。另外,縮進你的代碼。 – 2013-02-26 18:46:45
但是是什麼問題... – 2013-02-26 18:54:53
我應該怎麼知道?我看不到任何有關顯示帶有選擇框的JSP的操作。顯然沒有'projectlist'值。此外,您不斷創建新列表,而不是添加到單個列表。 – 2013-02-26 18:56:21