• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to call a class in yr jsp page  RSS feed

 
Raj kalaria
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have one jsp page which call the class. where am i suppose to place this class in tomcat.

Basically the requirment is that my java code will query the database and produce the results in excell sheet.

i am sending the piece of code (actually i have to do lots of things apart from wht i am posting in the code this is just to test it )


I am placing the jsp page in "C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\" folder

my jsp page is called raj.jsp
------------------***********_________-----------------------------
<%@ page import="javax.servlet.http.HttpServletRespinse"%>

<%
csv csv1 = new csv();
csv.writefile(response,out);
%>

----------------------------********************-------------------------- now my java class is as follow
-------------------**************---------------------------------

import java.util.*;
import java.io.IOException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.http.HttpServletResponse;

public class csv {

private static final String CONTENT_TYPE = "application/excel";
public void writefile(HttpServletResponse response, JspWriter out)throws IOException
{
StringBuffer buffer = new StringBuffer();
response.setHeader("Content-Disposition","inline; filename=\"mult-table.xls\"");
response.setContentType(CONTENT_TYPE);

buffer.append("<html><head></head><body>");
buffer.append("<Table border = 1><tr><th> Object Name </th><th> subject </th>");
buffer.append("</tr><tr><td>alok</td><td>cricket</td></tr><tr><td>alok1</td>");
buffer.append("<td>cricket1</td></tr></Table></body></html>");
out.print(buffer.toString());

}


}
-----------------------******************-------------------------

guys plz help plz
 
Raj kalaria
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have place the class file in

C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\WEB-INF\classes

when i call the jsp page

http://localhost:8080/raj.jsp
it gives me following error

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 3 in the jsp file: /tak.jsp
Generated servlet error:
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\tak_jsp.java:46: cannot resolve symbol
symbol : class csv
location: class org.apache.jsp.tak_jsp
csv csv1 = new csv();
^


An error occurred at line: 3 in the jsp file: /tak.jsp
Generated servlet error:
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\tak_jsp.java:46: cannot resolve symbol
symbol : class csv
location: class org.apache.jsp.tak_jsp
csv csv1 = new csv();
^
2 errors



org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
 
Raj kalaria
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I got the solution

Create a package in yr java file , anbd then import the package in yr webinf/classes folder

and in yr jsp file right the @page = import package_name

Thanks a lot
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was going to be my suggestion, thanks for getting back to us with the solution though.

In future, please try to UseRealWords and avoid abbreviations like yr, plz.

thanks,
Dave.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!