Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help needed to 'Forward' Servlet to Servlet

 
Apple Khoa
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I am trying hard in my code to call one servlet from another servlet, but I have no idea what's wrong with my code that I kept getting the following error message:

HTTP Status 405 - HTTP method POST is not supported by this URL
--------------------------------------------------------------------------------
type Status report
message HTTP method POST is not supported by this URL (http://localhost:8080/helloservlet/control)
description The specified HTTP method is not allowed for the requested resource (HTTP method POST is not supported by this URL).


What I am trying to do is to call a servlet (ControlServlet) from my html form, and then ControlServlet is to call the EasyQnServlet when a user selects the 'Easy Question' radio button on my webpage. If the user selects 'Hard Question' radio button, the ControlServlet should call the HardQnServlet.

In a nutshell, the path is like this: HTML form > ControlServlet > EasyQnServlet / HardQnServlet

I am trying to use the forward function in my ControlServlet code (shown below):



My web.xml code:


I use doPOST in both my EasyQnServlet & HardQnServlet.
In my html form, I use <form method = "POST" action="control">

(Using doGET in all servlets give me the same error as well)

Can anyone kindly advise me on how can I solve this problem?

An advance thanks to all.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64701
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at your servlet. Really look at it. Hint: line 3.
 
Apple Khoa
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is exactly the same as what I read from a 'forward servlet' tutorial, except for the name of the servlet. As for the web.xml, I wrote it myself.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64701
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not looking hard enough at line 3. If it matches the tutorial, throw the tutorial away as it is useless.

Here's another hint: Java is case-sensitive
 
Apple Khoa
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You're not looking hard enough at line 3. If it matches the tutorial, throw the tutorial away as it is useless.

Here's another hint: Java is case-sensitive


Yeah Bear Bibeault, you are right, Java is case-sensitive. I have edited the doPOST to doPost. The previous error is resolved but another error surfaces - Error 404 (no details shown). Is my forward servlet code in the core correct?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64701
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried to hit the servlets directly using the browser?
 
Apple Khoa
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:What happened when you tried to hit the servlets directly using the browser?


Everything was working fine when I call the EasyQnServlet directly from my webpage without the ControlServlet 'in between'. However, Error 404 (no details shown) surfaces when I add and call ControlServlet, which has the code attached above. I have no idea if it is the coding in the ControlServlet, or the mapping in the web.xml that is wrong.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64701
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:What happened when you tried to hit the servlets directly using the browser?
 
Apple Khoa
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:What happened when you tried to hit the servlets directly using the browser?


When I tried to invoke the ControlServlet with http://localhost:8080/servlet/ControlServlet, Error 404 appears with no details shown.
The same thing happened when I invoked EasyQnServlet with http://localhost:8080/servlet/EasyQnServlet.

But is it supposed to show something since my servlets has to receive users inputs (get.Parameter) before it can output anything?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64701
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apple Khoa wrote:
When I tried to invoke the ControlServlet with http://localhost:8080/servlet/ControlServlet, Error 404 appears with no details shown.

Not surprising as that doesn't match any of your servlet mappings. You can't just make up URLs. You have to use the actual mappings.
 
Apple Khoa
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Not surprising as that doesn't match any of your servlet mappings. You can't just make up URLs. You have to use the actual mappings.


Actual mappings? Is it like this (my modified web.xml):



Error displayed when I invoke the servlets using http://localhost:8080/servlet/EasyQnServlet:

HTTP Status 404 - /servlet/EasyQnServlet
--------------------------------------------------------------------------------
type Status report
message /servlet/EasyQnServlet
description The requested resource (/servlet/EasyQnServlet) is not available.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64701
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not see the string "/servlet" in your mappings. Why is it in your URL if it's not in your mapping?
 
Apple Khoa
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I do not see the string "/servlet" in your mappings. Why is it in your URL if it's not in your mapping?


I learnt from websites that I can invoke servlet from browser using http://machine-name:port/servlet/servlet-name. Inserting "/servlet" in my mappings doesn't help too, producing the same error.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64701
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You learned wrongly.

You use the mapping. Forget about the silly "/servlets" string.
 
Apple Khoa
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You learned wrongly.

You use the mapping. Forget about the silly "/servlets" string.


What's wrong with my mapping?


along with my ControlServlet code:


The html page, servlets are all in the same folder (Apache tomcat > webapps > helloservlet)

HTML in Apache tomcat > webapps > helloservlet
Servlets classes in Apache tomcat > webapps > helloservlet > WEB-INF > classes > simuleqn
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you ignore the "servlet" String from the URL in the browser?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic