Link to home
Start Free TrialLog in
Avatar of _Esam
_Esam

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of mrcoffee365
mrcoffee365
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of _Esam
_Esam

ASKER

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.
Great -- glad to help.