unable to compile login jsp code

V

vishal17

I have a strange problem,first i wrote the html code for input values
then i wrote d jsp code as given below for login :
this logincon.jsp is in webapps/test folder


<%@ pageimport="java.sql.*,vishal.dbConn4,java.util.*" %>

<%!
ResultSet rs ;
String sConn;
dbConn4 db;
public void jspInit() {

dbConn4 db = new dbConn4();
sConn = db.DBConnect();
rs = null;
}
%>

<%
String sID = request.getParameter("ID");
String uname =request.getParameter("uname");
String pwd =request.getParameter("password");
//String user=null;
int t=0;


rs = db.getData();

%>

<%
while(rs.next()){
%>
<%
String x=rs.getString(1);
String y=rs.getString(2);

if(x.equals(uname)&&y.equals(pwd))
{%>
<jsp:forward page="x.jsp"/>
<%
}
else{ t=1;

}
}
%>
<%if(t==1) { %>
<jsp:forward page="login1.jsp"/>
<%}%>
-----------------------------------------------------------------------------//------------------------------------------------
i wrote java program dbConn4 as below and put this class file in the
test/web-inf/classes/vishal
package vishal;
import java.sql.*;

public class dbConn4
{
// Member Variables
String uname="root";
String pwd="sai";
String url=

"jdbc:mysql://localhost/vishal";

ResultSet m_RS = null; //

RecordSet Variable
Connection m_conn = null;


public ResultSet getData() {
String sqlStatement = "SELECT

NAME,PWD FROM user" ;
ResultSet temp = executeQuery

(sqlStatement);
return temp;
}

when i compile this code then the following error comes:

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 12 in the jsp file: /tbill/login_conn.jsp
dbConn4 cannot be resolved to a type
9: <%!
10: ResultSet rs ;
11: String sConn;
12: dbConn4 db;
13: public void jspInit() {
14:
15: dbConn4 db = new dbConn4();


An error occurred at line: 15 in the jsp file: /tbill/login_conn.jsp
dbConn4 cannot be resolved to a type
12: dbConn4 db;
13: public void jspInit() {
14:
15: dbConn4 db = new dbConn4();
16: sConn = db.DBConnect();
17: rs = null;
18: }


An error occurred at line: 15 in the jsp file: /tbill/login_conn.jsp
dbConn4 cannot be resolved to a type
12: dbConn4 db;
13: public void jspInit() {
14:
15: dbConn4 db = new dbConn4();
16: sConn = db.DBConnect();
17: rs = null;
18: }


An error occurred at line: 29 in the jsp file: /tbill/login_conn.jsp
db cannot be resolved
26: int t=0;
27:
28:
29: rs = db.getData();
30:
31: %>
32:


Stacktrace:

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:
92)

org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:
330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:
443)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:362)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)

org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:
594)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:
316)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:
320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
---------------------------------------------//---------------
i also create database & tables with some entries.....
database connectivity is alright..
plz solve this problem ,i am struggling this for 1week
lots of thank u in advance......................
 
L

Lew

I have a strange problem,first i [sic] wrote the html code for input values
then i [sic] wrote d jsp code as given below for login :
this logincon.jsp is in webapps/test folder


<%@ pageimport="java.sql.*,vishal.dbConn4,java.util.*" %>

Type names should begin with an upper-case letter: 'DbConn4'.

DO NOT indent Usenet posts with TAB characters! Use a maximum of four space
characters per indent level.

Use of scriptlet in a JSP is an antipattern. I haven't done it in a while, so
I don't know why the pageimport doesn't seem to have worked.
<%!
ResultSet rs ;
String sConn;
dbConn4 db;
public void jspInit() {

dbConn4 db = new dbConn4();

This declaration hides the member declaration, so the member 'db' will remain
'null'.

Why did you declare 'rs' as a member variable? It should be local.
sConn = db.DBConnect();
rs = null;
}
%>

<%
String sID = request.getParameter("ID");
String uname =request.getParameter("uname");
String pwd =request.getParameter("password");
//String user=null;
int t=0;


rs = db.getData();

I would expect a NullPointerException here.
%>

<%
while(rs.next()){
%>
<%
String x=rs.getString(1);
String y=rs.getString(2);

if(x.equals(uname)&&y.equals(pwd))
{%>
<jsp:forward page="x.jsp"/>
<%
}
else{ t=1;

}
}
%>
<%if(t==1) { %>
<jsp:forward page="login1.jsp"/>
<%}%>
-----------------------------------------------------------------------------//------------------------------------------------
i [sic] wrote java program dbConn4 as below and put this class file
in the test/web-inf/classes/vishal

That should be "test/WEB-INF/classes/..."

And the file in the "vishal" directory is "dbConn4.class", right?

What was the exact compilation command?

(As mentioned, you should spell type names with an initial upper-case letter.)
package vishal;
import java.sql.*;

public class dbConn4
{
....

An error occurred at line: 15 in the jsp file: /tbill/login_conn.jsp
dbConn4 cannot be resolved to a type
12: dbConn4 db;
13: public void jspInit() {
14:
15: dbConn4 db = new dbConn4();
16: sConn = db.DBConnect();
17: rs = null;
18: } ....
lots of thank u [sic] in advance......................

Try giving the type its fully-qualified name (FQN) instead of doing the import
and see if that fixes it.

Either the import didn't work or the class-to-package-to-classpath mapping is
awry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top