• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to pass Form parameters from jsp to servlet

 
Baba prakash
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is happening?
 
adil qureshi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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....
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for your replies.
I realised my mistake.

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