lakkarajumurali
asked on
Retain the value of Drop down box in jsp
Hi,
I have a JSP with several drop down boxes. When the user clicks on submit button the page is submitted and again redirected to the same page with some results added in the bottom of the page. In this process, the values which are selected in the drop down box are also refreshed (expected). Now i want to retain the selected value in the drop down box, which am not finding a way to do it through jsp or javascript. Here is my code snippet:
<form action="tremorEntry.do" method="post" id="teForm">
<div id="dataEntryPoint" style=" background-color: activeborder; table-layout: auto; margin: 2px; margin-top:10px; margin-left:10px; width:1200px; height:80px; border: thin; border-color: black; border-style: dotted; ">
<table>
<tr>
<td style="width: 2pc"></td>
<td>
<label id="startDateLbl" class="setFont" >Start Date/Time : </label>
</td>
<td>
<input id="startDate" class="setFont" name="startDate" title="Start Date/Time" type="text" value="<% out.write(request.getParam eter("star tDate")); %>"/>
</td>
<td style="width: 2pc"></td>
<td>
<label id="endDateLbl" class="setFont" >End Date/Time : </label>
</td>
<td>
<input id="endDate" name="endDate" class="setFont" title="End Date/Time" type="text" value="<% out.write(request.getParam eter("endD ate")); %>"/>
</td>
<td style="width: 2pc"></td>
<td>
<label id="view" class="setFont" >View : </label>
</td>
<td>
<select id="view" name="view" class="setFont" style="width: auto;" tabindex="0">
<option selected="selected">Choose One</option>
<option>Vertical</option>
<option>Component</option>
<option>Widget</option>
<option>User Guid</option>
<option>Session Id</option>
<option>Root Guid</option>
</select>
</td>
<td style="width: 2pc"></td>
<td>
<label id="applicationLbl" class="setFont" >Application : </label>
</td>
<td>
<select id="application" name="application" class="setFont" style="width: auto;" tabindex="0">
<option>Choose One</option>
<option>Build Reports</option>
<option>Clear App</option>
<option selected="selected">Securi ty</option >
<option>Document</option>
<option>Clear EDD</option>
<option>Unknown</option>
</select>
</td>
</tr>
<tr style="height: 20px;">
</tr>
<tr>
<td style="width: 2pc"></td>
<td>
<label id="timeRangeLbl" class="setFont" >Time Range: </label>
</td>
<td>
<select id="timeRangeSel" name="timeRangeSel" class="setFont" style="width: auto;" tabindex="0">
<option selected="selected">15 Minute</option>
<option>Minute</option>
<option>Day</option>
<option>Month</option>
</select>
</td>
<td style="width: 2pc"></td>
<td>
<label id="middleTierLbl" class="setFont" >Middle Tier : </label>
</td>
<td>
<select id="middleTierSel" name="middleTierSel" class="setFont" style="width: auto;" tabindex="0">
<option selected="selected">Client </option>
<option>Production</option >
</select>
</td>
<td style="width: 80px;">
</td>
<td>
<span id="submitSpan">
<input id="submitBtn" value="Submit" type="submit"/>
<input id="hiddenBtn" type="hidden"/>
</span>
</td>
</tr>
</table>
</div>
</form>
Thanks,
Murali.
I have a JSP with several drop down boxes. When the user clicks on submit button the page is submitted and again redirected to the same page with some results added in the bottom of the page. In this process, the values which are selected in the drop down box are also refreshed (expected). Now i want to retain the selected value in the drop down box, which am not finding a way to do it through jsp or javascript. Here is my code snippet:
<form action="tremorEntry.do" method="post" id="teForm">
<div id="dataEntryPoint" style=" background-color: activeborder; table-layout: auto; margin: 2px; margin-top:10px; margin-left:10px; width:1200px; height:80px; border: thin; border-color: black; border-style: dotted; ">
<table>
<tr>
<td style="width: 2pc"></td>
<td>
<label id="startDateLbl" class="setFont" >Start Date/Time : </label>
</td>
<td>
<input id="startDate" class="setFont" name="startDate" title="Start Date/Time" type="text" value="<% out.write(request.getParam
</td>
<td style="width: 2pc"></td>
<td>
<label id="endDateLbl" class="setFont" >End Date/Time : </label>
</td>
<td>
<input id="endDate" name="endDate" class="setFont" title="End Date/Time" type="text" value="<% out.write(request.getParam
</td>
<td style="width: 2pc"></td>
<td>
<label id="view" class="setFont" >View : </label>
</td>
<td>
<select id="view" name="view" class="setFont" style="width: auto;" tabindex="0">
<option selected="selected">Choose
<option>Vertical</option>
<option>Component</option>
<option>Widget</option>
<option>User Guid</option>
<option>Session Id</option>
<option>Root Guid</option>
</select>
</td>
<td style="width: 2pc"></td>
<td>
<label id="applicationLbl" class="setFont" >Application : </label>
</td>
<td>
<select id="application" name="application" class="setFont" style="width: auto;" tabindex="0">
<option>Choose One</option>
<option>Build Reports</option>
<option>Clear App</option>
<option selected="selected">Securi
<option>Document</option>
<option>Clear EDD</option>
<option>Unknown</option>
</select>
</td>
</tr>
<tr style="height: 20px;">
</tr>
<tr>
<td style="width: 2pc"></td>
<td>
<label id="timeRangeLbl" class="setFont" >Time Range: </label>
</td>
<td>
<select id="timeRangeSel" name="timeRangeSel" class="setFont" style="width: auto;" tabindex="0">
<option selected="selected">15 Minute</option>
<option>Minute</option>
<option>Day</option>
<option>Month</option>
</select>
</td>
<td style="width: 2pc"></td>
<td>
<label id="middleTierLbl" class="setFont" >Middle Tier : </label>
</td>
<td>
<select id="middleTierSel" name="middleTierSel" class="setFont" style="width: auto;" tabindex="0">
<option selected="selected">Client
<option>Production</option
</select>
</td>
<td style="width: 80px;">
</td>
<td>
<span id="submitSpan">
<input id="submitBtn" value="Submit" type="submit"/>
<input id="hiddenBtn" type="hidden"/>
</span>
</td>
</tr>
</table>
</div>
</form>
Thanks,
Murali.
ASKER
it says selected cannot be resolved. here is how it is now.
<option value="<%if(request.getPar ameter("vi ew").equal s("Vertica l")) {out.println(selected="sel ected"); } %>">Vertical</option>
<option value="<%if(request.getPar
sorry change it to...
<option value="<%if(request.getPar ameter("vi ew").equal s("Vertica l")) {out.println('selected="se lected"'); } %>">Vertical</option>
<option value="<%if(request.getPar
ASKER
am getting the following exception:
org.apache.jasper.JasperEx ception: An exception occurred processing JSP page /WEB-INF/jsp/VtqForm.jsp at line 217
214: <td>
215: <select id="view" name="view" class="setFont" style="width: auto;" >
216: <option value="" selected="selected">Choose One</option>
217: <option value="<%if(request.getPar ameter("vi ew").equal s("Vertica l")) {out.println("selected='se lected'"); } %>">Vertical</option>
218: <option value="<%if(request.getPar ameter("vi ew").equal s("Compone nt")) {out.println("selected='se lected'"); } %>">Component</option>
219: <option value="<%if(request.getPar ameter("vi ew").equal s("Widget" )) {out.println("selected='se lected'"); } %>">Widget</option>
220: <option value="<%if(request.getPar ameter("vi ew").equal s("User Guid")) {out.println("selected='se lected'"); } %>">User Guid</option>
Stacktrace:
org.apache.jasper.servlet. JspServlet Wrapper.ha ndleJspExc eption(Jsp ServletWra pper.java: 510)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:4 19)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:313)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:260)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 717)
root cause
java.lang.NullPointerExcep tion
org.apache.jsp.WEB_002dINF .jsp.VtqFo rm_jsp._js pService(V tqForm_jsp .java:350)
org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:70)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 717)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 77)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:313)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:260)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 717)
org.apache.jasper.JasperEx
214: <td>
215: <select id="view" name="view" class="setFont" style="width: auto;" >
216: <option value="" selected="selected">Choose
217: <option value="<%if(request.getPar
218: <option value="<%if(request.getPar
219: <option value="<%if(request.getPar
220: <option value="<%if(request.getPar
Stacktrace:
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
root cause
java.lang.NullPointerExcep
org.apache.jsp.WEB_002dINF
org.apache.jasper.runtime.
javax.servlet.http.HttpSer
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks it works!
Open in new window
BR-Sudhindra-www.clicksperday.com