我在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}'无法解析为collection / array / map / enumeration / iterator类型。例如:人或人。{name}

文件: org / apache / jasper / servlet / JspServletWrapper.java

行号: 522

任何人都可以告诉我为什么会这样吗?

似乎在validate()方法给出result = <!>“input <!>”之后,它不会调用execute()方法而是尝试显示<!> /; /jsp/product_verification.jsp <!> QUOT;页面直接。

请帮我解决问题。

感谢。

有帮助吗?

解决方案

您的假设是正确的,当添加字段错误时,它将默认返回<!>“INPUT <!>”;结果,导致输入结果。我建议考虑实现可伪装,这样可以在页面渲染之前始终填充组合框。

其他提示

您需要在方法中添加组合框代码,如下所示:

public String execute() throws Exception {

//add this code also as per your comobobx code
countryList = new ArrayList<Country>();
        countryList.add(new Country(1, "India"));
        countryList.add(new Country(1, "Shri Lanka"));
        countryList.add(new Country(1, "USA"));
        countryList.add(new Country(1, "Pakistan"));
        countryList.add(new Country(1, "NewsLnad"));

//add this code also as per your comobobx code

    Session session = this.getHibernateSession();

    Transaction tx = session.beginTransaction();

    //Following will set combo box containing country list
    this.setCountryListCombo();

    tx.commit();

    return SUCCESS;
}

并在jsp页面中添加以下标记

<s:actionerror />

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top