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 Servlets and the fly likes Trying to access a servlet on  button click 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 » Java » Servlets
Bookmark "Trying to access a servlet on  button click" Watch "Trying to access a servlet on  button click" New topic
Author

Trying to access a servlet on button click

Ghazala Islam
Ranch Hand

Joined: Nov 22, 2000
Posts: 73
Hello,

I am trying to call a servlet on button click.Its not a submit button,but a graphical button (not a part of form).
When i click the button get the message:

HTTP STATUS 405:HTTP method GET is not supported by this URL.
The specified HTTP method is not allowed for the requested resource.

When i reference a jsp page it displays the page.Is there any way that I can call a SERVLET and send some information along the servlet name.If yes ,what should be the code?

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

As this is about servlets, it has been moved to the Servlets forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rao Raghu
Ranch Hand

Joined: Jan 05, 2007
Posts: 100

Originally posted by Ghazala Islam :
Is there any way that I can call a SERVLET and send some information along the servlet name.If yes ,what should be the code?




I am afraid you cannot do that with servlets. Servlets only process the requests through the service() or doGet() or doPost() methods. You have to use a form with one of these methods to access the service methods. Clicking a graphical button without a from cannot take you to a servlet. There is no other way. Lets say if even if you send parameters in the URL, how will you invoke the service methods? You got to re-adjust your application.



RAGHU<br /> <br />"When the going gets tough, the tough get going"
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
What method did you override....

doget or dopost??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Originally posted by rao raghu:
Clicking a graphical button without a from cannot take you to a servlet.


Horse pockey! There are numerous ways this could be accomplished via Javascript.
Ghazala Islam
Ranch Hand

Joined: Nov 22, 2000
Posts: 73
Servlet is overriding dopost method.
Ghazala Islam
Ranch Hand

Joined: Nov 22, 2000
Posts: 73
Servlet is overriding dopost method.
Ali Hassaan
Ranch Hand

Joined: May 16, 2001
Posts: 103
implement doget method.. and pass all the data you want to use in servlet in querystring.. for e.g.
http://url/servlet/MainServlet?userId=Ali&password=Ali

in doget method of servlet...get values of parameter via request.getParameter("userId")
Hunny Lee
Greenhorn

Joined: Feb 17, 2007
Posts: 23
Originally posted by Ghazala Islam:


HTTP STATUS 405:HTTP method GET is not supported by this URL.
The specified HTTP method is not allowed for the requested resource.


Most probably you did not implement the doGet() method.
Try doing that first and tell us how it goes.
Ghazala Islam
Ranch Hand

Joined: Nov 22, 2000
Posts: 73
The problem is pretty much solved as i had not override the doGet method in the servlet.
One more question,how can i associate a dyanamic value with a url,as usually we append fixed value with url as below,

http://url/servlet/myservlet?companyid=xyz
but what if company id changes everytime?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Trying to access a servlet on button click
 
Similar Threads
jsf: open pdf in browser
Default action of <a href="link">
invoking servlet from link in jsp
servlet beginner confused
"HTTP method POST is not supported by this URL"