Using java classes in jsp
hi everybody
I'm using Apache Tomcat 5.5.7 and I want to develop very very simple jsp-files.
I have a java class file called MyClass.
When I start the jsp file with the code line
MyClass class = new MyClass();
I get this error: MyClass cannot be resolved or is not a type
As I know the hierachy must be the following:
ProjectRoot/WEB-INF/classes/MyClass.class
ProjectRoot/start.jsp
In the java class the Constructor is empty... so I cannot see why this should make a problem. I also tried to put the class file into a package and import the package. I had the same error then.
I read something about the web.xml file which should be in the WEB-INF directory.
will this help me... and if yes, what do I need to write into it?
If I did any mistake I would be happy if somebody could give me a hint.
Cheers
alex
1 - The class needs to be in a package. eg com.mypackage.MyClass. This file lives in /WEB-INF/classes/com/mypackage/MyClass.class
2 - in your jsp you include the line
<%@ page import="com.mypackage.MyClass" %>
<%
MyClass myClass = new MyClass();
%>
3 - Also note that "class" is a reserved word in java, and can not be used as a variable identifier.
4 - Yes you most probably should have a web.xml file in the WEB-INF directory.
Look under the webbapps/ROOT/WEB-INF for a basic example.
Cheers,
evnafets
Similar Messages
-
Using java class from JSP page
I have a class that connects to the database and return the result in form of array of objects, now I wrote a tester and I was able to print the result on the console but when it came to JSP how can I use this class I am a bit confused, how can I declare an array of objects and save the result that comes from the class method
note: my class is not a bean it is a service class that contain methods to retreive different information from the database.
I would apritiate any help but please make it in sequence for example declaring an array to hold the result then call the method that returns the array of objects..etc
please help, I am really confused and don't know what to write
thank youYou can access a class in the same way as a bean, after all a bean is just a class that follows a set of rules.
You need to put your classes in packages to access them.
I have 2 packages, params and DTO. I set the class that returns the Data Transfer Object, or array of objects up as I would a bean
<jsp:useBean id="DTO" scope="request" class="params.DTO" />
I think you skip the above declaration and access it directly in code using
params.DTO();
but setting it up as I would a bean allows me to simply use
DTO();
DTO is the class that passes back the array of objects.
Objects themselves I have in a seperate package, also called DTO (sorry if this is confusing, made sense at the time :-) ) You dont need them in seperate packages, just helped me keep DTO objects seperate from business logic classes......
Now before I use params.DTO() I declare a variable of the Object type DTO() returns
<%! DTO.workSheet[] ws; %>
So, ws is the object type that will be returned by params.DTO()
Then to get my array of objects back from params.DTO() :-
ws = DTO.workSheet(day);
or if you dont like the bean declaration
ws = params.DTO.workSheet(day);
You need to put your packages under WEB-INF/Classes when using Tomcat
So I have
Tomcat 5.0\webapps\myApplication\WEB-INF\classes\params
Tomcat 5.0\webapps\myApplication\WEB-INF\classes\DTO
Under which reside the classes -
How to use java class in jsp page of JSPProvider?
Hello everybody.
I created simple JSPProvider channel with portal amconsole and named it "jspprov1". Then I created "jspprov"1 directory under "/ets/opt/SUNWps/desktop/sampleportal". I put "index.jsp" in it. And it worked until I add this line into "index.jsp": <% @page import="jspprov1package.aclass1" %>. Then I created directory "jspprov1package" under "/ets/opt/SUNWps/desktop/classes" and put "aclass1.class" into it and into "/ets/opt/SUNWps/desktop/classes" itself. I created "aclass1.class" on the other machine (with no installed portal) in j2sdk1.4.1_02: "javac aclass1.java". The text of this class is simple:
"package jspprov1package;
public class aclass1{
public int int_field = 10;
But the page still don't work. It writes on the portal desktop "ERROR: Content is not available".
Does anybody know why this happened?Sorry, there were mistakes in jsp page and java files.
I maked the channel "show exceptions" and found them out. -
Passing parameters from a Java class to Jsp page
Hi everybody. I'm newbie in using Java class in conjunction with JSP pages. Infact I have a problem. How can I pass the parameters used in a Java class (as UserName, Password, and so on..) to a JSP page? What methods (and classes) I have to use?
Thank you in advance
Have a nice dayIt still doesn't work. I write the code
//my java class
package channel_service;
import java.util.Vector;
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
public class CallMenu {
private Vector parameters = new Vector();
public void setParameters( String UserId ) {
parameters.add(0, UserId);
//parameters.add(2, Pin);
//parameters.add(3, UserName);
//parameters.add(4, Greeting);
public Vector getParameters() {
return parameters;
//my jsp page
<%@ page import="Channel_Service.src.channel_service.CallMenu" %>
<%@ page import="java.util.Vector" %>
<html>
<head><title>User Menu Page</title></head>
<body>
<center><h1><i><b>This is your personal User Menu page</b></i></h1></center>
<br>
<br>
<center><h2><i>In the list below you'll find all your personal information (as UserID, Password and so on...)
and all the function you have the rights to use</i></h2></center>
<br>
<br>
<table align=center>
<tr>
<%
CallMenu cl = new CallMenu();
cl.setParameters();
Vector params = cl.getParameters();
String UserId = (String)params.elementAt(0);
String Pin = (String)params.elementAt(1);
String UserName = (String)params.elementAt(2);
String Greeting = (String)params.elementAt(3);
%>
<td><h2><b><i>User ID = <%= UserId %></td></tr>
<tr><td><h2><b><i>PIN = <%= Pin %></td></tr>
<tr><td><h2><b><i>User Name = <%= UserName %></td></tr>
<tr><td><h2><b><i>The system says <%= Greeting %></td></tr>
</table>
</body> -
Need help with tomcat 5.5 and using java classes
hey there,
i am trying to set up tomcat 5.5 on my computer at home and have sucessfully done so. i have been trying to use Java classes inside my JSP files however tomcat thows an internal servlet error as follows:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 144 in the jsp file: /order.jsp
Generated servlet error:
ProductList cannot be resolved to a type
An error occurred at line: 144 in the jsp file: /order.jsp
Generated servlet error:
ProductList cannot be resolved to a type
An error occurred at line: 144 in the jsp file: /order.jsp
Generated servlet error:
Product cannot be resolved to a type
i have the classes located as the setup tutorial recommends (root/WEB-INF/classes/) and still nothing works. i would appreciate any help anyone can give.
thanks,Which tutorial are you following?
As of java1.4, all classes must be in packages for them to work in Tomcat. This means your beans and servlets too.
Put your beans in a package, and then recompile them, and put them in the right place.
eg
package com.mypackage
public class MyClass ...
once compiled would go into WEB-INF/classes/com/mypackage/MyClass.class
Are you using Product and ProductList classes in scriptlet code?
Have you imported them with a page directive
<%@ page import="com.mypackage.Product, com.mypackage.ProductList" %> ? -
Accessing java class in JSP on Tomcat 5.5 server
Just i want to use a java class in JSP.
Explanation in following steps :
a. MY JSP Code - SimpleBean.jsp
b. My Java file - test.java
c. Path ( Root, jdk, jre , myfiles-test.java, SimpleBean.jsp )
d. Environment Variables
e. Error Message faced
Now Brief explanation.
a. MY JSP Code :
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,test" errorPage="" %>
<td>
<%! test obj = new test();
obj.setAge(32); %>
<%= obj.getAge(); %>
</td>
b. My Java file - test.java
package test;
class test
private int age;
public int getAge()
return age;
public void setAge(int intage)
this.age = intage;
c. Path ( Root, jdk, jre , myfiles-test.java, SimpleBean.jsp )
Tomcat Root : c:\Program Files\apache\tomcat5.5\webapps\ROOT
jdk : C:\Program Files\Java\jdk1.5.0\bin;
jre : C:\Program Files\Java\jre1.5.0\bin;
test.java : c:\Program Files\apache\tomcat5.5\webapps\ROOT\NRMS\test\test.java
SimpleBean.jsp : c:\Program Files\apache\tomcat5.5\webapps\ROOT\NRMS\test\SimpleBean.jps
d. Environment Variables :
PATH :
C:\Program Files\Java\jdk1.5.0\bin; C:\Program Files\Java\jre1.5.0\bin;
CLASSPATH :
.;C:\Program Files\Java\jre1.5.0\bin;
e. Error Message Faced : ( on accessing url http://localhost:8080/NRMS/SimpleBean.jsp )
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
Generated servlet error:
The import test cannot be resolved
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
test cannot be resolved (or is not a valid type) for the field SimpleBean_jsp.obj
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
test cannot be resolved or is not a type
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
Syntax error on token(s), misplaced construct(s)
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
Syntax error on token "32", delete this token
An error occurred at line: 28 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
Syntax error on token ";", delete this token
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:389)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.4 logs.
Apache Tomcat/5.5.4
Please explain where i am doing the mistake.
Thanks in advance.
Regards,
Lax.>
<%@ page contentType="text/html; charset=iso-8859-1"
language="java" import="java.sql.*,test" errorPage=""
%>Your class is test.test.The compiler wouldnt know what test is from your import.
Change import as
java.sql.*,test.test
<%! test obj = new test();
obj.setAge(32); %>The symbol '!' ? -
Java Classes and JSP`s (urgent)
hi, my question is:
How can i invoke normal java classes` methods using Jsp`s for this??, is it possible??, if it is, then how do you do this, and where do you have to put the java classes in order to find them from a jsp.
thanksHi,
You can access normal java classes in JSP pages. You have to import them in the header like this:
<%@ page language="java" import="//your java class file with package"%>
or if u r using java beans, then use the <usebean> tag. Put the java classes in the classes directory. Which server u r using? If it is JWS, then u have a specified classes directory, where u have to put all the class files along with their packages. Hope this will help.
atanu. -
How to load java class from jsp page?
hi all!
Does anyone know how to load java class from jsp page?
I try to load java class from jsp page.
Is it possible to load java class fom jsp page?
thanks and have a good day!What I mean is How to load/open java class file from jsp page?
I think we can open Applet from jsp page by using
<applet code=helloApplet.class width=100 height=100>
</applet>
but, how to open java class which is an application made by Frame?
thanks and have a good day -
What's the difference between using java directly in JSP and java bean
What is the difference if I use java code directly in JSP or use java bean in JSP?
Which class to use for receiving the passed parameter from html or java script? Any difference for java code and java bean in the way receiving the passed data?
How can I pass string from jsp to html or java script?1 Cleaner pages
2 you have to write the class and use set and get methods
3 What do you mean when saying passing string from jsp to html??, do you mean the value you can use <%=variablename%> -
Can any help, can i use java class in
froms 6 or any one have designed form
of progress bar please help meThanks for your reply...
Actually the task is quite simple... It requires me to do a better interface for a tomcat server folders...
For example, users are free to access
http://apache.oss.eznetsols.org/jakarta/tomcat-5/v5.0.12-beta/
to download the tomcat... However, its index may not nice and easy for browing.. Therefore, the task requires a new dynamic page to access this server folder, and get all file names under this folder, anlaysis whether it is file or directory..and finally get its path....
It is quite easy to do a JSP page, but I don't know whether it is possible to do by using JavaScript .... Although JS is running in client side, the user/client also can access the tomcat folder, why not JavaScript?
Thanks a lot!
SD -
hello friends,
i'm new to jsp. i want to create an html form that accepts username and a value from four radio buttons and display back the entered name and checked radio button's value using java bean.
i use the <jsp:setProperty id="" property="*"> method. i don't know how to access the radio buttons value from the html.
also when i use an additional field other than username the jsp page is showing error.
Please give me the correct method to use java bean with jsp in this circumstance.
thank you.thank you, but i have a problem left. the case is like this.
i got the jsp and bean worked fine when i have a sinle input text field.
but when i added a second text field i recieved the following error.
javax.servlet.ServletException: basket.newbean.getUserPass()Ljava/lang/String;
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.newform.process_jsp._jspService(process_jsp.java:69)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
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)
where userPass is the new form element. I have made the subsequent chanes in my bean program and jsp file.
pls hlp. -
Calling java class from jsp page
Dear Friends.
I wrote jsp page and java class.
Am calling java class from jsp page. after processing result,
I have to refresh jsp page from java class.
processing time may take 5 minutes or 1 minute etc. that depends on user.
Can It be possible ? if possible , How ?Ok, I get a very strange error now:
org.apache.jasper.JasperException: Unable to compile class for JSPerror: An error has occurred in the compiler; please file a bug report (http://java.sun.com/cgi-bin/bugreport.cgi).
What is this??? Anyone? -
How to use JAVA class in C++
Hi people,
is there anyone who knows how I can create and use JAVA class in C++ code. Example I have one JAVA class which works with database.
One of the methods from this class returns XML string that represent result set. How to create instance of this class inside of C++ and have possibility to call this method.Hi, I'm also curious how to solve this.
My problem is that I call a DLL from C++ that returns several values (e.g. function(a, b, c, &w, &x, &y, &z); )
and I want to create a java class object that can be used to store these values so I can return 1 object
Below I've written an abstract of the code
Can someone help me with the parts in <> ??
Thanks!
Sander
JNIEXPORT jobject JNICALL Java_nativeF(...a,b,c...)
int w,x;
float y,z;
C_DLL_Function(a, b, c, &w, &x, &y, &z);
//<Create Java Class 'Data' jobject>
//<Call Data.setvalues(w,x,y,z) >
return jobject;
...in java...
class Data
private int jw, jx;
private float jy, jz;
public function setvalues(int w, int x, float y, float z)
jw = w;
etc...
[\code] -
Create web service using java class
Hi,
I created the web service using java class then i deployed this web service in to the weblogic admin server.when i tested this process it is working fine.
when I tested The generated WSDL to this process in browser(IE). it is not working.
I need to to invoke this webservice from another BPEL but this WSDL is not working.Hi,
when i created the webservice in jdeveloper by default it is connected to integrated weblogic server and generates this wsdl.
http://localhost:7101/helloApplication-javaexcel-context-root/MyWebService1Soap12HttpPort?WSDL
then I deployed this webservice in to the Adminserver.it gives the following URL.
http://192.168.56.1:7001/extracExcelToCSV-extractExcelToCSV-context-root/ExtractExcelToCSVSoap12HttpPort?wsdl
This URL is not working but when i tested this process it is working fine.
It is giving below error when i try to invoke from jdeveloper
Error while reading wsdl file
caused by:java.net.connectExcepption :Connection timed out:connect -
Help for using java class in forms 9i
hi
i have been trying to use java class in forms9i but unable to execute ,i have encountered exceptions,for which exception handlers have been declared like ora_java.java_error and exception_thrown but failed to handle run time errors , i have tried all ways from my side.
my java class returns a simple string
i need help on various work arounds
thanks in advance
yashsir
i have written a simple java class which returns a string hello imported using a java importer in forms 9i
and i call my class in when button press trigger
i have also imported java.lang.Exception for my exception handlers,i have no compile errors,but when i run my forms i get run time error and my exception handlers fail to trap it . ihave no idea how to proceed .
should i use bean area in form and call the class using fbean from custom item rigger if so please explain
can i get sample code example for calling a java class methods from forms.
thanks
yash
Maybe you are looking for
-
I have an iPad2 and a new MacBook running Mountain Lion. Both Devices use the same Apple ID which is a Hotmail eMail id. Can I create a new iCloud eMail Id and use iCloud eMail and continue to use my current Hotmail Id for my Apple Id for iTunes, iCl
-
E17 crashes when opening "sreen resolution" dialog
hello! i have a problem for a long time. when i want to open the screen resolution dialog e17 freezes. i can move the mouse and kill the xserver by strg-alt-backspace, but enlightenment is not responding. anyone here with the same problem? another th
-
Blackberry updates remove (uninstalls) Roxio Easy CD/DVD Burning software
Whenever I do a Blackberry Desktop update, my Roxio Easy CD/DVD Burning software is removed. The only part of the program left standing is the "Drag & Drop" portion. Solved! Go to Solution.
-
I'm Lost...Installing/Config Forms 6i & Forms Server
I realize this is pretty basic so my apologies to everyone but... I have installed Oracle Standard 8i (8.1.6) on my Windows 2000 Server. I then installed forms 6i Release 2 for xp on my client PC. I then installed Forms servers and pretty much accept
-
Ios5 no longer allows Live Playlist Syncing
I had this problem in early releases of iOS4 and it was eventually fixed, but now it's back in iOS5. Ipads and iPhones, and I suspect iPods will not sync live updated smart playlists. I tried restoring my iPhone 4, the tried removing and resyncing