Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 657343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:48:47+00:00 2026-05-13T22:48:47+00:00

I have a DLPUser object in my session, this DLPUser is basically a container

  • 0

I have a DLPUser object in my session, this DLPUser is basically a container for Strings, ints and some useful info for me.

(this is a fragment of code inside my action class in java)

Map <String, Object> session = ActionContext.getContext().getSession();
session.put("logged-in","true");
session.put("user", user); //user is DLPUser user = new DLPUser();

Now I want to show the value of user.getName(); inside a textField in some JSP
How can I do this?
I am working with Struts tag and the following didn’t work.

<s:textfield label="Name" name="name" value="<% session.user.getName(); %>"/>

or

<s:textfield label="Name" name="name" value="#session.user.getName"/>

This is supposed to be simple… but I am stuck and cannot find a good reference about this thing in struts and jsp.
Any Help is very appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:48:48+00:00Added an answer on May 13, 2026 at 10:48 pm

    I was learning how to do this myself, and this discussion was helpful. This, combined from material from various webpages and the book "Struts 2 in Action" got me to where I needed to be.

    Nate’s and nacho4d’s answers are close to the mark. Here is what I did:

    Required imports:

    import java.util.Map;
    import com.opensymphony.xwork2.ActionSupport;
    import org.apache.struts2.interceptor.SessionAware;
    

    My action class ("User") declaration:

    public class User extends ActionSupport implements SessionAware {
    

    My session variable is a data member of User:

    Map <String, Object> session;
    

    Then, in my method that authenticates the user (note that UserModel is simple class of just data members and their getter/setters)

    UserModel user;
    ...
    session.put("User", user);
    

    Finally, in my jsp file:

                <s:if test="%{#session.User.isLoggedIn()}">
                    Welcome back, <s:property value="%{#session.User.firstName}" />
                    <s:property value="%{#session.User.middleName}" />
                    <s:property value="%{#session.User.lastName}" />!
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="Logout.action">Logout</a>
                </s:if>
    

    Notice the syntax of accessing the session objects methods/data members. Although I’ve not read it detailed somewhere, I’m guessing that:

    • %{} tells jsp to evaluate the expression inside the {}
    • session gets you access to the session stack/object?

    And from there, the result is normal dot operators for accessing objects and their methods/members.

    I’m a novice at this, but it also seems like it doesn’t matter if the UserModel’s data members are private, the JSP can access them anyway.

    Oh. One last bit, to make it "complete", how about logging out? My java for the logout action:

    public String logoutUser()
    {
        session.remove("User");
        return SUCCESS;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
Have converted devise new session from erb to Haml but doens't work, this is
This post is an continuation of this post I have DlUser Class each object
Have some code: using (var ctx = new testDataContext()) { var options = new
have a php code like this,going to convert it in to C#. function isValid($n){
Have some dates in my local Oracle 11g database that are in this format:
Have this code: <sj:head compressed=false jqueryui=true jquerytheme=custom/> <s:url id=link action=ABC namespace=/DEF escapeAmp=false/> <sj:a openDialog=_dialog
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
have anyone can tell me what syntax error on this actionscript (actionscript3.0)? var rotY:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.