File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make a select option selected for a certain option?

 
May Hsiao
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a "select"- on my JSP page, it has 5 options. I want to base on the database' data to make a certain option selected. How to write this JSP code? I kmow it only need to type "selected" in the <option ...... selected /option>
 
kichu kichu
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a sample code that i have posted,here I'am getting a set of values say RelatedProject names from the database.
Now suppose we pass a RelatedProject name,we have to see if this value we have passed is present in the database or not.
If it is present in the database,then this value should remain selected.
strRelProj1--->Set of projects from database.
strRelProj---->The value that we pass.

<%
//Query to display Related Project Details
sql = "select NAME from XD_ENTOBJ where ENTITY_UID="+intEUID;
//Execute Query
rs = stmt.executeQuery(sql);
while ( rs.next() )
{
String strRelProj1 = rs.getString(1);
if ( strRelProj1.equals(strRelProj) )
{
out.println("<option value=" + strRelProj1+ " selected >"
+ strRelProj1+ "</option>");
}
else
{
out.println("<option value=" + strRelProj1+ " >"
+ strRelProj1+ "</option>");
}
}
%>
hope this helps!!!:-)
Doubts if any are always welcome.
regards,
kichu
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic