?
Solved

Selecting from two drop down boxes.

Posted on 2002-07-22
9
Medium Priority
?
299 Views
Last Modified: 2010-04-01
I have a jsp page and it has two drop down boxes. If choose Category1 from the first and Subcategory1 from the second drop down and click OK button it should take me to subcategory1.jsp. If i choose Category1 and Subcategory2 from the second drop down and click OK button it should take me to Subcategory2.jsp. If i choose Catgeory1 and SubCategory3 it should send me to error page. How do i do it in Jsp without using Javascript. I would appreciate a code for this.

 Ramani


<html>
<body>
<form NAME="TControlForm">
<table  border="0" cellspacing="0" cellpadding="0">
    <tr>
       <td >View </td>
             
         <td><select name="TType" size="3" multiple >
<option selected></option>
<option>Category1</option>
<option>Category2</option>
<option>Category3</option>
<option>Category4</option>
<option>Category5</option></select><br></td>
                     <td><select name="TCategory" size="3" multiple >
                     <option selected>All</option>
<option>SubCategory1</option>
<option>SubCategory2</option>
<option>SubCategory3</option>
<option>SubCategory4</option>
<option>---------------------------</option></select><br></td>
   </tr>
</table>
</body>
</html>
0
Comment
Question by:ramani081399
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 7170430
one option could be to have the JSP submit to a redirect JSP that reads in the form submitted fields and based on the values redirects the user accordingly.

CJ
0
 

Author Comment

by:ramani081399
ID: 7170456
cheekycj,
I am looking for code to acomplish this.
Ramani
0
 
LVL 6

Accepted Solution

by:
kotan earned 600 total points
ID: 7170932
trigger below servlet when click OK button.


void doPost(HttpServletRequest req, HttpServletResponse resp)
{
    String TType = req.getParameter( "TType" );
    String TCategory = req.getParameters( "TCategory" );
   
    if ( "Category1".equals( TType ) )
    {
        if ( "SubCategory1".equals( TCategory ) )
        {
            resp.sendRedirect( "subcategory1.jsp" );
        }
        else if ( "SubCategory2".equals( TCategory ) )
        {
            resp.sendRedirect( "subcategory2.jsp" );
        }
        else if ( "SubCategory3".equals( TCategory ) )
        {
            resp.sendRedirect( "error.jsp" );
        }
    }
}
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:ramani081399
ID: 7173016
Kotan,

  I tried the way u have sugessted but get a error saying that forwarding URL cannot be found.
package FirstJSP;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class TestDropDown extends HttpServlet {
 
 
   String defaultName;
   String TType ;
   String TCategory;

 
  public void init(ServletConfig config) throws ServletException
  {
    super.init(config);
   }
 
  public void doPost(HttpServletRequest req, HttpServletResponse res)
       throws IOException
  {
    // Must set the content type first
    res.setContentType("text/html");
    // Now we can obtain a PrintWriter
    PrintWriter out = res.getWriter();
   
    defaultName = req.getParameter("yourname");
    out.println("<h4>");
    out.println("Hello" + " " + defaultName + "!");
    out.println("</h4>");
     TType = req.getParameter( "TType" );
     TCategory = req.getParameter( "TCategory" );

     if ( "Category1".equals( TType ) )
   {
       if ( "SubCategory1".equals( TCategory ) )
       {
           res.sendRedirect( "SubCategory1.jsp" );
       }
       else if ( "SubCategory2".equals( TCategory ) )
       {
           res.sendRedirect( "SubCategory2.jsp" );
       }
       else if ( "SubCategory3".equals( TCategory ) )
       {
           res.sendRedirect( "error.jsp" );
       }
   }
}

     
 
}

Form:

<html>
<body>
<form NAME="TControlForm" action="TestDropDown" method="post">
Enter your name:

<input type="text" name="yourname" size = 14>
<table  border="0" cellspacing="0" cellpadding="0">
   <tr>
      <td >View </td>
             
        <td><select name="TType" size="3" multiple >
<option selected></option>
<option>Category1</option>
<option>Category2</option>
<option>Category3</option>
<option>Category4</option>
<option>Category5</option></select><br></td>
                    <td><select name="TCategory" size="3" multiple >
                    <option selected>All</option>
<option>SubCategory1</option>
<option>SubCategory2</option>
<option>SubCategory3</option>
<option>SubCategory4</option>
<option>---------------------------</option></select><br></td>
  </tr>

</table>
<br>

<input type="submit" name="submit" value="Go">
</body>
</html>
0
 
LVL 6

Expert Comment

by:kotan
ID: 7173250
try

res.sendRedirect( "/SubCategory1.jsp" );
0
 

Author Comment

by:ramani081399
ID: 7174297
Kotan,
No it does not work. I have put the servlet testDropDown.java in package called FirstJSP. The compiled class i have put it under Web-Inf/classes/FirstJSP/TestDropDown.class
I get the error
Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI
 
Ramani
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7174369
How are you forwarding and/or accessing the servlet/JSPs?

Do you have entries in your web.xml to map URIs to Servlets?

CJ
0
 

Author Comment

by:ramani081399
ID: 7175107
cheekycj
no i dont have entries in web.xml.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7175193
you need to map your URIs to your servlets.

Like:

one entry in your web.xml would be:

    <servlet-mapping url-pattern="TestDropDown.jsp" servlet-name="TestDropDown" />
         <servlet>
            <servlet-name>TestDropDown</servlet-name>
            <servlet-class>FirstJSP.TestDropDown</servlet-class>
            <load-on-startup/>
        </servlet>

Now in your form update it to be:
<form NAME="TControlForm" action="TestDropDown.jsp" method="post">

Now if each SubCategory*.jsp is a servlet not a jsp you will have to add mapping such as the one above in the web.xml for each one of those.

CJ
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hey fellow admins! This time, I have a little fairy tale for you. As many tales do, it starts boring and then gets pretty gory. I hope you like it. TL;DR: It is about an important security matter, you should read it if you run or administer Windows …
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question