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 JSP and the fly likes Can't get parameter from request 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 » JSP
Bookmark "Can Watch "Can New topic
Author

Can't get parameter from request

Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
I'm new to JSPs and just wanted to write a simple login type page. I can't even get the submitted parameters from the request.

Here's what I'm trying:




Everytime I submit, the page loads with null for the user name parameter. I'd really appreciate any insight you could offer.


Fun programming etcetera!
anupa oru
Ranch Hand

Joined: Jan 15, 2005
Posts: 118
Hi,

I believe you have to use name attribute in place of id attribute for <input> element as
<input type="text" name="userName">

I hope this will solve your problem.
Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

You are not doing anything to set the value of your input elements. If you want to preload an element with a value it needs a value attribute.

In your example, something like:



Disclaimer: not that I would do things this way. I would never submit to a JSP -- always to a servlet, and I would favor the JSTL over scriptlet expressions. But that's another show...
[ May 11, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
Disclaimer: not that I would do things this way. I would never submit to a JSP -- always to a servlet


Could you help a newbie out and let me know why it is a bad idea to submit to a JSP?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

In (at least what I would consider) a properly achitected web application, JSPs serve as presentation mechansims only. They perform no processing of their own except what is necessary for "display support". Such a pattern is frequently refered to as "Model 2" or "MVC" or even "n-tiered". There has been much written on these subjects.

Inherently, when submitting a form, processing of the form data occurs. Such processing is inappropriate for a JSP in a web app following this pattern.

In fact, especially if you are using a JSP 2.0 container, it's better to write what have become termed "scriptless" JSP pages. That is: pages that contain no java. No scriptlets, no declarations, no scriptlet expressions. Rather, these pages rely upon the EL (Expression Language), JSTL (JSP Standard Tag Library), JSP actions, and custom actions (formerly known as "custom tags") to perform their jobs.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't get parameter from request
 
Similar Threads
authentication in jboss
javax. servlet. Servlet Exception: java. sql. SQLException
How to send Parameters from JSP to a Servlet?
Struts IE render problem
datas storing twice from servlet to mysql database