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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:58:20+00:00 2026-05-21T16:58:20+00:00

I am trying a simple program with Java Servlet wherein a HTML page with

  • 0

I am trying a simple program with Java Servlet wherein a HTML page with a text box and a submit button will be displayed. Once the user enters the data and submits it, the next page will display a Hello . Calling the servlet URL with the GET parameter directly shows that it works fine. But when I open the HTML file and submit data from there, the GET request isn’t formed properly, i.e. the parameters are not getting passed in the address of the ‘action’ URL.

Here is the HTML code:

<!DOCTYPE html>
<html>
 <head>
  <title>Hello</title>
 </head>
 <body>
  <form action="/TestServlt/TestClass" name="myform" method="get">
    Enter your name: <input type="text name="username">
    <br />
    <input type="submit" value="Go">
  </form>
 </body>
</html>

and the servlet code:

package in.lguruprasad;

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

public class TestClass extends HttpServlet implements Servlet {
static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    PrintWriter output = response.getWriter();
    response.setContentType("text/html");
    String name = request.getParameter("username");
    output.println("Hello "+name+"!");
    output.flush();
    output.close();
}
}

The servlet is mapped to /TestServlt/TestClass URL and the form submit redirects http://localhost:8080/TestServlt/TestClass instead of http://localhost:8080/TestServlt/TestClass?username=<user input> which would work fine. The output I get is ‘Hello null!’.

In all the browsers the form submits without the get parameter. I tried writing a similar doPost method, but that didn’t work as well.

What is the issue here and how to fix it?

I am using Eclipse 3.1.2, Apache Tomcat 5.5, JDK 1.6.25 if that helps.

  • 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-21T16:58:21+00:00Added an answer on May 21, 2026 at 4:58 pm

    You are missing a quote in the html input:

    Enter your name: <input type="text name="username">
    

    should be

    Enter your name: <input type="text" name="username">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement simple program in Java that will be used to
I'm trying to write a simple program in VC++ which will just initialize the
I'm trying to write a simple java applet program, but it seems that I'm
I'm trying to compile a very simple program in Java 1.6 on Ubuntu Jaunty,
I am trying to build a simple java program which creates a db file,
i'm trying to make a simple Java program to open an existing word-document, change
Im trying to create a simple dll file.Im following the tutorial http://java.sun.com/docs/books/jni/html/start.html when i
Just getting back into using C++ and trying to convert a simple Java program
I am trying to create a simple simulation program of SIR-epidemics model in java.
I'm trying to compile a simple program, with #include <gtkmm.h> The path to gtkmm.h

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.