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 9155417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:35:18+00:00 2026-06-17T12:35:18+00:00

Suppose we have this code for login & we want if the credential was

  • 0

Suppose we have this code for login & we want if the credential was for admin page the RequestMapping be for admin & if it was for user credential the user redirect to user panel.
now, the main page of both oppose the same url as I defined in my code below, something like :

http://localhost:8080/project/{username}/main

my question is :

how we can separate these two method in here when they have the same RequestMapping “main” after the login checking finished inside the Controller class?

@RequestMapping(value = "/login")
public String welcome(@RequestParam("j_username") String username, @RequestParam("j_password") String password, HttpSession session, Model model) throws RemoteException, NotBoundException {

    int checkAccount = uiClient.checkAdminAccount(username, password);
    if (checkAccount == 1) {
        session.setAttribute("username", username);
        return "redirect:/" + username + "/main";
    } else if (checkAccount == 0) {
        checkAccount = uiClient.checkAccount(username, password);
        if (checkAccount == 1) {
            session.setAttribute("username", username);
            return "redirect:/" + username + "/main";
        } else if (checkAccount == 0) {
            return "login";
        }
    } else {
        return "databaseError";
    }
    return "login";
}

@RequestMapping(value = "/{username}/main")
public String indexPage(@PathVariable("username") String username) {
    return "/user/userPanel";
}

@RequestMapping(value = "{username}/main")
public String adminIndexPage(@PathVariable("username") String username){
    return "/admin/adminPanel";
}

I mean, is there any way like special tag or something that we can put for each Mapping & separate them after the login process finished so the admin redirect to adminPanel & the user also redirect to userPanel but both with the same url:

http://localhost:8080/project/{username}/main

???

  • 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-17T12:35:19+00:00Added an answer on June 17, 2026 at 12:35 pm

    What about this way:

    @RequestMapping(value = "/login")
    public String welcome(@RequestParam("j_username") String username, @RequestParam("j_password") String password, HttpSession session, Model model) throws RemoteException, NotBoundException {
    
        int checkAccount = uiClient.checkAdminAccount(username, password);
        if (checkAccount == 1) {
            session.setAttribute("username", username);
            session.setAttribute("userrole", "Admin");
            return "redirect:/" + username + "/main";
        } else if (checkAccount == 0) {
            checkAccount = uiClient.checkAccount(username, password);
            if (checkAccount == 1) {
                session.setAttribute("username", username);
                session.setAttribute("userrole", "Admin");
                return "redirect:/" + username + "/main";
            } else if (checkAccount == 0) {
                return "login";
            }
        } else {
            return "databaseError";
        }
        return "login";
    }
    
    @RequestMapping(value = "/{username}/main")
    public String indexPage(@PathVariable("username") String username) {
        if ("Admin".equals(session.getAttribute("userrole"))) {
            return "/admin/adminPanel";
        } else {
            return "/user/userPanel";
        }
    }
    

    For simplicity, I didn’t use Spring Security to check user role here.

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

Sidebar

Related Questions

Suppose I have this code: String encoding = UTF-16; String text = [Hello StackOverflow];
Suppose I have this jQuery code. $(document).delegate('a[title]', 'click', function(event) { var txt = //
I have this code that suppose to place the marker by the latlng public
Suppose I have this (C++ or maybe C) code: vector<int> my_vector; for (int i
Suppose we have this example: http://techdroid.kbeanie.com/2009/07/custom-listview-for-android.html with source code available here: http://code.google.com/p/myandroidwidgets/source/browse/trunk/Phonebook/src/com/abeanie/ How can
Suppose I have the code like this: <table> <tr> <th>name</td> <th>price</td> </tr> <tr> <td>a</td>
Suppose, I have a connected socket after writing this code.. if ((sd = accept(socket_d,
Suppose, I have saved some permissions in the database by using this code: RoleRepository
Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
Possible Duplicate: How secure is a HTTP POST? Suppose I have a login page

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.