15,000 Jobs Available in:
Java, ASP, C#, PHP, SQL, SAP, MySQL and many more.
- Class Quick -
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
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply 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.

This message was edited 1 time. Last update was at by Bear Bibeault

Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 48842

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.

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 48842

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: 462

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.
 
 
subject: Not able to pass Form parameters from jsp to servlet
 
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture