Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi all, I'm new in JSP and total

Status
Not open for further replies.

garfield11

IS-IT--Management
Jul 4, 2002
44
0
0
SG
Hi all,

I'm new in JSP and totally no idea how it works. So far I was able to load the driver and get a connection to the database already. That's great!

Now the problem is I have created a package called "myappli" and placed it in C:\tomcat\webapps\ROOT. In it I created another folder called "classes" where all my .java/class files are stored.

Under JPadPro menu, I set the standard classpaths as:
\\WESTPOINT\Microsoft_SQL_Server_2000_Driver_for_JDBC\lib\msbase.jar
\\WESTPOINT\Microsoft_SQL_Server_2000_Driver_for_JDBC\lib\mssqlserver.jar
\\WESTPOINT\Microsoft_SQL_Server_2000_Driver_for_JDBC\lib\msutil.jar
\\WESTPOINT\tomcat\lib\servlet.jar

So far I created Employee.java/class n Employee.jsp and import as like <%@ page import = &quot;myappli.Employee&quot; %> but i encountered error -

org.apache.jasper.JasperException: Unable to compile class for JSPC:\tomcat\work\localhost_8080\_0002fmyappli_0002fEmployee_0002ejspEmployee_jsp_0.java:15: Class myappli.Employee not found in import.
import myappli.Employee;
^
1 error

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
at org.apache.jasper.servlet.JspServlet.doLoadJSP(JspServlet.java:612)
at org.apache.jasper.servlet.JasperLoader12.loadJSP(JasperLoader12.java:146)
at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:542)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:258)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:268)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:806)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:752)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Unknown Source)

Can anyone please advise? Thanks!

Love_Garfield [spin]
 
Sorry but i really very blur.

Ok now my tomcat located at C:\ drive and I created a folder called &quot;myapp&quot; under webapps. Then inside myapp got 2 other folders : WEB-INF & inside it got web.xml + another folder called classes (where i put all my .java/class files are placed) and jsp (where all my .jsp files are placed).

Then in tomcat.bat I
set _CP=%CP%
set _TOMCAT_HOME=%TOMCAT_HOME%\webapps\myapp\WEB-INF\classes%

Then in server.xml i added in
<Context path=&quot;/myapp&quot; docBase=&quot;webapps/myapp&quot; debug=&quot;1&quot; reloadable=&quot;true&quot; />

Then under JDK menu the standard classpath i added this :
\\WESTPOINT\Microsoft_SQL_Server_2000_Driver_for_JDBC\lib\msbase.jar
\\WESTPOINT\Microsoft_SQL_Server_2000_Driver_for_JDBC\lib\mssqlserver.jar
\\WESTPOINT\Microsoft_SQL_Server_2000_Driver_for_JDBC\lib\msutil.jar
\\WESTPOINT\tomcat\lib\servlet.jar

So far am i correct?

Then I created Employee.java to display all employee's info;

Below r e codes :

import java.util.*;
import java.sql.*;
//import java.io.*; <bp> public class Employee {
public static void main(String args[]){
// Load the relevent JDBC driver
try {
Class.forName( &quot;com.microsoft.jdbc.sqlserver.SQLServerDriver&quot; );
} catch (ClassNotFoundException e) {
System.err.println( &quot;Driver not found: &quot; + e + &quot;\n&quot; + e.getMessage() );
}
// Use the driver to connect to the database
try {
Connection conn = DriverManager.getConnection (
&quot;jdbc:microsoft:sqlserver://servername:1217&quot;, &quot;username&quot;, &quot;password&quot; );
Statement stmt = conn.createStatement();
ResultSet rs;
// Now execute our query
rs = stmt.executeQuery(&quot; SELECT * FROM Employee &quot;);
while (rs.next()) {
String EmpID = rs.getString(&quot;Employee_ID&quot;);
String name = rs.getString(&quot;Name&quot;);
System.out.println(EmpID + &quot; &quot; + name);
}
conn.close();
} catch (Exception e) {
System.err.println(&quot;Exception: &quot; + e + &quot;\n&quot; + e.getMessage() );
}
}
}

I save it under C:\tomcat\webapps\myappl\WEB-INF\clasees and was able to compile and run it and it display employee_id n name.

I also created Employee.jsp and save under C:\tomcat\webapps\myapp\jsp and try to import my class as like:
<%@ page import = &quot;myapp.Employee&quot; %> and try to view it by typing this add:
but it give me e error like &quot;page not found&quot;.

I really dunno what's wrong. Can anyone please advise?

Thanks.

Love_Garfield [bomb]
 
The JSP files should not be in WEB-INF (unless you are using MVC in which case it is valid).

Directory Structure should look like:
myapp
\_.jsp files
\_WEB-INF
\_web.xml
\_classes
\_.class files
 
Yes!!!

Finally can view it already.

Thanks a lot.

Love_Garfield [bomb]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top