aspose file tools*
The moose likes JSP and the fly likes why doesn't request.getParameter( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "why doesn Watch "why doesn New topic
Author

why doesn't request.getParameter( "j_username" ) work?

Sheldon Plankton
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
Friends,
I am trying to based my content on the user that has logged in.
I am basically using the logon.jsp from the J2EE 1.4 tutorial ...

... and I want to use the value of j_username in this jsp ...

... and here is the HTMl that gets generated ...

I tink that I am not getting anything from the request.getParameter( "j_username" ); call.
What am I doing wrong?
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
Where is the action j_security_check implemented? Is the form submitting to a servlet? How is the 2nd jsp getting displayed? Is the request getting dispatched to the 2nd jsp?
Request object is specific to a request. What is likely happening is that the form is getting submitted & its request is being processed (perhaps in a servlet) & the servlet is displaying the next jsp. The 2nd jsp will not have access to the request object of the 1st jsp unless you forward the request & response objects via the RequestDispatcher.
If you are using a servlet you can do the following:
getServletContext().getRequestDispatcher(urlForJSP).forward(request, response)


Ever Existing, Ever Conscious, Ever-new Bliss
Sheldon Plankton
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
Where is the action j_security_check implemented? Is the form submitting to a servlet? How is the 2nd jsp getting displayed? Is the request getting dispatched to the 2nd jsp?
I don't know ... I am using Tomcat and the J2EE1.4 Application Server I used the "deploytool" to make a WAR file. I tried to ape the example "FormBasedAuthenication" from the J2EE 1.4 Tutorial to create my own formbased logon screen. The example in the Sun tutorial displays the logged on user's username like so ...

Does this mean my jsp should look like this?

Thanks for the reply!
[ February 18, 2004: Message edited by: Sheldon Plankton ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

The getParameter family of methods do not work with multi-part form data.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sheldon Plankton
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
Hi Bear,
Thanks for the reply. Are you saying that I need to change ...

... to ...

...? If make this change will I still be able to upload files?
Thanks!
[ February 18, 2004: Message edited by: Sheldon Plankton ]
[ February 18, 2004: Message edited by: Sheldon Plankton ]
[ February 18, 2004: Message edited by: Sheldon Plankton ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

If make this change will I still be able to upload files?

No. Basically, uploading files and using getParameter are incompatible. To upload a file you need to use a multi-part form, which precludes the use of getParameter. You need to parse the input yourself or use a third party package (like com.oreilly.servlet) that does it for you.
Sheldon Plankton
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
Ah man!
have you ever used Jakarta's FileUpLoad? I guess that's what I'll try next.
Thanks for the info. You jut saved me a lot of wasted time and fustration.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

The 'cos' package is the only one I've personally used. This topic has come up before, so I'd suggest searching this (and the Servlets) forum for more info.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: why doesn't request.getParameter( "j_username" ) work?
 
Similar Threads
Servlet becomming slow
Servlet becomming slow
using jsp:useBean
Invalid directive? outdated directive?
Cannot create InputStream from Properties file