6 Replies Latest reply: Feb 11, 2012 8:57 PM by EJP RSS

    Calling servlet from jsp when jsp is not at root

    916615
      I have a very simple web application MusicStore which has one servlet ShoppingServlet and one jsp EShop.jsp. This is how the web.xml is for the servlet:
      <servlet>
          <servlet-name>ShoppingServlet</servlet-name>
          <servlet-class>shopping.ShoppingServlet</servlet-class>
      </servlet>
      <servlet-mapping>
          <servlet-name>ShoppingServlet</servlet-name>
          <url-pattern>/ShoppingServlet</url-pattern>
      </servlet-mapping>
      The jsp is not at root but actually in jsp\shopping folder. This is how I access the jsp:
      http://localhost:8080/MusicStore/jsp/shopping/EShop.jsp
      Now this jsp has a form who I want to submit to the servlet. My question is what should be the action for this form?
      <form name="shoppingForm" action="" method="post">
      when I use
      <form name="shoppingForm" action="ShoppingServlet" method="post">
      it gives me HTTP Status 404 error message: The requested resource (/MusicStore/jsp/shopping/ShoppingServlet) is not available.

      when I use
      <form name="shoppingForm" action="/ShoppingServlet" method="post">
      it gives me HTTP Status 404 error message: The requested resource (/ShoppingServlet) is not available.

      when I use
      <form name="shoppingForm" action="MusicStore/ShoppingServlet" method="post">
      it gives me HTTP Status 404 error message: The requested resource (/MusicStore/jsp/shopping/MusicStore/ShoppingServlet) is not available.

      when I use
      <form name="shoppingForm" action="/MusicStore/ShoppingServlet" method="post">
      it works. But I dont want to use MusicStore name in the jsp.

      Any help is greatly appreciated.

      Thanks in advance