aspose file tools*
The moose likes JSP and the fly likes Calling java file from jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Calling java file from jsp" Watch "Calling java file from jsp" New topic
Author

Calling java file from jsp

Ramesh Jambulingam
Greenhorn

Joined: Jun 25, 2010
Posts: 19
Hi,

I am having a java file for doing the operation of fetching CSV feeds. I need to call the java file from my JSP and display the CSV values. Can anyone suggest me a way to call the external file.. thanks in advance.


Regards,
Ramesh.
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Try those! [=

http://www.java-tips.org/java-ee-tips/javaserver-pages/uploading-file-using-jsp.html
http://www.devsphere.com/mapping/docs/guide/upload.html


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Ramesh Jambulingam
Greenhorn

Joined: Jun 25, 2010
Posts: 19
Hi,


I gave my code snippet for creating object(ForexTest is class name) and calling the method(getRate is the method in that class).

<% ForexTest forexObject = new ForexTest();

while (true) {

int i=0;
String line = forexObject.getRate();

%>


I am getting error(500-) as mentioned below, (I am not sure about calling the method from JSP as mentioned above). Can anyone let me know how to resolve it..


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:155)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


root cause

org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:600)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:143)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


root cause

java.lang.ClassNotFoundException: org.apache.jsp.helloJSP_jsp
java.net.URLClassLoader$1.run(Unknown Source)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(Unknown Source)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:134)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:598)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:143)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

1) Put your codes inside [ code ] tags. It's easier to read.
2) I believe the messages say it coud not locate your JSP. Check the folder where you put it.
Nilesh Miskin
Ranch Hand

Joined: Jun 17, 2010
Posts: 44
Also, see if you can modify your design to comply with good programming practices. Please avoid using scriptlets in JSPs. Use servlets to implement business logic; JSPs are supposed to be 'views'. This would make your web app more scalable & maintainable.


Nilesh Miskin
Ramesh Jambulingam
Greenhorn

Joined: Jun 25, 2010
Posts: 19
Hi,

Thank you Hebert and Nilesh for your reply. The information which you is useful. I separated the view from logic.

I am calling the java file ForexTest from helloJSP.jsp file as given below.



And the called class file is,




I am trying to display the getRate method output in my helloJSP page. But still getting the same 500- error.



Could please help me to find a way to overcome this issue..


Thanks and Regards,
Ramesh.
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

I don't see anything wrong with the JSP code you posted, but you obviously didn't post all of your JSP because the error indicates that there's more to it. You're probably forgetting to comment out the ending brace of the for loop.

Also, you don't need the "language" attribute in the page directive because "java" is the only language that JSP supports.


SCJP 6 || SCWCD 5
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Instead


Try



I believe you will do fine! =D
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

Ideally, you should be storing the instance of ForexTest in a request-scoped attribute and then using EL to call getRate().

Servlet:


JSP:
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Michael Angstadt wrote:Ideally, you should be storing the instance of ForexTest in a request-scoped attribute and then using EL to call getRate().

Servlet:


JSP:


Indeed. Go for this.

I was just trying to fix your code, but just do as he says. [=
Ramesh Jambulingam
Greenhorn

Joined: Jun 25, 2010
Posts: 19
Hi thanks for your reply. For time being i used the method getRate() in my jsp itself.I inserted a for loop and this method is returning the csv feeds from server as given below.


EURUSD ,1.3286,1.3291, 8/6/2010 , 5:52pm
EURAUD ,1.4465,1.4478, 8/6/2010 , 5:52pm
NZDAUD ,0.798,0.7996, 8/6/2010 , 5:50pm

I need to pass these values to calling method in same jsp to display each separated values. How can I return these values. Can I send as buffered string? how should i parse it to display one by one.. Can anyone suggest any approach..

Thanks and Regards,
Ramesh.
 
jQuery in Action, 2nd edition
 
subject: Calling java file from jsp