p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   JSP Basics (http://p2p.wrox.com/forumdisplay.php?f=92)
-   -   problems with examples (http://p2p.wrox.com/showthread.php?t=10251)

Javahead March 8th, 2004 06:16 PM

problems with examples
    i tried to run the program written on chapter 13 in page 492. i wrote a similar program but if i run it, it shows error. can anyone help me please.Here's my code:

package com;

import java.sql.*;

public class mysql1

  int id=0;
  int account_no=0;
  String pass="";

  public void init()
      Connection con = null;
      Statement st = null;
      ResultSet rs = null;

       Class.forName("com.mysql.jdbc.Driver").newInstance ();
       con = DriverManager.getConnection("jdbc:mysql:///password",
        "root", "firehouse");

       st = con.createStatement();
       rs = st.executeQuery("SELECT id, account_no, password FROM pass");

         id = rs.getInt(1);
         account_no = rs.getInt(2);
         pass = rs.getString(3);
         //System.out.println(userId + ". " + lastName + ", " + firstName + " ");

     } catch (Exception e)
         System.err.println("Exception: " + e.getMessage());


            if(rs != null)
            if(st != null)
            if(con != null)
          } catch (SQLException e)

 public int getId()
    return id;

 public int getAccountNo()
    return account_no;
 public String getPass()
    return pass;

 }// class ends

jsp page:

   <title>Checking pass</title>
  com.mysql1 qdb = new com.mysql1();

<h2>Query Result</h2>
Account No: <%qdb.getAccount_no()%>
Password: <%qdb.getPass()%>



but i get the following error when i run it:

org.apache.jasper.JasperException: Unable to compile class for JSP
No Java compiler was found to compile the generated source for the JSP.
This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK
to the common/lib directory of the Tomcat server, followed by a Tomcat restart.
If using an alternate Java compiler, please check its installation and access path.

    org.apache.jasper.compiler.DefaultErrorHandler.jav acError(DefaultErrorHandler.java:128)
    org.apache.jasper.compiler.ErrorDispatcher.javacEr ror(ErrorDispatcher.java:348)
    org.apache.jasper.compiler.Compiler.generateClass( Compiler.java:415)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:455)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:439)
    org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:555)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:300)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:293)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:240)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:856)

Martyn March 9th, 2004 05:41 AM

Is JAVA_HOME set up corerectly?



Javahead March 9th, 2004 07:07 AM

Thanks martyn for your reply. yes i set the JAVA_HOME in the environment variables.but i got this error.



Martyn March 9th, 2004 07:54 AM

Have you ran successfully compiled other JSPs using the current Tomcat implementation?



Martyn March 9th, 2004 08:10 AM

Searching around a bit, it seems that this rather seriously sounding error can in fact be caused by something as simple as a missing brace or a semi-colon. If you can run other JSPs then it all points to the problem being in your source. Are you sure that the class path to your com package is correct? Why not write a simple JSP snippet to prove this. If you can't run other JSPs then it is down to your implementation.



Javahead March 9th, 2004 09:14 AM

Thanx martyn. i set all the paths according to the instruction on page 13 of chapter 1 "Configuring your environment". is that okay or not. can u please tell me the complete path list.Thank you.


Martyn March 9th, 2004 11:08 AM

I don't have the book to hand but if you have exactly the same version of Tomcat as the one specified and carried out the install instructions then it should work. I've the following variables set on my machine:




You still haven't said if you can run other JSPs.



Javahead March 9th, 2004 12:52 PM

Hi martyn,
          thanx again. i can run the chapter 4 javabean examples, in that case the jsp runs. but if i run the jsp that calls a function like <%qdb.getTitle()%> then it shows the errors. i already set up the paths the way u said. but it still doesn't work. thank you for ur help.can u help me please.Thanx again.

           --- Javahead

Martyn March 9th, 2004 01:40 PM

Has class com.mysql1 has compiled and been deployed to reside in your-install-directory\webapps\ROOT\WEB-INF\class? If not move it to there, delete the old version and restart Tomcat (can't hurt can it?).

For a brief and simple tutorial on JSPs and beans see: http://java.sun.com/developer/online...cises/Counter/



All times are GMT -4. The time now is 12:57 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.