GeeCON Prague 2014*
The moose likes Servlets and the fly likes Not able to pass Form parameters from jsp to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Not able to pass Form parameters from jsp to servlet" Watch "Not able to pass Form parameters from jsp to servlet" New topic
Author

Not able to pass Form parameters from jsp to servlet

Baba prakash
Greenhorn

Joined: Jan 14, 2010
Posts: 5
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

Joined: Jan 10, 2002
Posts: 61315
    
  66

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

What is happening?
adil qureshi
Ranch Hand

Joined: Jul 11, 2008
Posts: 48
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....


SCJP 1.5,SCWCD 1.5
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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 ...


Thanks,
Sherif
Baba prakash
Greenhorn

Joined: Jan 14, 2010
Posts: 5
Thanks for your replies.
I realised my mistake.

I changed the form.Now it is working fine for me.
 
GeeCON Prague 2014
 
subject: Not able to pass Form parameters from jsp to servlet