문제

내 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;
}

아래와 같이 Validate 메소드를 우선적으로 사용하고 있습니다.

@Override
public void validate() {
 HttpServletRequest request = this.getServletRequest();

     if(request.getParameter(countryId) == 0){
          addFieldError("countryId", "Please select country");
     }

}

이제 내 행동을 실행할 때 국가로 가득 찬 Countryid 콤보 상자와 함께 형태를 보여줄 것입니다.

이제 콤보 상자를 선택하지 않고 양식을 제출하면 오류가 표시됩니다.

그러나 "국가를 선택하십시오"오류를 표시하는 대신 다음 오류가 발생합니다.

스트럿 문제 보고서

Struts는 처리되지 않은 예외를 감지했습니다.

메시지 : 태그 'select', field 'list', name 'countryID': 요청 된 목록 키 '%{countryListCombo}'는 수집/배열/지도/열거/반복자 유형으로 해결할 수 없습니다. 예 : 사람 또는 사람. {name}

파일: org/apache/jasper/servlet/jspservletwrapper.java

라인 번호 : 522

누구든지 왜 그런지 말해 줄 수 있습니까?

validate () 메소드를 제공 한 후 result = "input"를 제공 한 후에는 execute () 메소드를 호출하지 않고 대신 "/jsp/product_verification.jsp"페이지를 직접 표시하려고합니다.

문제를 해결하도록 도와주세요.

감사.

도움이 되었습니까?

해결책

필드 오류가 추가되면 기본적으로 "입력"결과를 반환하여 입력 결과가 렌더링됩니다. Page Rendering 전에 항상 Combobox를 채울 수있는 준비 가능한 구현을 찾는 것이 좋습니다.

다른 팁

아래와 같이 메소드에 콤보 박스 코드를 추가해야합니다.

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