Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is an another way of getting the form parametrs from jsps?

 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yesterday I faced an interview question which I couldn't answer-

"apart from the getParameter() method for getting the form parameters from the jsps what is an another way of doing it?"

Does anybody know here?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the other methods of (Http)ServletRequest, and you'll see.
 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Check the other methods of (Http)ServletRequest, and you'll see.


Thank you Ulf.

This is now the lack of understanding here .
Even though I knew the answer I couldnt understand what exactly he was expecting from me.
I would have been able to give the answer indeed if he would have asked me for other methods in the HttpServletRequest .

I guess this happened with me as I've not come across the other ones frequently. Or what else?

Anyways thanks Ulf for getting the thing clear .
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even though I knew the answer I couldnt understand what exactly he was expecting from me.

It's perfectly fine to ask for clarification if a question is not completely clear. Of course, the interviewer won't tell you what, exactly, *he* expects to hear, since that's for *you* to say :-)

I would have been able to give the answer indeed if he would have asked me for other methods in the HttpServletRequest.

That would not have been a good interview question (not that the one that did get asked is all that great, either). Knowing by heart all methods in a class is not a tremendously useful skill if I can just look up the javadocs in 10 seconds.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not that the one that did get asked is all that great, either


++. I was about to say that.

I was firstly a little bewildered with the question. Another form of input like headers / cookies / inputstreams / inputReaders ? Another method to get parameters ?

If a question is not clear, follow it up with the interviewer and narrow it down.
 
Evan Caballero
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And so, what is the final answer to the original question ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a poor question, but I suspect that the interviewer was fishing for getParameterMap() and its ilk.
 
Mike Kaufman
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way, if the form uses "POST", would be to use the request's input stream to read the posted data directly from the request's body content, and then parse it into parameter names and values yourself.

You'd need to avoid making any calls to "getParameter" beforehand, as the first such call causes the input stream to be consumed (it retrieves and parses the posted data, and merges it with any request parameters found in the query string - which leaves the input stream already-consumed and at end-of-file).

I can't think off-hand of many situations where this would be worthwhile, but if the request has both posted data and a normal query string this approach does let you access the two sets of parameters entirely separately from each other (even if they both have parameters with the same name) - i.e. retrieve the posted data from the input stream, then use getParameter to retrieve the query string parameters on their own. You could also use this regardless of the request's content type, whereas getParameter only reads posted data if its content type is specifically that expected for posted form data.

At any rate, reading the posted data directly from the input stream is another way to do it, and maybe (just maybe) that's what the interviewer was after.
 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you guys.

Next time I'll beware of asking the question to get clarified:-).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic