Original address: Struts2 JSP form submits the value in the input box in the form drop-down box select and input
JSP page
1 function Dosearch () {
2 if ($ ("#textValue"). val () = = "") {
3 $ ("#errortip"). HTML ("<font color= ' #FF0000 ' > Please enter query content </font>");
4 return false;
5}
6 $ (' #searchform '). Submit ();
7}
1 <form id= "searchform" name= "Searchform" action= "listpsinfo.action" method= "POST" >
2 <div id= "sr" class= "B1 MB10" >
3 <ul id= "SR_BQ" >
4 <li class= "on" >
5 <div>
6 Find Employee Information
7 </div>
8 </li>
9 </ul>
Ten <select class= "Sa_w_tx" style= "width:100px" id= "SelectType" name= "Psinfodo.name" >
One <option value= "1" <s:if test= "Optionvalue==1" >selected= "selected" </s:if>> Work No. </opt Ion>
<option value= "2" <s:if test= "optionvalue==2" >selected= "selected" </s:if>> (nickname) < /option>
<option value= "3" <s:if test= "optionvalue==3" >selected= "selected" </s:if>> real name </o Ption>
<option value= "4" <s:if test= "optionvalue==4" >selected= "selected" </s:if>> mailbox </opt Ion>
</select>
<input type= "text" class= "Sa_w_tx" style= "width:180px;" id= "TextValue" name= "Psinfodo.value" value= "< ; S:property value= "Psinfodo.value"/> "maxlength=" title= "Please enter the appropriate content does not allow null value"/>
<input type= "button" value= "Query" class= "BTN1" id= "subform" onclick= "Dosearch ();" /> <div id= "Errortip" ></div>
</form>
To preserve the value in the drop-down list box, save the value in option with a variable optionvalue when the form is submitted to the action so that the optionvalue is returned to the
The JSP uses the STRUTS2 label S:if as a judge to use the value of the drop-down box to retain the
1 <option value= "1" <s:if test= "Optionvalue==1" >selected= "selected" </s:if>> Work No. </option>
The normal input input box can use the domain model in the action.
Action
1 private Ipeoplesoftinfobo Peoplesoftinfobo;
2 private Peoplesoftinfodo Psinfodo;
3 Private Peoplesoftinfodo Querypsinfo;
4 private String OptionValue;
1 public String Listpsinfo () throws Exception {
2
3 This.optionvalue=psinfodo.getname ();
4 this.querypsinfo=peoplesoftinfobo.findpsinfobyconditions (Psinfodo);
5
6 if (querypsinfo==null)
7 {
8 Addfielderror ("Userlognamemessage", "the system does not exist this employee information, please check and manually set the operator's basic information");
9}
Ten return SUCCESS;
11}
Struts2 the value of the input box in the form after the JSP form is submitted drop-down box select and input