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

  • Home
  • SEARCH
  • 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 7922055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:49:20+00:00 2026-06-03T16:49:20+00:00

I have a problem in getting the logged in user in my spring-extjs application.I

  • 0

I have a problem in getting the logged in user in my spring-extjs application.I am using spring security 2.0.4.Here are the details of what i have tried.

Controller class:

@RequestMapping(value="/StaffingApplication/index.action", method = RequestMethod.GET)
public String printUser(ModelMap model) {
  Authentication auth = SecurityContextHolder.getContext().getAuthentication();
  String name = auth.getName(); //get logged in username    
  System.out.println(name);
  model.addAttribute("username", name);
  return "index.jsp";
}

login.js file

var login = new Ext.FormPanel({
    labelWidth:80,
    url:'j_spring_security_check',
    frame:true,
    title:'Please Login',
    defaultType:'textfield',
    width:300,
    height:130,
    monitorValid:true,
    // Specific attributes for the text fields for username / password.
    // The "name" attribute defines the name of variables sent to the server.

    items:[{
        fieldLabel:'Username',
        name:'j_username',
        allowBlank:false
    },{
        fieldLabel:'Password',
        name:'j_password',
        inputType:'password',
        allowBlank:false
    }],

    // All the magic happens after the user clicks the button
    buttons:[{
        text:'Login',
        formBind: true,
        // Function that fires when user clicks the button
        handler:function(){
        login.getForm().submit({

            method:'POST', 

            // Functions that fire (success or failure) when the server responds.
            // The server would actually respond with valid JSON,
            // something like: response.write "{ success: true}" or

            // response.write "{ success: false, errors: { reason: 'Login failed. Try again.' }}"
            // depending on the logic contained within your server script.
            // If a success occurs, the user is notified with an alert messagebox,

            // and when they click "OK", they are redirected to whatever page
            // you define as redirect. 

            success:function(){
            Ext.Msg.alert('Status', 'Login Successful!', function(btn, text){
                if (btn == 'ok'){
                      window.location = 'index.action';
                }
            });

        },

        // Failure function, see comment above re: success and failure.
        // You can see here, if login fails, it throws a messagebox
        // at the user telling him / her as much.  


        failure:function(form, action){
            if(action.failureType == 'server'){
                obj = Ext.util.JSON.decode(action.response.responseText);

                Ext.Msg.alert('Login Failed!', obj.errors.reason);
            }else{
                Ext.Msg.alert('Warning!', 'Authentication server is unreachable : ' + action.response.responseText);
                //window.location='loginFailure.html'+action.response.responseText; 
            }
            login.getForm().reset();
        } 

        });
    }
    }]
});

On my jsp page I access it like this.

<div id="header" class="header">Options Staffing Application
    <div style="" id="user-status">
        <a href='<c:url value="j_spring_security_logout"/>'>Logout</a>
        <h3>Username : ${username}</h3>
    </div>
</div>

But I just get a blank in place of username.
When I try to print it in the controller I get the value printed,but doesn’t seem to be displayed on the jsp page.Went throgh other threads but did not help.Any help would be appreciated

Thanks for the time
Sachin

  • 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-06-03T16:49:21+00:00Added an answer on June 3, 2026 at 4:49 pm

    You don’t need to put the username into an object model because you can access it from a jsp just like the way you do in the controller class:

    <h3>Username <%=SecurityContextHolder.getContext().getAuthentication().getName(); =></h3>
    

    Or even better:

    <h3>Username <sec:authentication property="name" /></h3>
    

    But i’m not sure if you can use that taglib in Spring Security 2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem getting a private method using reflection. Even with BindingFlags.NonPublic and
I have a problem with getting a class from an external .jar file. I
I have been trying to get the currently logged-in user's token information using the
I have a problem. When I am using comand as a user in SQLPLUS
I just started a graphical C++ course and I have problem getting an overview
I have a problem getting the right Price for a product based on Effectivity
I have a problem getting boost::multi_index_container work with random-access and with orderd_unique at the
I have this problem getting my newly created php project on Netbeans work on
I have a problem with getting my pager-function to work. For some reason it
I have a problem with getting jquery to retrieve results from a WCF service.

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.