【发布时间】:2009-06-20 12:38:59
【问题描述】:
我的 struts.xml 文件中有以下内容
<action name="ProductVerification" class="com.frontend.ProductVerification">
<result name="success">/jsp/product_verification.jsp</result>
<result name="input">/jsp/product_verification.jsp</result>
<result name="error">/jsp/product_verification.jsp</result>
</action>
我的 html 代码中有以下内容
<s:form name="frmVerification" id="frmVerification" onsubmit="Javascript: return checkFrmVerification(this);" >
<s:select name="countryId" id="cmbcountryid" headerKey="0" headerValue="%{getText('label.Please_Select')}" list="%{countryListCombo}" listKey="countryId" listValue="country" value="countryId" cssClass="style2" onchange="Javascript: GetCities();" required="true" />
<s:submit name="submit" src="images/submit_btn.jpg" type="image" value="submit" />
</form>
我有如下执行方法。
public String execute() throws Exception {
Session session = this.getHibernateSession();
Transaction tx = session.beginTransaction();
//Following will set combo box containing country list
this.setCountryListCombo();
tx.commit();
return SUCCESS;
}
我正在重写验证方法,如下所示。
@Override
public void validate() {
HttpServletRequest request = this.getServletRequest();
if(request.getParameter(countryId) == 0){
addFieldError("countryId", "Please select country");
}
}
现在,当我执行我的操作时,它会显示带有 countryId 组合框的表单,其中包含国家/地区。
现在,当我在不选择组合框的情况下提交表单时,它应该会显示错误。
但不是显示错误“请选择国家”它给了我以下错误。
Struts 问题报告
Struts 检测到一个未处理的异常:
消息: 标签“select”、字段“list”、名称“countryId”:请求的列表键“%{countryListCombo}”无法解析为集合/数组/地图/枚举/迭代器类型。示例:人或人。{name}
文件: org/apache/jasper/servlet/JspServletWrapper.java
行号: 522
谁能告诉我为什么会这样?
在 validate() 方法给出 result="input" 之后,它似乎没有调用 execute() 方法,而是尝试直接显示“/jsp/product_verification.jsp”页面。
请帮我解决问题。
谢谢。
【问题讨论】:
标签: validation struts2