smileying
asked on
How to import an object(Java Class) in JSP? (Urgent, Thank you)
I would like to develop a function of auto mailing. It is a java class but I don't know how to use it in JSP? I'm not familiar with programming too much. I want to call the constructor in the java class. May I know how to type the import statement, how to new the object and constructor in JSP and where should I put the .class file or .java file?
Thank you!
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
Let's say I have a java file called Email. Then what I should do is putting it into a folder?? This folder is that I made? Where should I create this folder? If the folder called EmailPack, then,
<%@ page import="java.util.*, EmailPack.Email.class" %> or <%@ page import="java.util.*, EmailPack.Email" %>
Let's say I have a java file called Email. Then what I should do is putting it into a folder?? This folder is that I made? Where should I create this folder? If the folder called EmailPack, then,
<%@ page import="java.util.*, EmailPack.Email.class" %> or <%@ page import="java.util.*, EmailPack.Email" %>
just
EmailPack.Email
no .class is necessay
EmailPack.Email
no .class is necessay
ASKER
Is that I can import the file but what's the problem then?
bad class file: C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\c lasses\tem p\Hello.cl ass
class file contains wrong class: Hello
Please remove or make sure it appears in the correct subdirectory of the classpath.
Hello temp1 = new Hello();
^
1 error
bad class file: C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\c
class file contains wrong class: Hello
Please remove or make sure it appears in the correct subdirectory of the classpath.
Hello temp1 = new Hello();
^
1 error
ASKER
public class Hello
{
public Hello()
{
System.out.println("hello ar");
}
public String writing() {
String temp;
temp ="hi hi";
return temp;
}
public static void main(String args[])
{
Hello application = new Hello();
}
}
========================== ========== ========== ===
<%@ page contentType="text/html; charset=big5" language="java" import="java.sql.*,temp.*" errorPage="" %>
...
<%
out.print("1");
Hello temp1 = new Hello();
String msg = temp1.writing();
out.print(msg);
%>
{
public Hello()
{
System.out.println("hello ar");
}
public String writing() {
String temp;
temp ="hi hi";
return temp;
}
public static void main(String args[])
{
Hello application = new Hello();
}
}
==========================
<%@ page contentType="text/html; charset=big5" language="java" import="java.sql.*,temp.*"
...
<%
out.print("1");
Hello temp1 = new Hello();
String msg = temp1.writing();
out.print(msg);
%>
The default packages that are available to JSPs are not available to add
new classes to. Any classes you write that you want to use in your JSP
pages have to be specifically imported (the packages at least).
You can 't use the default package, so you 'll need to define a package
and based on the package you include the Class names....
import="package.class" or import="package.class1,...
example....
<%@ page import="java.util.*, PakcageName.YourClass1" %>
R.K