Reputation: 1828
I have a problem and can't find information.
I run my web-app from jsp-page which find on folder in "web". And try to go to servlet Smth like this
<form action="MyServlet" method="post">
<input type="submit" name="command" />
</form>
In web.xml next
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>mypackage.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
I thought that this should work but when I run my app I see next url for button
But my goal is get url localhost:8080/TomcatApp/MyServlet
I try to do it using GlassFish and Apache Tomcat 7. I don't know. Can you help me?
Upvotes: 2
Views: 1959
Reputation: 6887
The form's action is relative to the current page's path. So if your JSP is at /TomcatApp/folder/some-page.jsp
, just setting the action to MyServlet
is the same as /TomcatApp/folder/MyServlet
because it automatically uses the current path as a base. To get just /TomcatApp/MyServlet
, you need to set your form's action to either ../MyServlet
or ${request.contextPath}/MyServlet
.
Upvotes: 3