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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:35:32+00:00 2026-05-18T09:35:32+00:00

I have tried a program where if username matches password, welcome message should be

  • 0

I have tried a program where if username matches password, welcome message should be displayed in someother page. If it doesn,t match error should be in the same page. I have tried this

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class WelcomeUser extends HttpServlet {
    public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String name=request.getParameter("name");
        String pwd=request.getParameter("pwd");
        response.setContentType("text/html");
        PrintWriter out=response.getWriter();

        if (!(name.equals(pwd))) {
            out.println("Invalid");
            request.getRequestDispatcher("login.html").forward(request,response);
        } else {
            out.println("<html>");
            out.println("<body>");
            out.println("Welcome"+name);
            out.println("</html>");
            out.println("</body>");
        }
    }
}

What change should I make to print invalid user in the same page? It compiles fine but I am not getting invalid in the login page

  • 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-18T09:35:32+00:00Added an answer on May 18, 2026 at 9:35 am

    Don’t ever use out.print for HTML in a servlet. There the JSP is for. Set it as request attribute and just let JSP display it with help of EL.

    request.setAttribute("message", "Invalid"); // Will be available as ${message}
    request.getRequestDispatcher("login.jsp").forward(request,response);
    

    Rename login.html to login.jsp and add the following somewhere next to the submit button.

    ${message}
    

    See also:

    • Servlets tag info page – contains hello world example and several useful links.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried the following program for writing the contents into Spreadsheet. I downloaded
I have tried to write my first Boost program from information on the Boost
I tried implementing a sorting program in mapreduce such that I have just the
I have compiled an Ada program on Ubuntu using GNAT. Afterwards, I tried a
I have tried to use the program described here Problems in deleting a Folder
In a Ruby program I have a password that is a Base64 string and
I have a program in which the user enters a username and a date
I have a program that tries to shrink a double down to a desired
I have written an ActionScript client program that tries to connect to a local
Have tried to find solutions for this and can't really come up with anything.

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.