Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 8th, 2004, 06:16 PM
Registered User
 
Join Date: Mar 2004
Location: Luton, Beds, United Kingdom.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default problems with examples

Hi,
    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;

    try
     {
       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");

       while(rs.next())
        {
         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());
        }
       finally
       {

         try
          {

            if(rs != null)
              rs.close();
            if(st != null)
              st.close();
            if(con != null)
              con.close();
          } catch (SQLException e)
             {
             }
       }
   }

 public int getId()
  {
    return id;
  }

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

 }// class ends


jsp page:

<html>
 <head>
   <title>Checking pass</title>
 </head>
<body>
<%
  com.mysql1 qdb = new com.mysql1();
  qdb.init();

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

</body>

</html>


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)

Reply With Quote
  #2 (permalink)  
Old March 9th, 2004, 05:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is JAVA_HOME set up corerectly?

Cheers

Martyn
Reply With Quote
  #3 (permalink)  
Old March 9th, 2004, 07:07 AM
Registered User
 
Join Date: Mar 2004
Location: Luton, Beds, United Kingdom.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

cheers

Javahead
Reply With Quote
  #4 (permalink)  
Old March 9th, 2004, 07:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Cheers

Martyn
Reply With Quote
  #5 (permalink)  
Old March 9th, 2004, 08:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Cheers

Martyn
Reply With Quote
  #6 (permalink)  
Old March 9th, 2004, 09:14 AM
Registered User
 
Join Date: Mar 2004
Location: Luton, Beds, United Kingdom.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Javahead
Reply With Quote
  #7 (permalink)  
Old March 9th, 2004, 11:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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:

JAVA_HOME

CATALINA_HOME

PATH

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

Cheers

Martyn
Reply With Quote
  #8 (permalink)  
Old March 9th, 2004, 12:52 PM
Registered User
 
Join Date: Mar 2004
Location: Luton, Beds, United Kingdom.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #9 (permalink)  
Old March 9th, 2004, 01:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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/


Cheers

Martyn
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems running Beginning ASP.NET 2.0 examples ymak ASP.NET 2.0 Basics 0 June 4th, 2006 05:02 AM
Problems with Examples of Beginning with php4 Book xtimox Beginning PHP 2 December 17th, 2004 02:01 PM
problems with examples in book skicrud Javascript How-To 2 May 27th, 2004 08:52 AM
Problems with the examples from the J2EE book alf.guzman J2EE 0 April 20th, 2004 09:43 AM



All times are GMT -4. The time now is 02:48 PM.


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