473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

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

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
Sep 14 '07 #1
14 2381
madhoriya22
252 100+
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 ?
Sep 14 '07 #2
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
Sep 14 '07 #3
madhoriya22
252 100+
yes i'm printing in the console also
Hi,
Then what is printing on the console ?
Sep 14 '07 #4
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.
Sep 14 '07 #5
r035198x
13,262 8TB
yes i'm printing in the console also
Which output are you not getting then?
Sep 14 '07 #6
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
Sep 14 '07 #7
Nepomuk
3,112 Expert 2GB
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
Sep 14 '07 #8
r035198x
13,262 8TB
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.
Sep 14 '07 #9
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
Sep 14 '07 #10
madhoriya22
252 100+
i'm not getting any output
hi,
see reply #9 and try what r0 is saying
Sep 14 '07 #11
hi,
see reply #9 and try what r0 is saying

Tried that way also but not able to get the output
Sep 14 '07 #12
r035198x
13,262 8TB
Tried that way also but not able to get the output
Which way? Can you post what you've done.
Sep 14 '07 #13
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.
Sep 19 '07 #14
r035198x
13,262 8TB
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.
Sep 19 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Martin | last post by:
I use dbx and i got the following error: Reading GL_CliConnMgr core file header read successfully Reading ld.so.1 dbx: core file read error: address 0xff3e6000 not available dbx: core file...
1
by: learner | last post by:
Hi, How to find a word is containing only alphabets, numbers, _ and -? Also,It should not start with _ and -? How abt testing with this exp - /^(\w|\d)(\w|\d|-|_)+$/; ?
1
by: SmartGuy | last post by:
hi,all: The whole thing is : My team is developing some activex controls in VB 6.0. As a new comer, i am quite familiar with .Net(c#) than vb 6.0. So can i develop ActiveX controls in c#? And if...
1
by: ambr | last post by:
i made a program for grading true and false test,there are no syntax error but program is not running like it should be itshould give me student's ID followed by the answer,followed by test score...
0
by: iamits | last post by:
Hi, Note : URGENT Can anynone plz tel me when this error comes and what should be done to avoid it? com.ibm.db2.jcc.b.SQLException: The value of input host variable or parameter number "3"...
0
by: reachnaveenkumar | last post by:
Hi there! Do we have editable combo box in JSF? If so I need an editable combo box in which I can add, edit delete a record. If I type starting letters of a name, then it should list all the names...
6
by: ramesh9999 | last post by:
Hi all, I am new to perl and xml ... Can anyone help me out to read an xml file and write it to text file.
2
by: apattin | last post by:
Hi all, I have this table: create table my_table (file_id int not null, property_id int not null, property_value varchar(255)); In some instances the property_value is a string representing...
1
by: vshalpatel | last post by:
EmpNo DeptNO 2001 10 2002 20 2003 30 2004 20 2005 10 2006 30 2007 20 2008 10 2009 30
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.