On 01/28/10 07:00 AM, glassfish_at_javadesktop.org wrote:
> I use annotations instead of web.xml, but you are correct with your assumptions, my servlet is mapped to "/".
>
> Mapping to "" solved the problem, but revealed another problem:
> When mapping a servlet to "", the container doesn't seem to accept POST requests to this servlet. The doGet() method is always invoked, and any parameters are stripped away.
>
This is a problem with your form, see below ...
> Here's a servlet and html file that reproduces the problem:
>
> [b]#### ee6test.TestServlet ####[/b]
>
> package ee6test;
>
> import javax.servlet.ServletException;
> import javax.servlet.annotation.WebServlet;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import java.io.IOException;
> import java.util.Enumeration;
>
> @WebServlet("")
> public class TestServlet extends HttpServlet {
> @Override
> protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
> dump("doGet", request, response);
> }
>
> @Override
> protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
> dump("doPost", request, response);
> }
>
> private void dump(String method, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
> response.setContentType("text/plain");
> response.getWriter().println(method + "\n");
> response.getWriter().println("HEADERS:");
> Enumeration<String> headerNames = request.getHeaderNames();
> while (headerNames.hasMoreElements()) {
> String name = headerNames.nextElement();
> response.getWriter().println(name + ": " + request.getHeader(name));
> }
>
> response.getWriter().println("\nPARAMETERS:");
> Enumeration<String> parameterNames = request.getParameterNames();
> while (parameterNames.hasMoreElements()) {
> String name = parameterNames.nextElement();
> response.getWriter().println(name + ": " + request.getParameter(name));
> }
> }
> }
>
> [b]#### test.html ####[/b]
>
> <html>
> <body>
>
> <form action="/EE6Test_war_exploded" method="GET">
> <fieldset>
> <legend>GET</legend>
> <input type="text" name="test" value="test"/>
> <input type="submit"/>
> </fieldset>
> </form>
>
> <form action="/EE6Test_war_exploded" method="POST">
>
You need to append a "/" to the action URI, as in
<form action="/EE6Test_war_exploded/" method="POST">
If you don't, then when the form is submitted using POST at
/EE6Test_war_exploded
the browser will get a parameter-less (since the parameters were part
of the request body, as opposed to the request URI) redirect to
/EE6Test_war_exploded/
which it will follow with a parameter-less GET.
On the other hand, if you submit the form using GET at
/EE6Test_war_exploded?test=test
the browser will get a redirect to
/EE6Test_war_exploded/?test=test
(that is, the parameters will be preserved in the redirect, since
they were part of the original request URI).
Give it a try and let us know how it works.
Thanks,
Jan
> <fieldset>
> <legend>POST</legend>
> <input type="text" name="test" value="test"/>
> <input type="submit"/>
> </fieldset>
> </form>
>
> </body>
> </html>
> [Message sent by forum member 'toker5' (java.net_at_reinseth.org)]
>
> http://forums.java.net/jive/thread.jspa?messageID=383486
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>