aspose file tools*
The moose likes Servlets and the fly likes Servlet getParameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet getParameter" Watch "Servlet getParameter" New topic
Author

Servlet getParameter

Antonis Papadakis
Greenhorn

Joined: Nov 27, 2006
Posts: 1
Hi everybody,

I am learing java by myself and I am reading about servlets and I have stuck. I have written the following html

<html>
<head>
<title>Select a Stock</title>
</head>
<body>
<form action="http://localhost:8080/servlet/ServLet1" method="GET">
Enter your name: 
<input type=text value=Name>
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

Also I have written the java servlet

public class ServLet1 extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String name = request.getParameter("Name");

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello world!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello world!</h1>");
out.println("<br>");
out.println("<h2>");
out.println("hi 1");
out.println(name);
out.println("</h2>");
out.println("</body>");
out.println("</html>");
}

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

I have install tomcat on windows XP Professional

I call the html with firefox, I type in a name and press the submit button. The html of the servlet is displayed but the getParameter returns NULL. I have checked that the name is correctly written.

Does anybody has an idea why?
Thanks in advance.

Regards

Antonis
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

In your HTML file,

Change this,

<input type=text value=Name>

to this,

<input type=text name="Name" value=Name>


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
Change this,

<input type=text value=Name>

to this,

<input type=text name="Name" value=Name>


Actually, all attributes should be quoted for conformance to the HTML standard and general best results.

<input type="text" name="Name" value="Name">

Bill


Java Resources at www.wbrogden.com
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

without quotes also it will work but yes as per standard of mark up language all the attribute's value should be inside quote.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
try out :

<input type="text" name="Name"/>

try out getParameter("Name")
at the servlet point.
Why do you need to give a value.Well with value also it should work.


Rahul Bhattacharjee
LinkedIn - Blog
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Originally posted by Prabhu venkatachalam:
without quotes also it will work


Yeah its works but not completely.
and finally...


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet getParameter
 
Similar Threads
Progress bar on IE6
Doubt in servlet program using eclipse IDE
Servlet becomming slow
Servlet becomming slow
passing parameters from JSP to a Servlet