Meaningless Drivel is fun!*
The moose likes JSP and the fly likes Can a EL expression pass a value that was entered into a form? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Can a EL expression pass a value that was entered into a form?" Watch "Can a EL expression pass a value that was entered into a form?" New topic
Author

Can a EL expression pass a value that was entered into a form?

John Piper
Greenhorn

Joined: Mar 27, 2011
Posts: 12
After listening to Bear's suggestion I'm tossing my previous code and am trying to write code using JSTL and EL.

What I am trying to accomplish currently is implementing session tracking. I just want to track the username used to login to a form and pass it from page to page as the user navigates the website.

I have a very simple two jsp pages setup to try to figure out how to pass what is input in the username field in the form.

index.jsp


securitycheck.jsp


Is what I'm trying to do possible? And if so, how?

Thanks everyone.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Looking at this code:

Let's see if I can help you answer your own question. Answer these questions:
  • When does the <c:set> get executed?
  • When does the user enter the value into the field?
  • How does this answer your question?


  • [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61433
        
      67

    If you can't answer the questions, read this article and try again.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61433
        
      67

    And (personal pet peeve): name="un". un? Use real words and keep things readable.
    Stefan Evans
    Bartender

    Joined: Jul 06, 2005
    Posts: 1018
    One more tidbit of information that may help.
    EL defines an implicit variable called "param"

    "param" is a map of all the request parameters, keyed by request parameter name.

    ${param.foo} is approximately equivalent to request.getParameter("foo");

    I actually think you're taking Bear a little TOO literally.
    Yes you want to stop scriptlets in the JSP, and use EL.
    But you also want to use Java beans to encapsulate most of your data

    So rather than having a <c:set> on the page I would go with creating a User Bean (java class) and populate that with values from the request parameters.

    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61433
        
      67

    Stefan Evans wrote:
    So rather than having a <c:set> on the page I would go with creating a User Bean (java class) and populate that with values from the request parameters.

    I'd go as far as to say that collecting params isn't something that belongs in a JSP at all. But one thing at a time...
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Can a EL expression pass a value that was entered into a form?