V
vaneric
hi,
I have an index.jsp where i am collecting user input through form
fields.I want to send the data to doPost() method of a Servlet.I am
deploying my web app at a context, say 'myapp'.
index.jsp
--------
<body>
<h2>Entry Form</h2>
<form name="Name Input Form" method="Post" action="/posthandler">
Enter your Name:
<input type="text" name="name" value="" />
<input type="submit" value="OK" />
</form>
</body>
In my servlet
-------------
doPost()....{
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter( );
String name = request.getParameter("name");
out.println("<html>");
out.println("<body>");
out.println("<h1>You Entered</h1>");
out.println(
"Your name is: " + ( (name == null || name.equals("")) ?
"Unknown" : name));
...
}
In web.xml ,I mapped the servlet
<servlet>
<servlet-name>PostHandler</servlet-name>
<servlet-class>org.mypackage.PostHandler</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PostHandler</servlet-name>
<url-pattern>/posthandler</url-pattern>
</servlet-mapping>
But when I click the Submit button in the html page created by
index.jsp ,it tries to access
http://localhost:8080/posthandler
I suppose what needs to be invoked is
http://localhost:8080/myapp/posthandler
Can someone tell me how I can do that from index.jsp ? I got the
correct result when I put
<form name="Name Input Form" method="Post" action="/myapp/
posthandler">
But I am a little doubtful.The context name 'myapp' is something I
give in build.xml .Hardcoding that in index.jsp doesn't feel right
Please advise
thanks
eric
I have an index.jsp where i am collecting user input through form
fields.I want to send the data to doPost() method of a Servlet.I am
deploying my web app at a context, say 'myapp'.
index.jsp
--------
<body>
<h2>Entry Form</h2>
<form name="Name Input Form" method="Post" action="/posthandler">
Enter your Name:
<input type="text" name="name" value="" />
<input type="submit" value="OK" />
</form>
</body>
In my servlet
-------------
doPost()....{
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter( );
String name = request.getParameter("name");
out.println("<html>");
out.println("<body>");
out.println("<h1>You Entered</h1>");
out.println(
"Your name is: " + ( (name == null || name.equals("")) ?
"Unknown" : name));
...
}
In web.xml ,I mapped the servlet
<servlet>
<servlet-name>PostHandler</servlet-name>
<servlet-class>org.mypackage.PostHandler</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PostHandler</servlet-name>
<url-pattern>/posthandler</url-pattern>
</servlet-mapping>
But when I click the Submit button in the html page created by
index.jsp ,it tries to access
http://localhost:8080/posthandler
I suppose what needs to be invoked is
http://localhost:8080/myapp/posthandler
Can someone tell me how I can do that from index.jsp ? I got the
correct result when I put
<form name="Name Input Form" method="Post" action="/myapp/
posthandler">
But I am a little doubtful.The context name 'myapp' is something I
give in build.xml .Hardcoding that in index.jsp doesn't feel right
Please advise
thanks
eric