aspose file tools*
The moose likes JSP and the fly likes General Error in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "General Error in JSP" Watch "General Error in JSP" New topic
Author

General Error in JSP

Deo Sharma
Greenhorn

Joined: Apr 14, 2012
Posts: 12
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Deo Sharma
Greenhorn

Joined: Apr 14, 2012
Posts: 12
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.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Apr 14, 2012
Posts: 12
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

Joined: Apr 14, 2012
Posts: 12
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

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
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61010
        
      65

    And yes, you need to add the JSTL jar files to WEB-INF/lib.
    Deo Sharma
    Greenhorn

    Joined: Apr 14, 2012
    Posts: 12
    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.
    Piyush Mangal
    Ranch Hand

    Joined: Jan 22, 2007
    Posts: 196
    Your class files should be in WEB-INF/classes folder. Check if they are there.
    Deo Sharma
    Greenhorn

    Joined: Apr 14, 2012
    Posts: 12
    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

    Joined: Jan 22, 2007
    Posts: 196
    It should be in your application's war. It is WEB-INF and not WEB_INF.
    Deo Sharma
    Greenhorn

    Joined: Apr 14, 2012
    Posts: 12
    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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: General Error in JSP