Question

I have a very long url with numbers of parameter like

http://localhost:8080/BUUK/dbcc?dssin=9371062001&roundid=JS&KIPL=02&PLATFORM=1&FREQUENCY=2&DRBEARER=1&BUYTYPE=1&EUP=12&TID=72123456435653654&SHORTCODE=54300&ADCODE=234rfdfsf&Buytag=3&Checkpoint=5,6,7&CHARGEMODEL=complete&restbalance=1

I want retrieve all the parameter from this url.

I was wondering if i can use request.getParamter("restbalance");

I will provide more info if required. Thanks

Était-ce utile?

La solution 2

For each request your web server more precisely your web container creates a two object request and response.

HttpServletRequest and HttpServletResponse

The servletcontainer is attached to a webserver which listens on HTTP requests on a certain port number, which is usually 80. When a client (user with a webbrowser) sends a HTTP request, the servletcontainer will create new HttpServletRequest and HttpServletResponse objects and pass it through the methods of the already-created Filter and Servlet instances whose url-pattern matches the request URL, all in the same thread.

The request object provides access to all information of the HTTP request, such as the request headers and the request body. The response object provides facility to control and send the HTTP response the way you want, such as setting headers and the body (usually with HTML content from a JSP file). When the HTTP response is committed and finished, then both the request and response objects will be trashed.

request.getParameter("request_param"); will give you request_param value. So there is nothing to get surprise accessing request parameter from request object

Autres conseils

If you're dealing with HttpServletRequest you can use

String restbalance = request.getParameter("restbalance");

or...to get all the parameteres, you can do:

String[] params = request.getParameterValues();

Here's the javadoc for the HttpServletRequest class, with all the available methods listed.

Yes you can use request.getParameter where request is the object of HttpServletRequest.

From the javadocs getParameter

java.lang.String getParameter(java.lang.String name) Returns the value of a request parameter as a String, or null if the parameter does not exist. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data. You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use getParameterValues(java.lang.String).

If you use this method with a multivalued parameter, the value returned is equal to the first value in the array returned by getParameterValues.

If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the body directly via getInputStream() or getReader() can interfere with the execution of this method.

Try getParameterMap()

Map params = request.getParameterMap();
Iterator i = params.keySet().iterator();
while ( i.hasNext() )

{

String key = (String) i.next();

String value = ((String[]) params.get( key ))[ 0 ];

}

Well , request.getparameter() will work fine only if the request hits your Servlet from where you want to get hold of the request parameters . Please go through the documentation ServletRequest interface for all the relevant methods for your purpose.

  1. getParameter();

  2. getParameterNames();

  3. getParameterValues();

  4. getParameterMap();

You can also use HttpServletRequest#getQueryString() for custom parsing.

For normal Java code , you can parse the string returned by URL.getQuery() yourself to extract the data .

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top