Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Not able to pass Form parameters from jsp to servlet

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am learning Servlets and JSP. I have tried following example.

MyJsp page:-

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="GET" action="/TestServlet2">
User Name:<input type="text" name="username"><br>
Pass Word:<input type="text" name="password"><br>
<input align="middle" type="button" value="Submit">
</form>
</body>
</html>

ServletCode:-
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String username=request.getParameter("username");
String password=request.getParameter("password");
out.println(username);
out.println("<br>");
out.println(password);
}

Web.xml:-
<servlet>
<description></description>
<display-name>TestServlet2</display-name>
<servlet-name>TestServlet2</servlet-name>
<servlet-class>org.baba.prakash.TestServlet2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet2</servlet-name>
<url-pattern>/TestServlet2</url-pattern>
</servlet-mapping>

I tried running this code.But i am not able to print username and password.I tried all other examples.But did not work for me.Please help me to resolve the issue. I am able to see login page with User name and password. But when i click on Submit button i am not seeing any response.
 
Sheriff
Posts: 67592
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.
 
Bear Bibeault
Sheriff
Posts: 67592
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is happening?
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check that you are using button , it wont submit the form ..... you need to use in <code> < input type="submit" value="Submit Form"> </code> ...... then tell me whats the problem you are facing....
 
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Baba prakash wrote:Hi all,
I am learning Servlets and JSP. I have tried following example.

MyJsp page:-

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="GET" action="/TestServlet2">
User Name:<input type="text" name="username"><br>
Pass Word:<input type="text" name="password"><br>
<input align="middle" type="button" value="Submit">
</form>
</body>
</html>

ServletCode:-
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String username=request.getParameter("username");
String password=request.getParameter("password");
out.println(username);
out.println("<br>");
out.println(password);
}

Web.xml:-
<servlet>
<description></description>
<display-name>TestServlet2</display-name>
<servlet-name>TestServlet2</servlet-name>
<servlet-class>org.baba.prakash.TestServlet2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet2</servlet-name>
<url-pattern>/TestServlet2</url-pattern>
</servlet-mapping>

I tried running this code.But i am not able to print username and password.I tried all other examples.But did not work for me.Please help me to resolve the issue. I am able to see login page with User name and password. But when i click on Submit button i am not seeing any response.




As i see there is no submitting button the submitting button should looks like this : in your code there is only a normal button not a submitting button ...
 
Baba prakash
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your replies.
I realised my mistake.

I changed the form.Now it is working fine for me.
 
reply
    Bookmark Topic Watch Topic
  • New Topic