• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

General Error in JSP

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I m trying to display data from Ms-access to JSP pages in HTML. I have a table name test in Access database with two field ID and names. But i m getting Exception as General Error my code is as under. I have trace the exception, it is at reading the data from database as it is showing the exception of ClassNotFoundException3 General Error

<%@ page
import = "java.io.*"
import = "java.lang.*"
import = "java.sql.*"
%>

<HTML>
<BODY>
<%! String db=null;%>
<%
Connection conn = null;
String Event = new String("");

Statement stmt = null;
Statement stmt2 = null;

ResultSet rs = null;
ResultSet rs2 = null;

try
{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
}




catch( ClassNotFoundException e )
{
%>
ClassNotFoundException1: <%= e.getMessage() %>


<%
}
try
{
db= "jdbc:odbc:Driver={MicroSoft} Access Driver (*.mdb);DBQ=C:/demo.mdb";
}
catch(Exception e )
{
%>
ClassNotFoundException2: <%= e.getMessage() %>


<%
}
try
{

conn = DriverManager.getConnection( db );


stmt = conn.createStatement();

rs = stmt.executeQuery( "SELECT * FROM test" );

%>
Names
<%
while( rs.next() )
{
%>
this is a line from the DB: <%= rs.getInt("ID") %>
<%=rs.getString("names")%>
<%
}

}

catch(Exception e )
{
%>
ClassNotFoundException3: <%= e.getMessage()%>


<%
}

finally
{
//Clean up resources, close the connection.
if( conn != null )
{
try
{
conn.close();
}
catch( Exception ignored )
{
}
}
}

%>

</BODY>
</HTML>

Please help me to solve the problem
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, you should not be putting Java code into a JSP. That's a practice that has been discredited for 10 years now.

That said, it sounds like you are missing a jar file. We'll need to see the exact stack trace, not your paraphrasing of it.
 
Deo Sharma
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply and suggestion. The problem has been solved but you have told me to not to put java code in JSP. Then how to perform these task. As i m new to JSP so i want to know about this. Can you tell me the exact way to perform using minimum software to develop the web page using JSP and tomcat 6.0.35.
 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start by getting a current book on Java web app development, like Head First Servlets & JSP. There's more to Java web app development than raw JSPs - you need to know about servlets, backing beans, JSTL and EL as well if you want to create a well-structured app.
 
Deo Sharma
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am planning to develop web page using Tomcat 6.0.35, net beans and JSP. Is that all are enough to develop the basic web page of storing and retrieving data from database?
 
Deo Sharma
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I m not gettin values from java file that contain getter and setter method. I have use use Bean tag in jsp page. But i m confused where to place my java file or class file. Do i need to install any software for using Bean tag in JSP. Please tell me the steps to get values from java file to JSP page. I have try the example given in this forum but not worked. It does not show any error but not getting the value. Please help me i m stucked.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, make sure you have an understanding of the basics of JSP and a handle on web application structure. These articles will help:
  • The Secret Life of JSPs
  • The Front Man

  • Essentially you set a bean object into request scope as a scoped variable (using setAttribute()) in the page controller. Within the page you can use the EL and JSTL to read the properties of the bean. Tags such as useBean and getProperty aren't used all that much in modern JSP.
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    And yes, you need to add the JSTL jar files to WEB-INF/lib.
     
    Deo Sharma
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Dear sir,

    I have JSTL jar files in the WEB_INF/lib. But also i m not able to access the value from JAVA FILE. Can you tell me where to save my java file that contain getter and setter method. I want to use use Bean tag only in JSP page. I think the culprit is on Java file that has get and set method. From where JSP page access the value of Java Class file. Can you tell me in details.
     
    Ranch Hand
    Posts: 196
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Your class files should be in WEB-INF/classes folder. Check if they are there.
     
    Deo Sharma
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Dear sir,

    I have the class file in WEB_INF/classes folder of Tomcat 6.0.35. It should be in the WEB_INF/classes folder of Tomcat or where?
     
    Piyush Mangal
    Ranch Hand
    Posts: 196
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It should be in your application's war. It is WEB-INF and not WEB_INF.
     
    Deo Sharma
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    My application is in C:\apache-tomcat-6.0.35\webapps folder. So where to place my java file and class file of java file in order to get the value from getter and setter method of Java file from JSP page. I have put the Java File in WEB-INF/classes folder but it is not displaying the data.

    I have one html page in which user enter his name,email and age. When click submit button in this html page it post to JSP page which in turn call the Java file containing the get and set method and display the result. But it is not displaying the data.

    My JSP page which display the data is as under;

    <jsp:useBean id="user" class="user.UserData" scope="session"/>
    <HTML>
    <BODY>
    You entered<BR>
    Name: <%= user.getUsername() %><BR>
    Email: <%= user.getEmail() %><BR>
    Age: <%= user.getAge() %><BR>
    </BODY>
    </HTML>

    So, now my question is where it search for that user package and UserData Class.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic