• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

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

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 382
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Sheldon Plankton
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Marshal
Posts: 67389
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The getParameter family of methods do not work with multi-part form data.
 
Sheldon Plankton
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 67389
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 67389
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic