File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes where to place Bean file(*.class)in Tomcat server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply locked New topic
Author

where to place Bean file(*.class)in Tomcat server

Srinivas Genji
Ranch Hand

Joined: May 04, 2004
Posts: 37
I created a simple application for getting name,age and so on.Then By hitting submit will show the values entered in a session.So i created a Java file with getters and setters for Name, age and so on.
<jsp:useBean id="user" class="UserData" scope="session"/>
where i have to store this UserData.class file.
scrathing my head for long time
Thanks in Advance
Srinivas


Genji B Srinivas<br />M.Tech (IT) Aus
Ramya Shetty
Greenhorn

Joined: May 04, 2004
Posts: 1
Place the Class file for the bean in a folder under WEB-INF/classes.
Srinivas Genji
Ranch Hand

Joined: May 04, 2004
Posts: 37
Thanks for Reply,i placed class file in web-inf/classes
but still i`m getting these errors,org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.


An error occurred at line: 6 in the jsp file: /JSP/Test.jsp

Generated servlet error:
C:\Program Files\ApacheTomcat 4.0\work\localhost\_\JSP\Test$jsp.java:86: Class org.apache.jsp.UserData not found.
UserData user = null;
^


An error occurred at line: 6 in the jsp file: /JSP/Test.jsp

Generated servlet error:
C:\Program Files\ApacheTomcat 4.0\work\localhost\_\JSP\Test$jsp.java:89: Class org.apache.jsp.UserData not found.
user= (UserData)
^


An error occurred at line: 6 in the jsp file: /JSP/Test.jsp

Generated servlet error:
C:\Program Files\ApacheTomcat 4.0\work\localhost\_\JSP\Test$jsp.java:94: Class org.apache.jsp.UserData not found.
user = (UserData) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "UserData");
^
3 errors, 1 warning


Any reply appreciated
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

This is a recording

Do not use the default package. Create a package directory structure under WEB-INF/classes, and put the package specification at the beginning of all your JavaBean classes.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Rishi Tandon
Greenhorn

Joined: Oct 23, 2002
Posts: 17
Ya Nathan is rite .


U can follow this code :






Beans should always be associated with some package other than DEFAULT.


Rishi Tandon<br />SCJP 1.2<br />SCBCD
Srinivas Genji
Ranch Hand

Joined: May 04, 2004
Posts: 37
Thanks Nathan and Rishi for helping me,
Now its working fine.
cheers mate
Srinivas
jothish chokkalingam
Ranch Hand

Joined: Jan 02, 2006
Posts: 57
Still i m getting the same error as the above my class file is
placed my class file in (C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\classes)
package user;
public class UserData {
String username;
String email;
int age;
public UserData(){
}
/*public void setUsername( String value )
{
username = value;
}

public void setEmail( String value )
{
email = value;
}

public void setAge( int value )
{
age = value;
}*/

public String getUsername() { return "jothi"; }

public String getEmail() { return "yahoo"; }

public int getAge() { return 10; }
}

MY jsp page is
<jsp:useBean id="user" class="user.UserData" scope="session"/>
<jsp:getProperty name="user" property="*" />
<HTML>
<BODY>
You entered<BR>
Name: <%= user.getUsername() %><BR>
Email: <%= user.getEmail() %><BR>
Age: <%= user.getAge() %><BR>
</BODY>
</HTML>
error i got is that
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: -1 in the jsp file: null

Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\SaveName_jsp.java:41: cannot resolve symbol
[javac] symbol : class UserData
[javac] location: class org.apache.jsp.SaveName_jsp
[javac] UserData user = null;
[javac] ^
[javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\SaveName_jsp.java:43: cannot resolve symbol
[javac] symbol : class UserData
[javac] location: class org.apache.jsp.SaveName_jsp
[javac] user = (UserData) pageContext.getAttribute("user", PageContext.SESSION_SCOPE);
[javac] ^
[javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\SaveName_jsp.java:46: cannot resolve symbol
[javac] symbol : class UserData
[javac] location: class org.apache.jsp.SaveName_jsp
[javac] user = (UserData) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "UserData");
[javac] ^
[javac] 3 errors

Help is urgently needed
thanks in advance


jothish
jothish chokkalingam
Ranch Hand

Joined: Jan 02, 2006
Posts: 57
i have placed the class file in the path C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\classes
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by jothi chokalingam:
i have placed the class file in the path C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\classes


Should be:
C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\classes\YOUR PACKAGE\yourFile.class

The directory structure has to match the package structure.
[ January 02, 2006: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
jothish chokkalingam
Ranch Hand

Joined: Jan 02, 2006
Posts: 57
hi Ben Souther ,
You mean to say it to be like this path...
C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\classes\user\UserData.class
jothish chokkalingam
Ranch Hand

Joined: Jan 02, 2006
Posts: 57
I m using jasper reports to my project...
here is my servlet class i m using ..
i want to get the output from of the pdf file in client side...
but i m not getting the stream of pdf in client side...
even there is no errror showing in the tomcat server when i load nthis servlet using an html file ......
help is needed urgently

/* Program or JASPER Engine to convert the .JRXML file to a report and the exporting it to .PDF file */
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.JRException;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.*;
import java.sql.*;
import java.io.File;
import java.util.Date;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.view.JasperViewer;
import net.sf.jasperreports.engine.JasperPrintManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletOutputStream;
import java.io.PrintWriter;
import java.io.IOException;
public class SimpleServlet extends HttpServlet{

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{


try{
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc racle:thin:@10.236.8.49:1521:heb","hebuser","hebpass");
// @machineName ort:SID, userid, password
//int i=0,j=0;
String query = "select * from storeevent1";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);


System.out.println("The context path is >>>>>>>>>> " + request.getContextPath());
/
String src= "/heb.jrxml";
net.sf.jasperreports.engine.design.JasperDesign jDesign = net.sf.jasperreports.engine.xml.JRXmlLoader.load(src);
JasperReport jReport = net.sf.jasperreports.engine.JasperCompileManager.compileReport(jDesign);

Map p1 = new HashMap();

JasperPrint jPrint= JasperFillManager.fillReport( jReport,null,conn );

OutputStream out = response.getOutputStream();
net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jPrint,out);
System.out.println(jPrint);
System.out.println(out);
System.out.println("next");
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}

}
}

help me regarding this
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

jothi,

I hadn't noticed earlier that you tacked your question onto someone else's thread. This is called hi-jacking a thread and is considered rude.
Your last post is completely unrelated.
Please start a new thread with this new question.

Thank you
-Ben
[ January 05, 2006: Message edited by: Ben Souther ]
jothish chokkalingam
Ranch Hand

Joined: Jan 02, 2006
Posts: 57
yes ben i have posted a new thread
reg opening a pdf file created by jasper in client side
can you please solve position
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: where to place Bean file(*.class)in Tomcat server