This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Get and Post with Init Params Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Get and Post with Init Params" Watch "Get and Post with Init Params" New topic
Author

Get and Post with Init Params

Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
This code works well when I use "POST but does not work when I use "GET"
I get "This url does not support get" something of this sort

Is it because I am not allowed to use "GET" when i am retrieving Init Parameters.



My Web.xml


DrinkSelect.java


And if needed My form.html



The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Do you really not indent your code?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 253

Hey Nabila,
What are you getting in the browser when you use get in the form.
I guess you might be getting a blank page in browser, reason being you have not overriden the doGet() method of HttpServlet Class.

Kindly let us know if you see some behavior other than this while using get form method.


Regards
Salil Verma
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41036
    
  43
It has nothing to do with init parameters. The default action of the methods in HttpServlet is to throw a "not supported" exception. Only those methods that you override (doGet, doPost etc.) will be allowed.


Ping & DNS - my free Android networking tools app
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
ok.. that helped !

I guess I was looking at the wrong file because I was pretty sure I was getting this error after overriding the Get Method and using the method "GET".

Thanks Everybody!
And sorry about the indentation.
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 253

Hey ulf,
The default action of the methods in HttpServlet is to throw a "not supported" exception. Only those methods that you override (doGet, doPost etc.) will be allowed.


I tested and found that you are correct. but I am curious to know why does it give not supported exception. doGet is called from the service method and HttpServlet already contains and doGet method implementation. Does this protected implementation of doGet in HttpServlet always throws this exception whenever accessed ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41036
    
  43
I am curious to know why does it give not supported exception.

The HttpServlet class can't know what a servlet that extends it should do for any particular method, so it makes sense to report an error for all methods that have not been overridden.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get and Post with Init Params
 
Similar Threads
getServletConfig
jsp-file tag
HTTP method GET is not supported by this URL
Servlet doesn't pick initial parameter
getServletConfig() and getServletContext()