Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

How to Navigate among 3 JSP ?

How to Navigate between JSP pages?

Hi,

I can't seem to navigate among 3 JSP pages.
Here is what I did.

I have the first JSP page where I have:

<BODY>
Welcome to Hello1
<form action="../Hello1" method="POST">       //since the servlet Hello1 is at JavaSource package and
                                              //the Hello1.jsp is at WebContest/jsp/Hello1.jsp


<input type="submit" value="Process Hello1" >
</form>
</BODY>


Inside the Hello1.java Servlet, I have...

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          doPost(request, response);
      }

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      

            try{
                getServletContext().getRequestDispatcher("/jsp/Hello2.jsp").forward(request, response);
               
                System.out.println("Inside Hello1 Servlet");
                Logger.log(Hello1.class, Logger.ERROR, "Inside Hello1 Servlet");
      
            }
            catch(Exception nEx){
                Logger.log(Hello1.class, Logger.ERROR, "ERROR: Inside Hello1 Servlet", nEx.getMessage());
            }
}

NOW I can come from Hello1.jsp thru the servlet to the Hello2.jsp

Now Here is what I have in Hello2.jsp

<BODY>
Welcome to Hello2
<form action="../Hello2" method="get">


<input type="submit" value="Process Hello1" >
</form>
</BODY>

Now insider Hello2.java servlet.... I have:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          doPost(request, response);
      }

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      

            try{
                getServletContext().getRequestDispatcher("/jsp/Hello3.jsp").forward(request, response);
               
                System.out.println("Inside Hello1 Servlet");
                Logger.log(Hello1.class, Logger.ERROR, "Inside Hello2 Servlet");
      
            }
            catch(Exception nEx){
                Logger.log(Hello1.class, Logger.ERROR, "ERROR: Inside Hello2 Servlet", nEx.getMessage());
            }
}

Now, I can't seem to go to Hello3.jsp ..

The explorer is saying can't find the resources ??

What should I do to make it work?

Let me know.

Thax.
_Esam.
0
_Esam
Asked:
_Esam
  • 2
1 Solution
 
mrcoffee365Commented:
Did you create Hello3.jsp?

If so, how did you configure your access to your servlets?  When I created these pages, I fixed your URLs for the servlets.

By default, a servlet's location in a URL is
http://[host]:[port]/servlet/[servletname]

So I changed your form action in Hello1.jsp like this:
from
<form action="../Hello1" method="POST">  

to
<form action="/servlet/Hello1" method="POST">

With those changes, your sequence of events worked fine.

0
 
_EsamAuthor Commented:
Yes, I understand what you said.

I undsertood the relative path thing also while testing them.


Since my JSP's were under jsp folder I tried like:

From Hello1.jsp
<form action="../servlet/Hello1" method="POST">

Inside Hello1.java

getServletContext().getRequestDispatcher("/jsp/Hello2.jsp").forward(request, response);


From Hello2.jsp
<form action="../servlet/Hello2" method="POST">

Insicde Hello2.java
getServletContext().getRequestDispatcher("/jsp/Hello3.jsp").forward(request, response);

and they did work fine.



Thanks a lot..


Regards,
_Esam.
0
 
mrcoffee365Commented:
Great -- glad to help.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now