• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem calling Servlet from jsp.  RSS feed

 
Abiodun Okusolubo
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I have:


JSP:

<form method ="GET" action = "TestResult.do">

<center><input type="submit"></center>
</form>


web-xml:

<servlet>
<servlet-name>testing</servlet-name>
<servlet-class>testResult.TestResult</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>testing</servlet-name>
<url-pattern>/TestResult.do</url-pattern>
</servlet-mapping>


Servlet:

package testResult;

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

public class TestResult extends HttpServlet{


These work perfectly with JSP in the root directory. The JSP can call servlet with no problem at all. However, If JSP is placed in another directory e.g. root/anotherFolder/file.jsp, then I face the problem of calling my Servlet from the JSP.

Please if you have any answer to this question, please help. I am using Tomcat as my Container.
Waiting to hear from you.
Thank you.
 
Marco Fung
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try change your JSP to

<form method ="GET" action = "/TestResult.do">

<center><input type="submit"></center>
</form>

If I am right, since JSP will translate and compile into servlet. When a relative path is used, the generate JSP_servlet will use it related path to find another servlet.

In the cases, the relative path included the directory of the jsp, which doesn't fall into the context path.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!