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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:41:29+00:00 2026-05-18T04:41:29+00:00

Im made a sort of autentication on my web application using GWT. So i

  • 0

Im made a sort of autentication on my web application using GWT. So i make these functions in the GWTServiceImpl Class :

public class PageMenuLogin extends FlowPanel {
    public PageMenuLogin() {
        PageMenuLogin.getService().isSetSession(new AsyncCallback<String>() {
            @Override
            public void onFailure(Throwable caught) {
                InlineLabel err=new InlineLabel();
                err.setText("Errore Di Connessione");
                PageMenuLogin.this.add(err);
            }

            @Override
            public void onSuccess(String result) {
                if(result.compareTo("")==0) {
                    designLogin();
                } else {
                    designLogout(result);
                }
            }
        });
    }

    public final void designLogin() {
        final InlineLabel menu_err=new InlineLabel("");
        menu_err.setStyleName("menu_err");
        this.add(menu_err);        

        Button menu_login_button=new Button("Login");
        this.add(menu_login_button);

        menu_login_button.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                getService().checkLogin("nickname", "password", new AsyncCallback<Boolean>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        menu_err.setText("Comunicazione Fallita");
                    }

                    @Override
                    public void onSuccess(Boolean result) {
                        if (result) {
                            // I LOAD THE PROFILE PAGE
                        } else {
                            menu_err.setText("Username e password non validi");
                        }
                    }
                });
            }
        });
    }
}

********************************************************************************

public class GWTServiceImpl extends RemoteServiceServlet implements GWTService {
    HttpServletRequest request;
    HttpSession session;
    public String isSetSession() {
        this.request = this.getThreadLocalRequest();
        this.session=this.request.getSession();

        if(this.session.getAttribute("nickname")==null) {
            return "";
        } else {
            return (String)this.session.getAttribute("nickname");
        }
    }

    public boolean checkLogin(String username, String password) {
        if("i check on the database if the user exist") {
            this.session.setAttribute("nickname", value);
            return true;
        } 

        return false;
    }
}

On client side, i call the GWTServiceImpl functions (server side), i check the return values and i do some operations.

Is this the right way to work with session on GWT? Any suggestion/tips/helps would be appreciated 🙂

Thanks for your time!!!

EDIT

New GWTServiceImpl :

public class GWTServiceImpl extends RemoteServiceServlet implements GWTService {

    HttpSession session;

    public String isSetSession() {
        HttpSession session=getThreadLocalRequest().getSession();
        if(session.getAttribute("nickname")==null) {
            return "";
        } else {
            return (String)session.getAttribute("nickname");
        }
    }

    public boolean checkLogin(String nickname, String password) {
        HttpSession session=getThreadLocalRequest().getSession();
        Database mydb=Configuration.getDatabase();
        mydb.connetti();

        // faccio md5 ed escape
        String log_check_user=nickname;
        String log_check_pass=password;

        // controllo che l'utente esista
        ArrayList<String[]> db_result=null;
        db_result=mydb.selectQuery("SELECT nickname FROM users WHERE  nickname='"+log_check_user+"' AND password='"+log_check_pass+"'");
        mydb.disconnetti();
        if(!db_result.isEmpty()) {
            session.setAttribute("nickname", nickname);
            return true;
        }

        return false;
    }

    public boolean checkLogout() {
        HttpSession session=getThreadLocalRequest().getSession();
        session.invalidate();
        return true;
    }
}
  • 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-18T04:41:30+00:00Added an answer on May 18, 2026 at 4:41 am

    Looks like it should work. I do a lot of work with GWT, although I often forego the use of the RemoteServiceServlet in favour of passing data back and forth via JSON.

    A few suggestions, though. When you’re calling a method or field within the same class, you don’t need to include the this keyword. It doesn’t hurt, but tends to make your code longer than it needs to be. Feel free to keep it though, if you find it makes things clearer for you.

    Also, unless you’ve got methods that actually use the request, you don’t need to create the request object; you can just do

    session = getThreadLocalRequest().getSession();

    A final suggestion: Since you’re using the session in more than one method, it might be a good idea to initialize it right away; So, instead of initializing it in isSetSession(), you could just write HttpSession session = getThreadLocalRequest().getSession();, or initialize it in the class’s constructor. As it stands now, if you happen to call checkLogin() before isSetSession(), you’ll get a NullPointerException since session hasn’t yet been initialized.

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

Sidebar

Related Questions

I made an universal binary and didn't implement any sort of device orientation rotation.
I made a windows app and I need to add a sort by selected
I am trying to sort a static grid (made from HTML table) to sort
I have made an SQL query that picks out web statistics from a database.
i know insertion sort isn't that great...but even still...what are two more simple improvements
ive made a button in the scene 1 which i have managed to navigate
I made a simple db with a few users in it with mongodb and
I've made a Vaadin table which contains (apart from Strings) a button (with a
I've got a function that goes through an array of objects, and creates a

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.