我在应用程序中使用struts 1.1,我需要从数据库值填充下拉菜单,并将其设置为我的操作中的表单bean,显示以下jsp。
<td width="80%" class="formfield" valign='top'>
<html:select property="selectedUsedByUserName">
<html:option value="" >-</html:option>
<html:optionsCollection property="usedByUserList" label="name" value="staffNo"/>
</html:select>
</td>
在表单bean中我使用了getter和setter,
private UserDTO selectedUsedByUser = null;
private HashMap usedByUserListMap = new HashMap();
public UserDTO[] getUsedByUserList() {
return (UserDTO[]) usedByUserListMap.values().toArray(new UserDTO[0]);
}
public void setUsedByUserList(UserDTO[] usedByUserList) {
usedByUserListMap.clear();
if (usedByUserList != null) {
for (int i = 0; i < usedByUserList.length; i++) {
usedByUserListMap.put(
String.valueOf(usedByUserList[i].getStaffNo()),
usedByUserList[i]);
}
}
}
public String getSelectedUsedByUserName() {
String selectedUsedByUserName = null;
UserDTO tempSelectedUsedByUser = getSelectedUsedByUser();
if (tempSelectedUsedByUser != null) {
selectedUsedByUserName = String.valueOf(tempSelectedUsedByUser
.getStaffNo());
}
return selectedUsedByUserName;
}
public void setSelectedUsedByUserName(String string) {
UserDTO tempSelectedUsedByUserName = null;
if (string != null) {
tempSelectedUsedByUserName = (UserDTO) usedByUserListMap
.get(string);
}
setSelectedUsedByUser(tempSelectedUsedByUserName);
}
public UserDTO getSelectedUsedByUser() {
return selectedUsedByUser;
}
public void setSelectedUsedByUser(UserDTO usedByUser) {
this.selectedUsedByUser = usedByUser;
}
但是当我打印异常的堆栈跟踪时,我会在下面看到。请问这个例外的原因是什么,
根据TLD或标记文件,属性属性是必需的 标签选择 org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:78) 在 org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:373) 在 org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:201) 在 org.apache.jasper.compiler.Validator $ ValidateVisitor.visit(Validator.java:833) 在org.apache.jasper.compiler.Node $ CustomTag.accept(Node.java:1501)at at org.apache.jasper.compiler.Node $ Nodes.visit(Node.java:2291)at at org.apache.jasper.compiler.Node $ Visitor.visitBody(Node.java:2341)at at org.apache.jasper.compiler.Validator $ ValidateVisitor.visit(Validator.java:870) 在org.apache.jasper.compiler.Node $ CustomTag.accept(Node.java:1501)at at org.apache.jasper.compiler.Node $ Nodes.visit(Node.java:2291)at at org.apache.jasper.compiler.Node $ Visitor.visitBody(Node.java:2341)at at org.apache.jasper.compiler.Node $ Visitor.visit(Node.java:2347)at at org.apache.jasper.compiler.Node $ Root.accept(Node.java:498)at at org.apache.jasper.compiler.Node $ Nodes.visit(Node.java:2291)at at org.apache.jasper.compiler.Validator.validate(Validator.java:1853)at at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:210)at at org.apache.jasper.compiler.Compiler.compile(Compiler.java:435)at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:608) 在 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:360) 在 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486) 在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:847)at org.apache.catalina.core.ApplicationFilterChain.servletService
我已经在jsp select标签中设置了属性属性。我们是否需要在jsp加载之前将其设置为一个值。我相信我们使用它来跟踪在填充右下角后选择的选项?那么一旦我们选择一个值,struts会将所选值设置为正确吗?