0

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

AzAh
  • 41
  • 1
  • 1
  • 14
  • Do you want to retrieve parameters inside the servlet ? – AllTooSir Jul 30 '13 at 11:48
  • 1
    @AzAh yes you can.Did you try before posting this question? Or is there something else you want to make a not of? – Deepak Ingole Jul 30 '13 at 11:50
  • @captain I tried, damn I was not using it correctly. NOW I am using it with the beans and a method with `HttpServletRequest` parameter which sets all the bean. All the answer was helpful. THANKS – AzAh Aug 01 '13 at 11:17

5 Answers5

1

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.

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
0

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.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • `request` can be an object of any `ServletRequest` not necessarily `HttpServletRequest` . See it is declared in `ServletRequest` interface. – AllTooSir Jul 30 '13 at 11:59
0

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 ];

}
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
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 .

AllTooSir
  • 48,828
  • 16
  • 130
  • 164
0

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

user207421
  • 305,947
  • 44
  • 307
  • 483
Deepak Ingole
  • 14,912
  • 10
  • 47
  • 79