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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:40:58+00:00 2026-06-05T17:40:58+00:00

I am trying to implement a simple login servlet but it’s not working properly.

  • 0

I am trying to implement a simple login servlet but it’s not working properly.

What I wanted to know is how to pass the parameters using a HTTP POST. It already works with HTTP GET but the username and password are visible from the URL. It would be better to hide them in a POST.

<form method="post" action="home" >
  <input name="username" class="form-login" title="Username" value="" size="30" maxlength="2048" />
  <input name="password" type="password" class="form-login" title="Password" value="" size="30" maxlength="2048" />
  <input type="submit" value="Connect">
</form>

web.xml

  <servlet>
    <servlet-name>home</servlet-name>
    <servlet-class>controller.HomeController</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>home</servlet-name>
    <url-pattern>/home</url-pattern>
  </servlet-mapping>

Servlet:

public class HomeController extends HttpServlet {

    private HttpSession session;
    private UserBean userBean;

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

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

        user.setUsername(userName);
        user.setPassword(password);

        user = UserDAO.login(user);

        dispatch(request, response, ApplicationRessource.getInstance().getHomePage());
    }

    protected void dispatch(HttpServletRequest request,
                HttpServletResponse response, String page)
            throws javax.servlet.ServletException, java.io.IOException {
        RequestDispatcher dispatcher = getServletContext()
                .getRequestDispatcher(page);
        dispatcher.forward(request, response);
    }
}

The problem is that the userName and password strings are always empty, meaning that the parameters are never fetched from the POST. What am I doing wrong?

  • 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-05T17:40:59+00:00Added an answer on June 5, 2026 at 5:40 pm

    it should work, can you check by changing form method to get and trying, you should see parameters in url.

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

Sidebar

Related Questions

Iam trying to implement a simple JMS(traditional not using springs) code in eclipse using
I'm trying to implement a simple login system in Rails, but when I try
I've been trying to implement simple low level keyhook using JNI and all went
I am trying to implement a simple request to Wikipedia's API using AJAX (XMLHttpRequest).
I am trying to implement a simple Observer pattern using .net Observable class. I
I'm trying to implement a simple form-based login for my web application deployed with
I'm trying to implement a simple jabber messenger on Android using asmack library. Here's
I am trying to implement simple login and logout mechanism. When the user logs
I tried to implement a simple login system with Mongodb and Node.js, but I
I've been trying to implement simple (I think) thing in my app. I thought

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.