Connecting Tech Pros Worldwide Forums | Help | Site Map

Urgent:Can anyone tell me where i'm worng in this servlet program

Member
 
Join Date: Jul 2007
Posts: 55
#1: Sep 14 '07
Hi All,

I have the following code for form and servlet. when the form is submitted the servlet will print the values passed by the form. i'm not getting the servlet o/p when i submit the form.here is my code:(simple code just for testing i did this program)

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  5. <title>Insert title here</title>
  6. </head>
  7. <body>
  8. <form name="login" method="POST" action="/servlet/LoginServlet">
  9. UserName<input type="text" name="username"/>
  10. Password<input type="password" name="pwd"/>
  11. <input type="button" value="Submit"/>
  12. </form>
  13. </body>
  14. </html>
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. import java.io.IOException;
  22. import java.io.PrintWriter;
  23.  
  24. import javax.servlet.ServletException;
  25. import javax.servlet.http.HttpServletRequest;
  26. import javax.servlet.http.HttpServletResponse;
  27.  
  28. /**
  29.  * Servlet implementation class for Servlet: LoginServlet
  30.  *
  31.  */
  32.  public class LoginServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
  33.     /* (non-Java-doc)
  34.      * @see javax.servlet.http.HttpServlet#HttpServlet()
  35.      */
  36.     public LoginServlet() {
  37.         super();
  38.     }       
  39.  
  40.     /* (non-Java-doc)
  41.      * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  42.      */
  43.     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  44.         // TODO Auto-generated method stub
  45.         System.out.println("in the login method");
  46.         PrintWriter out = response.getWriter();
  47.         out.println("Came to the login page");
  48.         String name = request.getParameter("username");
  49.         String password = request.getParameter("pwd");
  50.         out.println("name is:" +name);
  51.         out.println("pwd is:" +password);
  52.         System.out.println("name is:" +name);
  53.         System.out.println("password is:" +password);
  54.  
  55.     }      
  56.  
  57.     /* (non-Java-doc)
  58.      * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  59.      */
  60.     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  61.         // TODO Auto-generated method stub
  62.     }                 
  63. }
  64.  
  65.  
I'm accessing the user.html(which has form) using http://localhost:8080/User/user.html. where User is the folder name which contains the html and servlet program.

The url pattern defined as <url-pattern>/LoginServlet</url-pattern> in web.xml for the servlet

madhoriya22's Avatar
Familiar Sight
 
Join Date: Jul 2007
Location: India
Posts: 254
#2: Sep 14 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Hi,

What these two lines ...
Expand|Select|Wrap|Line Numbers
  1. System.out.println("name is:" +name);
  2. System.out.println("password is:" +password);
  3.  
printing on the console ?
Member
 
Join Date: Jul 2007
Posts: 55
#3: Sep 14 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Quote:

Originally Posted by madhoriya22

Hi,

What these two lines ...

Expand|Select|Wrap|Line Numbers
  1. System.out.println("name is:" +name);
  2. System.out.println("password is:" +password);
  3.  
printing on the console ?

yes i'm printing in the console also
madhoriya22's Avatar
Familiar Sight
 
Join Date: Jul 2007
Location: India
Posts: 254
#4: Sep 14 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Quote:

Originally Posted by ramadeviirrigireddy

yes i'm printing in the console also

Hi,
Then what is printing on the console ?
Member
 
Join Date: Apr 2007
Posts: 41
#5: Sep 14 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Quote:

Originally Posted by ramadeviirrigireddy

yes i'm printing in the console also

Hi,

One concern u r extending the HttpServlet class so u need not to implement Servlet interface again as because HttpServlet class is implementing the Servlet interface.


Regards,
Sateesh.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#6: Sep 14 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Quote:

Originally Posted by ramadeviirrigireddy

yes i'm printing in the console also

Which output are you not getting then?
Member
 
Join Date: Jul 2007
Posts: 55
#7: Sep 14 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Quote:

Originally Posted by r035198x

Which output are you not getting then?


when i submitted the form i'm not able to see the name and password values neither in the console nor in the html page
Nepomuk's Avatar
Moderator
 
Join Date: Aug 2007
Location: Germany
Posts: 2,466
#8: Sep 14 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Quote:

Originally Posted by ramadeviirrigireddy

when i submitted the form i'm not able to see the name and password values neither in the console nor in the html page

So the output of
Expand|Select|Wrap|Line Numbers
  1. System.out.println("name is:" +name);
  2. System.out.println("password is:" +password);
  3.  
is
Expand|Select|Wrap|Line Numbers
  1. name is:
  2. password is:
  3.  
(Without adding the values for name and password.) Is that correct? Or do you get no output at all?

Greetings,
Nepomuk
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#9: Sep 14 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Quote:

Originally Posted by ramadeviirrigireddy

when i submitted the form i'm not able to see the name and password values neither in the console nor in the html page

Your form submit method is "post" but you have overriden the doGet method.

Note that if you override the service method instead, then your code will be executed whether the form uses get or post.
Member
 
Join Date: Jul 2007
Posts: 55
#10: Sep 14 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Quote:

Originally Posted by nepomuk

So the output of

Expand|Select|Wrap|Line Numbers
  1. System.out.println("name is:" +name);
  2. System.out.println("password is:" +password);
  3.  
is
Expand|Select|Wrap|Line Numbers
  1. name is:
  2. password is:
  3.  
(Without adding the values for name and password.) Is that correct? Or do you get no output at all?

Greetings,
Nepomuk

i'm not getting any output
madhoriya22's Avatar
Familiar Sight
 
Join Date: Jul 2007
Location: India
Posts: 254
#11: Sep 14 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Quote:

Originally Posted by ramadeviirrigireddy

i'm not getting any output

hi,
see reply #9 and try what r0 is saying
Member
 
Join Date: Jul 2007
Posts: 55
#12: Sep 14 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Quote:

Originally Posted by madhoriya22

hi,
see reply #9 and try what r0 is saying


Tried that way also but not able to get the output
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#13: Sep 14 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Quote:

Originally Posted by ramadeviirrigireddy

Tried that way also but not able to get the output

Which way? Can you post what you've done.
Member
 
Join Date: Jul 2007
Posts: 55
#14: Sep 19 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Quote:

Originally Posted by r035198x

Which way? Can you post what you've done.

Sorry as i was busy i have'nt checked your reply.

in the reply #9 it's mentioned like "Your form submit method is "post" but you have overriden the doGet method.
Note that if you override the service method instead, then your code will be executed whether the form uses get or post." by you. So i have modified my code and checked but even then when i submit the form with values they are not getting displayed in the console nor in the html page.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#15: Sep 19 '07

re: Urgent:Can anyone tell me where i'm worng in this servlet program


Quote:

Originally Posted by ramadeviirrigireddy

Sorry as i was busy i have'nt checked your reply.

in the reply #9 it's mentioned like "Your form submit method is "post" but you have overriden the doGet method.
Note that if you override the service method instead, then your code will be executed whether the form uses get or post." by you. So i have modified my code and checked but even then when i submit the form with values they are not getting displayed in the console nor in the html page.

I also asked you to post the changes you've made. Did you rebuild the application after those changes?
Also make sure that your servlet path is correct.
Reply