• Post Reply Bookmark Topic Watch Topic
  • New Topic

Login page not working

 
Bittu Bhowmick
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone. I am facing a problem with the code i have written for the login page. The problem is it does not redirect to the respective page on successful validation. It instead displays the message in the alert box written at the end of the code in the else part. I am writing the code below. Thanking you all in advance.




 
Mauro Trevigno
Ranch Hand
Posts: 99
Java Linux Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The use of scriptlets (those <% %> things) in JSP is indeed highly discouraged since the birth of taglibs (like JSTL) and EL (Expression Language, those ${} things) over a decade ago.

The major disadvantages of scriptlets are:

Reusability: you can't reuse scriptlets.
Replaceability: you can't make scriptlets abstract.
OO-ability: you can't make use of inheritance/composition.
Debuggability: if scriptlet throws an exception halfway, all you get is a blank page.
Testability: scriptlets are not unit-testable.
Maintainability: per saldo more time is needed to maintain mingled/cluttered/duplicated code logic.

JSTL vs Scriptlet

Also here it an intro to JSTL:
http://www.javaranch.com/journal/2003/09/AnIntroductionToJstl.html

Try to put all the db logic in you backend, by the way for a login page you should use Preparedstatement, statement is vulnerable to sql injections.

Thanks,
-M
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Mauro has given you really good advice; heed it!

Also, please be sure to use code tags when posting code to the forums. Unformatted or unindented 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 click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.

I've gone ahead and added the code tags for you. See how much easier the code is to read?
 
Paul Clapham
Sheriff
Posts: 21863
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for the actual code, I suggest putting it into a servlet (where it belongs, as the others have alreadyu said). I also suggest fixing up the indentation so it's understandable -- one thing about putting Java code into a JSP is that you tend to indent it according to the JSP's rules rather than Java's rules which makes it hard to understand. Also remove the comments like /* 39 */ which interfere with the readability of the code. And then debug the code so you can tell which branches of your if's and else's are being taken. I think you'll find that your code first decides to redirect somewhere, then continues on and makes a different decision.

You've also made every single coding error traditionally made by programmers new to JDBC, but that's a separate issue and shouldn't affect the problem you're asking about here.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!