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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:19:25+00:00 2026-05-19T03:19:25+00:00

Passing Parameter to the Java file using Html form I couldn’t run in my

  • 0

Passing Parameter to the Java file using Html form I couldn’t run in my Tomcat server.
Who can describe this example step by step? where shall I put .html file and where .java and . class files. I am attaching html and java file. The compiled file with .class extension I have already done! Thank you in advance!

<html>

<head>
<title>New Page 1</title>
</head>

<body>

<h2>Login</h2>
<p>Please enter your username and password</p>
<form method="GET" action="/htmlform/LoginServlet">
  <p> Username  <input type="text" name="username" size="20"></p>
  <p> Password  <input type="text" name="password" size="20"></p>
  <p><input type="submit" value="Submit" name="B1"></p>
</form>
<p>&nbsp;</p>

</body>

</html>

and this is my LoginServlet.java file:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoginServlet extends HttpServlet{
  public void doGet(HttpServletRequest request, HttpServletResponse response)
                                   throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String name = request.getParameter("username");
    String pass = request.getParameter("password");
    out.println("<html>");
    out.println("<body>");
    out.println("Thanks  Mr." + "  " + name + "  " + "for visiting roseindia<br>" );
    out.println("Now you can see your password : " + "  " + pass + "<br>");
    out.println("</body></html>");
  }
}
  • 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-19T03:19:26+00:00Added an answer on May 19, 2026 at 3:19 am

    The HTML file has to go in public webcontent and the class file has to go in /WEB-INF/classes in the right folder structure which conforms the class’ package declaration. Also don’t forget to declare the servlet in /WEB-INF/web.xml.

    As to the HTML form, you need to realize that a leading slash / in the URL will bring you to domain root. So effectively your form submits to http://localhost:8080/htmlform/LoginServlet. You need to ensure that the webapp context path is indeed named /htmlform and that the Servlet is in web.xml been mapped on an url-pattern of /LoginServlet.

    See also:

    • About Servlets – Contains a Hello World example and several useful tutorial/resource links.

    Unrelated to the problem, Roseindia.net is considered the worst learning/example source. Relatively a lot of snippets over there are cluttered by bad practices. I’d suggest to ignore that list as long as you’re new.

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

Sidebar

Related Questions

I'm implementing some code using the java.util.concurrency framework. I will be passing a collection
I'm passing raw HTTP requests to an apache server (received by PHP). The request
When you're passing variables through your site using GET requests, do you validate (regular
I wonder if anyone can advise on a Java webapp question? I have a
I'm working on a web application written in Java using the Tapestry 5.1.0.5 framework.
I am confused in the following: In C++ we can pass a parameter to
I want to ask about the passing parameter in objective C on iPhone simulator.
According to the java docs of PreparedStatement.setNull: Note: You must specify the parameter's SQL
I have a java RMI app that I want to port to using CORBA.
I'm looking for a little help on programmatically passing parameters to a SSRS report

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.