Hi I was just curious when is the doPut() method in a servlet called. I know that if the form on a jsp/html page has a "post" method then the doPost() is called otherwise if it has a "GET" then the doGet() is called.When is the doPut() called ??
When an HTTP PUT request is received, naturally.
Can a page do a PUT request by code?
The only valid method attribute values of a <form> are get and post, according to the HTML5 spec. I assume that's what you're asking.
The doPut() method handles requests send by using the HTTP PUT method. The PUT method allows a client to store information on the server. For an example, you can use it to post an image file to the server. As the above answer says, goGet() and doPost() are in use, mostly. In my case, I use only these two, and I am getting only get requests, so I simply transfer the get request to doPost() and do my job easily.
if you want to send some confidential values in url via form you must use the post method, If you will use the get method for the form like login the values parameters like userid and password will be visible in url and anyone can hack that thing. So better to use post method in forms. By default it will call get method.
in get the url is like http://url?method=methodname&userid=123&password=123
so if you use post method the url will be like this http://url/methodname.do
Related
I have read about Servlet's in many tutorials. The Servlet parameters has getParameter() method. As the parameter has return type as only String. Why the ServletRequest do not have setParameter() method ?
I have read about that only attributes in Servlet's can be changed, and the parameters can not. Can anyone explain the basic concept why there is no provision for updating the parameter in request with method like setParameter()?
As per ServletRequest documentation, it is mentioned that :
Defines an object to provide client request information to a servlet.
That means ServletRequest object is used to transfer client side information to server methods. For ex. text field values from jsp page to servlet's doGet or doPost method.
ServletRequest Object is an client request to a Servlet, and ServletResponse object is the response sent to the client so always you get the required information from the request and you set the information in the response............!
Application developers use parameter for getting information from client, where as attributes are used by application developer for overall internal management purposes. You can not change (setParameter()) the values given to you by clients in parameters; you can simply get those values using getParameter()
I have written a helper function that can retrieve content from a url. This function can also parse a Map of parameters and feed a url or a body on request depending on GET or POST method. Let's say this function also do other things (change headers, cookies etc...). How can I test this function against an http(s) server ? How to simulate a fake servlet that will answer to the request made by this function ?
I've seen that we can use mock object, or other library that are specialized in servlet unit testing. But it doesn't seem to fit my needs as I trully need to test the request and its answer without changing the function content.
I would say to start up Jetty in embedded mode within your test.
Configure it to accept a request, validate it, and return an appropriate response.
See docs here: http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty
My app started by another app, and at initiating it must get POST parameters. I read that i can get GET parameters using Window.Location.getParameter . But I need to get POST parameter from request. How to implement it?
"get" in getParameter() means "retrieve", it's the standard Java naming convention for getters; it has nothing to do with the HTTP request method.
I've written a rest interface (with jersey), a browser will be calling this rest interface. I would like show some html/jsp to the user as a response to this rest call...
Is this possible? How do I do it?
Yes, that is possible. This post as well as this one gives a hint how to use Viewables to return JSPs as a response.
I have a query form that I would like to submit as a GET request so the result page may be bookmarked and otherwise RESTful. It's your classical text field with a submit button. How do I induce Seam/JSF to use GET and include the query expression as a parameter rather than POST, the default?
All you need to do is enable the SeamFilter in web.xml. See Blog Example for an example RESTful application using Seam. The key is to use a Seam page parameter, defined in WEB-INF/pages.xml
you can use a PhaseListener to convert POST requests to GET requests or just to interpret GET requests so that they can be bookmarkable.
This page should explain in more detail:
http://balusc.blogspot.com/2007/03/post-redirect-get-pattern.html
If you are using s:button or s:link, your form will be using GET method.