| Author |
failing to login with jsp, bean and servlet
|
Kenneth Owino
Greenhorn
Joined: Aug 09, 2010
Posts: 23
|
|
[size=12][size=12]Hi! I've written this code to login from jsp using a bean and servlet that checks username and password
from mysql database.
Code below:
The problem is the browser only displays a blank page of loginJsp.jsp and yet I expect it to display Hello World in
the adminHome.jsp. Where could the problem be? Please help me troubleshoot. [/size]
[/size]
|
 |
Stefan Evans
Bartender
Joined: Jul 06, 2005
Posts: 1002
|
|
Suggestion to help us answer your question: remove all the parts irrelevant to your question, and provide an example which has the bare bones of what you want to do, and displays the error.
For instance all of the styling information in this page is extraneous to your issue. We have to spend time scanning through a 2-3 page long jsp page, which we may not feel like doing. In fact you probably could have just posted the servlet for the login bit, because that appears to be the bt that is failing.
I presume you are filling in loginname/password, hitting submit, and expecting login to succeed.
There are many points in this code in which this can fail, so my suggestion would be to pepper the relevant bits with log statements. A logger like Log4j would be ideal, but System.out.println does almost as well :-)
Then check the output of your log file.
Some suggestions:
your checking if the fields are provided looks wrong to me
if (req.getParameter("usrnm") != null && req.getParameter("username") != "" && req.getParameter("pwd") != null && req.getParameter("password") != "") {
1 - You are referencing two different parameters: usrnm and username.
2 - To compare for empty string, use the .equals method, not !=
I think it should be more:
Also, when executing a query, you should use a prepared statement to pass in values rather than building a sql string in this fashion. You have opened yourself up for a SQL Injection attack.
|
 |
 |
|
|
subject: failing to login with jsp, bean and servlet
|
|
|