newbie Servlet doPost() handling problem

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

newbie Servlet doPost() handling problem

fabiandev
Hi,

I am new to Jetty, and have the following problem for which i couldn't find easily any information on the web or in the previous posts.

I start a server and want to add many servlets, like in this example :
http://jetty.mortbay.org/xref/org/mortbay/jetty/example/ManyServletContexts.html

It was working well, and later i realised that calling the services with a GET method was ok. But calling them with a POST method would not work.

I first thought my servlet was wrong, but i finally found out that it was the way i added it to the server that makes it work or not.

So, adding the servlet like that works :
        Context root = new Context(contexts,"/",Context.SESSIONS);
        ServletHolder holder = new ServletHolder(new ServletOntoMea());
        holder.setName("OntoMea");
        root.addServlet(holder, "/*");

But, changing the first line to add a contextPath will cause the problem :
Context root = new Context(server,"/sparql",Context.SESSIONS);

then, i never get a correct POST to the servlet.
I did debug the ServletOntoMea.service()
and when specifying the "/sparql" contextPath, the req.getMethod(); is always 'GET', even when a POST is sent..

as i am new, everything is unclear to me and how to solve the problem ?
Thanks for any help
Fabian
Reply | Threaded
Open this post in threaded view
|

Re: newbie Servlet doPost() handling problem

Chris Haynes
Have you implemented *both* the doGet() and doPost() methods in your Servlet?

Chris Haynes



On Tuesday, March 20, 2007 at 12:18:33 PM, fabiandev wrote:
> Hi,

> I am new to Jetty, and have the following problem for which i couldn't find
> easily any information on the web or in the previous posts.

> I start a server and want to add many servlets, like in this example :
> http://jetty.mortbay.org/xref/org/mortbay/jetty/example/ManyServletContexts.html

> It was working well, and later i realised that calling the services with a
> GET method was ok. But calling them with a POST method would not work.

> I first thought my servlet was wrong, but i finally found out that it was
> the way i added it to the server that makes it work or not.

> So, adding the servlet like that works :
>         Context root = new Context(contexts,"/",Context.SESSIONS);
>         ServletHolder holder = new ServletHolder(new ServletOntoMea());
>         holder.setName("OntoMea");
>         root.addServlet(holder, "/*");

> But, changing the first line to add a contextPath will cause the problem :
> Context root = new Context(server,"/sparql",Context.SESSIONS);

> then, i never get a correct POST to the servlet.
> I did debug the ServletOntoMea.service()
> and when specifying the "/sparql" contextPath, the req.getMethod(); is
> always 'GET', even when a POST is sent..

> as i am new, everything is unclear to me and how to solve the problem ?
> Thanks for any help
> Fabian


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: newbie Servlet doPost() handling problem

fabiandev
hello Chris, thanks

yes, i did implement both doGet() and doPost()

and as i said, i did override the service() method to see what was going on...and as i said, just depending on how the Context object is instanciated :
the req.getMethod() is right ("POST") when instanciating with
Context root = new Context(contexts,"/",Context.SESSIONS);
-> and so the doPost() is called
, and it's wrong ("GET") when instanciating with
Context root = new Context(server,"/sparql",Context.SESSIONS);
-> and so, a doGet() is called

...with the same calling code that does a POST...

well...i thought i was a simple and stupid mistake of mine. But is it something more complexe ? what information could i provide to get some more help ?

Actually, what i want to do is just the following :
being able to display a file contained on the server when querying for example http://myServer/query.html
and also being able to call one service, like : http://myServer/sparql?query=...
and another services : http://myServer/loc?list=countries

so, i wanted to add a webAppContext to give http access to the files, like query.html
and then add a servlet that would look at the queried service, for example 'sparql' or 'loc', and then call a correct processor...

Thanks again
Fabian

Chris Haynes wrote
Have you implemented *both* the doGet() and doPost() methods in your Servlet?

Chris Haynes



On Tuesday, March 20, 2007 at 12:18:33 PM, fabiandev wrote:
> Hi,

> I am new to Jetty, and have the following problem for which i couldn't find
> easily any information on the web or in the previous posts.

> I start a server and want to add many servlets, like in this example :
> http://jetty.mortbay.org/xref/org/mortbay/jetty/example/ManyServletContexts.html

> It was working well, and later i realised that calling the services with a
> GET method was ok. But calling them with a POST method would not work.

> I first thought my servlet was wrong, but i finally found out that it was
> the way i added it to the server that makes it work or not.

> So, adding the servlet like that works :
>         Context root = new Context(contexts,"/",Context.SESSIONS);
>         ServletHolder holder = new ServletHolder(new ServletOntoMea());
>         holder.setName("OntoMea");
>         root.addServlet(holder, "/*");

> But, changing the first line to add a contextPath will cause the problem :
> Context root = new Context(server,"/sparql",Context.SESSIONS);

> then, i never get a correct POST to the servlet.
> I did debug the ServletOntoMea.service()
> and when specifying the "/sparql" contextPath, the req.getMethod(); is
> always 'GET', even when a POST is sent..

> as i am new, everything is unclear to me and how to solve the problem ?
> Thanks for any help
> Fabian


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jetty-support mailing list
Jetty-support@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jetty-support