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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:41:46+00:00 2026-05-19T17:41:46+00:00

I am using Ajax in a jsp page wherein we have a form of

  • 0

I am using Ajax in a jsp page wherein we have a form of filling with Username and Password. I am able to retrieve them in the same page. But while passing it to a Servlet i.e. Admin.java file both username and password are not been passed.

Code:

function prepareLoginDialog(){
        $dialog = $('<div></div>')
        .html('<div id="dialog-confirm" title="Enter the login details here :">'+
            'User: <input type="text" id="u" name="u" ></input><br />'+
            'Pass: <input type="password" id="p" name="p" ></input>'+
            '</div>')

            //System.out.println(user);
        //System.out.println(pass);
        .dialog({
            autoOpen: false,
            modal: true,
            title: 'Login',
            buttons: {
                'Login': function() {
                    //Send Login Request to Server
                    var user = document.getElementById("u").value;
                    var pass = document.getElementById("p").value;
                    alert(user);
                    alert(pass);
                    //System.out.println(u.text);
                    login(user,pass);

                    $(this).dialog('close');
                },
                Cancel: function() {
                    $(this).dialog('close');
                }
            }

The Login Function is:

function login(user, pass) {
        //ToDo: User Login check
        alert(user);

        $.ajax({
            type:"GET",
            url: "Admin?action=login",
            dataType: "html",
            data: { username: user, password: pass },
            success: function(response){
                prepareLogoutDialog();
                prepareLoggedIn();
            }
        });

In the Java file it is

request.getSession().setAttribute("access", true);
            System.out.println("Admin:doGet:login:true");
            System.out.println("u");
            String userName = request.getParameter("u");

            String password = request.getParameter("p");
            System.out.println(userName);
            System.out.println(password);

Not getting printed.
Do I need to convert the username and password to string before passing? If so how do we do that?

Please help.

  • 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-19T17:41:46+00:00Added an answer on May 19, 2026 at 5:41 pm

    You expect them as request parameters u and p, you should thus also pass them as such:

    data: { u: user, p: pass },
    

    or change your servlet to retrieve them with the given names in data {}

    String userName = request.getParameter("username");
    String password = request.getParameter("password");
    

    On the other hand, the System.out.println() prints to the stdout (which end up in logfile), not to the HTTP response. If you expect them in the response, so that it’s available as content of response in function(response), then you need to print to the HTTP response.

    response.setContentType("text/plain;charset=UTF-8");
    PrintWriter writer = response.getWriter();
    writer.println(userName);
    writer.println(password);
    

    Related questions:

    • Update current page with a servlet
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jsp page which should load a popup using ajax. The content
I'm using Struts2+Hibernate. I have a form in a JSP page, in which there
I am using ajax in my jsp page to get all the values from
I am Calling a jsp(which is in another tomcat) using ajax function.But i am
I have a JSP page with a form. When I submit the form, it
I am developing application using Ajax and jsp. My index.jsp page has HTML code
I'm using AJAX to get data for several business-card like divs on my page
I am using AJAX to send form data to a server php file that
I am using Ajax tab container control with 3 tabs. I have placed a
I have a JSP page that renders a block of HTML. In normal usage,

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.