Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Internal Servlet Error:

 
numan ahmad
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hay to all...
i am new in jsp and making login form and i got an error please tell me how can i remove that error...

Internal Servlet Error:

org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
work\localhost_8080%2Fexamples\_0005cjsp_0005cvalidate_0002ejspvalidate_jsp_0.java:76: Missing term.
session.setAttribute("username", password);
 
Tim Moores
Bartender
Posts: 2733
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The syntax of the JSP is obviously incorrect. Without seeing the source, there's nothing anyone here can do (short of pointing out that it's extremely confusing to store the contents of a field called "password" in an attribute called "username").
 
numan ahmad
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Respected sir this is my code
please tell me what is wrong in it ?

<%@ page import="java.sql.*" %>
<%
String username=request.getParameter("name");
String password=request.getParameter("pass");
String qry="Select * from student where username='"+username+"'and password='"+password+"'";
//out.println(qry);

String driver="sun.jdbc.odbc.JdbcOdbcDriver";

Class.forName(driver);
java.sql.Connection con=DriverManager.getConnection("Jdbc:Odbc:LHR");
java.sql.Statement stmt=con.createStatement();
java.sql.ResultSet rs=stmt.executeQuery("qry");
if (rs.next())
{
session.setAttribute("username", password);

<jsp:forward page="about.html">
</jsp:forward>
else {
out.println("Invalid username & password");
}
%>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main thing that is wrong is that you are putting Java code into the JSP. This is a bad practice that has been discredited for 10 years now, ever since the introduction of JSP 2 in 2002!

Time to update your JSP knowledge.

Java code should be performed in Java classes; not within JSPs.
 
numan ahmad
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok sir but may you please tell me what is the mistake in this code ?
 
Tim Moores
Bartender
Posts: 2733
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, this code is wide open to SQL injection attacks. If you're running this code you're actually asking to be hacked - it's trivially easy for an attacker to delete your data.

Secondly, your parentheses are mismatched.

Thirdly, as Bear has already pointed out, don't put scriptlets in your JSPs.

Next, don't use the JDBC/ODBC bridge driver in web apps (or for anything, really). It's buggy and not thread-safe; using it in a web app means asking for trouble.

And lastly, mixing actions like a <jsp:forward> with scriptlet code is bound to cause problems, too. Either use JSTL, or use scriptlets, but not both.
 
numan ahmad
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i do not use JDBC/ODCB then sir what should i used for web application ?
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are getting a lot of wise advice on using ODBC and using Scriptlets in JSP - be sure to pay heed to what they are telling you. But, I think the root of your error might have something to do with having two opening braces ({) and only one closing brace (}) within your JSP Scriptlet. That might explain why it's unable to compile it.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That and the fact that he's plunking JSP actions right into the middle of the scriptlets.

This sort of mixed syntax nightmare is just one of the very many reasons that scriptlets are discredited.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic