Use a FORM submit. You can have the submit action occur on the selection of
the item in the select list using javascript or use a submit button in your
HTML. Use the <jsp:forward> tag in an switch statement or from a nested if
in the JSP or use RequestDispatcher from a servlet to forward the desired
page. Pretty easy.

Something like (don't actually do code this awful):

<%
  String optsel = req.getParameter( list.getId() );

  if ( optsel != null && optsel.length() > 0 )
  {
    if ( optsel.equals( "page1" ) )
    {
%>
      <jsp:forward page="page1.jsp"/>
<%
    }
    else if ( optsel.equals( "page2" ) )
    {
%>
      <jsp:forward page="page2.jsp"/>
<%
    }
    else if ( optsel.equals( "page3" ) )
    {
%>
      <jsp:forward page="page3.jsp"/>
<%
    }
    else
    {
%>
      <jsp:forward page="page4.jsp"/>
<%
    }
  }
%>

And to prevent the flood of Javascript questions, here is the javascript for
selecting from a list:

<%
  //setup list and list options here (use your imagination).
%>
  <SELECT name="<%= list.getId() %>" size="1"
onChange="javascript:document.forms[0].submit()">
    <OPTION>[ All ]</OPTION>
    <%= options.toString() %>
  </SELECT>



-----Original Message-----
From: Scott Fitzgerald [mailto:[EMAIL PROTECTED]]
Sent: Monday, August 21, 2000 1:55 PM
To: [EMAIL PROTECTED]
Subject: Displaying .jsp page based on selection


Greetings,

I would like to display different .jsp pages based on the user selecting an
option in a Select List(i.e. one page for every option). Should I be using
any of the "forward" or "include" actions? If someone could suggest a
solution it would be much appreciated.

Scott Fitzgerald

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to