?
Solved

How to import an object(Java Class) in JSP? (Urgent, Thank you)

Posted on 2004-04-25
6
Medium Priority
?
972 Views
Last Modified: 2010-04-01
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!
0
Comment
Question by:smileying
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 375 total points
ID: 10913531
its just the same as they are in Java..

<%@ page import="YOURPACKAGE.YOURCLASS "%>


<%
MyClass myclass= new MyClass();
%>
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10914592
Hi,

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,...,package.classN". This lets you specify what packages should be imported...

example....
<%@ page import="java.util.*, PakcageName.YourClass1" %>

R.K




0
 

Author Comment

by:smileying
ID: 10918731
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" %>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10919084
just
EmailPack.Email
no .class is necessay
0
 

Author Comment

by:smileying
ID: 10919100
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\classes\temp\Hello.class
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
0
 

Author Comment

by:smileying
ID: 10919113
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);

%>
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
I originally wrote this article to compare SARDU and YUMI, but have now added Easy2Boot, since that is the one I currently use and find the easiest to create and alter.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question