This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am trying to create a login page asking user for username and password, once submitted i am passing this info to servlet which will connect to database and check if login id and password is correct or not... here is my servlet code:
I know i should be using post instead of get ...but i was having some problem in using that that i ll resolve later... as of now now my problem is that the above code is conneccting to database but not giving the desired output... ie if i remove line
" if (username.equals(rs.getString("name"))) "
(in while statement) it is giving names of all users in database ... but no output otherwise... please help...
How do you expect the above query to execute? It should be
arjita mahajan wrote:
But now it is showing no output not even this line is executing (line no 29)
"p.println("<b><h1>hello before while "+user+"</h1>");"
In your code, line no.29, doesn't show this.. Have you posted the correct code?
Also, initially, variable flag is set to 0, and where is this flag assigned a new value like 1 or any other value? what's the use of checking if(flag==0) when the flag is not at all set after its initialized to 0? Its always going to be true..
arjita mahajan wrote:
This also is not a recommended approach, use e. printStackTrace(); this gives very useful information about exceptions, why just take out message, when we can get a detailed cause of the exception..
P:S: Accessing Database from servlet? not at all a good idea/design, also, emitting HTML tags from servlet also is not a good idea, you should use JSP's for this.
If you have started learning now, start with good practices
Joined: Nov 10, 2012
thank you all for help, my problem is solved.
P.S: yes , its true that i am new to advance java, i didn't get the reason to use jsp when during compilation it is converted to servlet (what i have read) and web container can get response through servlets only. I am suppose to create a website using java, any help is appreciated , thanks in advance
arjita mahajan wrote:i didn't get the reason to use jsp when during compilation it is converted to servlet (what i have read) and web container can get response through servlets only. I am suppose to create a website using java, any help is appreciated , thanks in advance..
Why do you write Java code, when computer understands only machine level language? You can directly program in Machine Level Language.
Wish you best of luck for creating a website using servlets (without JSP's)..
Please go through the basics of JSP's then you will come to know, why JSP (View Layer in general, can be jsp or any other thing) play a very important role in any JEE application development..