-1

I have a Dynamic application in which I have a JSP file which is sending a string to a Servlet which is in another project which is a Web application Project. I am using Tomcat server in JSP project and the server is starting just fine but when I am trying to run the web application on local host I am getting HTTP ERROR 500 Problem accessing /jsptoservlettocloud. Reason: INTERNAL_SERVER_ERROR

This is my JSP FILE

<body>
<% 
   String str= "Shanx";

   URL u = new 
       URL("http://localhost:8080/ServletToCloud/JSPToServletToCloudServlet");

       HttpURLConnection huc = (HttpURLConnection)u.openConnection();
       huc.setRequestMethod("GET");
       huc.setDoOutput(true);

       ObjectOutputStream objOut = new ObjectOutputStream(huc.getOutputStream());
       objOut.writeObject(str);
       objOut.flush();
       objOut.close();
%>  
 </body>

This is my Servlet Class

public class JSPToServletToCloudServlet extends HttpServlet 
{
String str;
protected void doGet(HttpServletRequest request, HttpServletResponse response)   
    throws ServletException, IOException 
    {
         ObjectInputStream ois = new ObjectInputStream(request.getInputStream());

        try
            {
                str= (String) ois.readObject();
        }

         catch (ClassNotFoundException e) 
         {
             e.printStackTrace();
         }

         finally
         {
        ois.close();
         }
    System.out.println("Servlet received : " + str); 
}
 }

This is my Web.xml file

<servlet>
    <servlet-name>JSPToServletToCloud</servlet-name>
    <servlet-class>pack.exp.JSPToServletToCloudServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>JSPToServletToCloud</servlet-name>
    <url-pattern>/jsptoservlettocloud</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

In the url ServletToCloud is the name of the web application project and JSPToServletToCloudServlet is the name of the servlet. Is this url correct.

1 Answers1

0

In your jsp you have http://localhost:8080/ServletToCloud/JSPToServletToCloudServlet but you have /jsptoservlettocloud in your web.xml Your mapping is wrong.

Boss Man
  • 587
  • 2
  • 12