wood burning stoves 2.0*
The moose likes JSP and the fly likes Display the Selected DropDown Value to another JSP Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Display the Selected DropDown Value to another JSP Page" Watch "Display the Selected DropDown Value to another JSP Page" New topic
Author

Display the Selected DropDown Value to another JSP Page

Daryll sabate
Greenhorn

Joined: Apr 03, 2012
Posts: 7
hi, im a newbie in JSP Programming,

i have a simple PRogram that can display/add/delete/edit the value from the database.. in my homePage.jsp i have one DropDown Menu this is filter the record.. my problem is in my AddRecord.jsp. because if a user select a value on the DropDown Menu ex. PAGE-1 and click ADD button, what i want to do is to display on the DROPDOWN is the SELECTED value of PAGE-1. but its not working instead when i SELECT PAGE-1 from the DropDown and Click ADD button, the value of dropdown in AddRecord that jsp will be back to empty which the user need to select the value again..

this for quick understanding..hope so...

ex. i have a car collection program. which is categorized according to brand name. and if i select the brand FERARI and i want to add new car in this category.. it will automatically display my selected FERARI then add the new can to it.....

hope it will help... sorry for my poor english..

thank you for some help..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61450
    
  67

Place the selected attribute on the option element that you want to be selected in the drop down.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Daryll sabate
Greenhorn

Joined: Apr 03, 2012
Posts: 7
honestly i dont get it.. as i've said im just a pure newbie in jsp.. so its sounds like chinese to me..

here is my code..

Homepage.jsp




on that.. when i select a value on the dropdown, and click ADD.. it will display the nextpage which is InsertReport.jsp

InsertReport.jps code:


what i want is..when i select a value a value of dropdown in HomePAge.jsp and click ADD what i want to see in the next page is the SELECTED VALUE FROM HomePage.jsp is Display to InsertReport.jsp automatically..


hope you will understand.. thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61450
    
  67

As a novice to JSP it's important that you learn JSP correctly and you're on a very bad track.

After the introduction of JSP2 in 2002 -- yes, 10 years ago - putting Java code, and especially database code, into a JSP is considered an unacceptable practice. It still exists for compatibility with legacy applications, but any JSP written after 2002 should be using the JSTL (JSP Standard Tag Library) and EL (Expression Language) in place of Java scriptlets.

I'd also recommend reading the following articles:
  • The Secret Life of JSPs
  • The Front Man

  • But what it comes down to is as easy as this: if you want a particular option in the drop down to be selected, you put the selected attribute on the option. For example:
    <option value="whatever" selected>Whatever!</option>

    Frequently the EL's ternary operator is useful for this. For example:
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Display the Selected DropDown Value to another JSP Page