How to import  my own class in jsp file

I have a jsp file in jsp\ directory and a class in web-inf\classes\ directory. How do I import the class in jsp so i can use it in my jsp file. Thanks,

This is your lucky day, wennie.
The correct forum to post this is:
[http://forums.sun.com/forum.jspa?forumID=45]

Similar Messages

  • HELP: Import my own class in JSP ???

    Hi, all!
    I read many previous topics in this forum but no one works for me!
    Please someone help me!
    I'm using Tomcat 4.1.12 and my JSP scripts work just fine, but I need to import my own .class file. I just don't know where to put it so Tomcat can find it!?
    I have this environment variable:
    JAVA_HOME=.;c:\jdk1.3.1
    And in my code I'want to place something like this:
    <%@ page import="myClass" %>
    But I get a "can not resolve symbol" exception.
    Thanks for readind this, and please help if you can!
    Bye.
    adriano

    Within the Tomcat directory, under your application directory place the class file/s into the WEB-INF/classes directory. If your classes are part of a package place the entire directory structure of the package under the WEB-INF/classes directory.
    The import in the JSP is the same as for any Java class.
    Hope this solves your problem.

  • NullPointerException - importing my own class to JSP

    Hi.
    I'm writing a JSP page. I also made a class in WEB-INF/classes/org/MyXml.class. When I try to run this class from console, there is no problems at all. But if i try to use function from that class in JSP, i get this (the same error i get whichever function i try to use (btw, all functions are static, as they should be, right?)):
    java.lang.NullPointerException
         org.MyXml.CountProducts(MyXml.java:46)
         org.apache.jsp.index_jsp._jspService(index_jsp.java:75)
         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)
    I used this class like this:
    <%@ page import="org.MyXml" %>
    <%
    MyXml.CountProducts();
    %>
    I'm also a bit confused, it says that error is on line 46. Well, there's just a comment!
    Please help. Thanks.

    pqeuens,
    MyXml is his class. his methods are static, so, import="org.MyXml.*" won't work. It would either be import="org.*" or import="org.MyXml" (which he has)
    paull1911
    "What file are you looking at to find line 46? It is the java file (a servlet) corresponding to the jsp file."
    It should actually be in the org.MyXml.java file. The stack trace line is:
    java.lang.NullPointerException
    org.MyXml.CountProducts(MyXml.java:46)
    someone_
    You know from the above error line that the error is in MyXml.CountProducts method. After making sure you are working with the most up-to-date version of the class, (if that doesn't help you get a more accurate line number) walk through the CountProducts method and see where you might be trying to access an object that has not yet been instantiated (either using someObject.someMethodOrMember, or someArray[index])

  • How to import non-package class in JSP ?

    We have develped an enterprise solution in java 1.3 . Some of the controller and controller helper classes donot have any package structure. So they are been kept in web_inf/classes. When any jsp tries to refrence these classes class not found exception arise.
    One solution is to put these classes in package and write approprite import statement. But this involve lot of changes. Kindly suggest a solution which can have minimum impact.
    I have even jared all these classes into a jar and put that jar in the class path. But still its not working.

    It should not be web_inf , the case and the spelling matters it should be WEB-INF , make that correction and see if it works.
    If not then, use an IDE to refactor your code.
    Some good IDEs with refactoring capabilities are
    IntelliJ IDEA - commercial
    NetBeans - open source I think (not sure)
    Eclipse Web Tools - also open source
    Using packages is a good practice, and will make your application more understandable.
    Message was edited by:
    appy77

  • How to import my own package in my jsp?

    I am doing aproject now. I have finished the java source file and complied them successfully. I want to package all of them and import this package in my jsp files. I copy all the .java and .class files to tomcat/webapps/projsp/WEB-INF/classes/ directory. I also write one line in my jsp file as following:
    <%@ page language= "java" import="java.sql.*,java.util.*,java.io.*,induction.*" %>
    My package named induction. I guess the problem is abput the class path. I don't know how can system find the package of mine. Hopefully, someone can help me!
    Below is The error information when I run my jsp:
    Internal Servlet Error:
    org.apache.jasper.JasperException: Unable to compile Note: sun.tools.javac.Main has been deprecated.
    /usr/local/tomcat/work/DEFAULT/projsp/jsp/geography_1.java:9: Package induction not found in import.
    import induction.*;
    ^
    1 error, 1 warning
    at org.apache.tomcat.facade.JasperLiaison.javac(JspInterceptor.java:898)
    at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:733)
    at org.apache.tomcat.facade.JspInterceptor.requestMap(JspInterceptor.java:506)
    at org.apache.tomcat.core.ContextManager.processRequest(ContextManager.java:968)
    at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:875)
    at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
    at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
    at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
    at java.lang.Thread.run(Thread.java:536)

    Hi!
    Yes! You should create induction subdirectory in classes or
    archive induction subdirectory in a jar file and store it in lib
    subdirectory.
    Bye

  • How to import user defined class in UIX page?

    Does anyone know how to import user defined class in UIX page so that the class can be called in the javascript in the UIX ?
    Thks & Rgds,
    Benny

    what you are referring to is not javascript.
    it is JSP scriptlets. These are very different.
    In order to keep a strict separation between View and Controller, it is not possible to run arbitrary java code from within your UIX code.
    However, you can run java code from within a UIX event handler; see:
    http://otn.oracle.com/jdeveloper/help/topic?inOHW=true&linkHelp=false&file=jar%3Afile%3A/u01/app/oracle/product/IAS904/j2ee/OC4J_ohw/applications/jdeveloper904/jdeveloper/helpsets/jdeveloper/uixhelp.jar!/uixdevguide/introducingbaja.html
    event handler code is run before the page is rendered.

  • Getting intermedia classes in jsp file

    Hi,
    I am using oracle intermedia classes in jsp file.I am importing the package 'oracle.ord.im' , and when running it is telling that the package is not available.
    I installed intermedia with oracle 10g, and i am using tomcat server,i don't know why it is saying that package is not availabe.
    can any one tell me how to access that package in a jsp file

    See my reply to your duplicate query

  • How to import data from excel or csv files to Oracle table

    hello everybody,
    I am new here and new in Oracle. I would like to know the steps how to import data from excel or csv files to Oracle table.
    Let say I already have table inside the Oracle. Then my user give me the sets of data inside the Excel Worksheet.
    So, how can I import the excel data into Oracle table.
    Thank you in advance.
    cheers,
    shima

    Even easier. Download JDeveloper 11G from this site.
    Set up the database connection, right click on the table, select Import->Excel and specify your file to load it. On the import pop-up, you must view and update each tab indicating Columns, Data Types, and DML.
    Columns -- move the selected columns that you want to load to the box on the right
    Data Types -- select column name from second column to which the data for each column of the import file should load
    DML -- click this tab to generate the INSERT SQL
    Once done click 'Insert'

  • How to import a java class in a JSP

    Hi All,
    I have a java class file called myTest.class (i made after compilation of myTest.java). I have a JSP page that uses this java class file.
    These 2 files are in same folder called c:/test
    and iam importing this java class file into my jsp file and that too at the start of this jsp file:
    <%@page import="myTest" %>
    BUt iam getting an error ..............when iam running this JSP page:
    /opt/bea81sp2/user_projects/domains/wliDomain/./Managed2/.wlnotdelete/extract/Managed2_myTest_myTest/jsp_servlet/__test.java:20: '.' expected
    probably occurred due to an error in /test.jsp line 5:
    <%@page import="myTest" %>
    Please advise how to solve this problem
    -sangita

    Don't bother with the import
    when iam not importing this class file into my JSP, then on my JSP, the class file is not found.
    Here is my code: and these 2 class file are in c:/test
    import org.apache.tools.ant.taskdefs.Ant;
    import org.apache.tools.ant.taskdefs.Property;
    import org.apache.tools.ant.types.*;
    import org.apache.tools.ant.*;
    import org.apache.tools.ant.taskdefs.ExecTask;
    import org.apache.tools.ant.types.Commandline;
    import java.io.File;
    * Creates an Ant project to run an Ant build
    * @author myself
    * @version 1.0
    public class RunTest extends Ant {
        String applicationName;
        String buttonClicked;
        String boxName;
        String targetName;
        public void applicationName(String applicationName){
         this.applicationName = applicationName;
        public void boxName(String boxName){
         this.boxName = boxName;
        public void buttonClicked(String buttonClicked){
         this.buttonClicked = buttonClicked;
      public RunTest() {
    public void goTest() {
         if(this.buttonClicked.equalsIgnoreCase("deploy") && this.applicationName.equalsIgnoreCase("scsmail") && this.boxName.equalsIgnoreCase("testnet")){
           this.targetName = "deploy-scsmail-testnet";
         if(this.buttonClicked.equalsIgnoreCase("undeploy") && this.applicationName.equalsIgnoreCase("scsmail") && this.boxName.equalsIgnoreCase("testnet")){
           this.targetName = "undeploy-scsmail-testnet";
        Project project = new Project();
        project.init();
        System.out.println("printing 1 ....");
        ExecTask exec = new ExecTask();
        exec.setProject(project);
        exec.setExecutable("/opt/bea/weblogic81/server/bin/ant.bat");
         exec.setDir(new java.io.File("/export/home/beamon/bin"));
         Commandline.Argument arg = exec.createArg();
         // arg.setLine("-f scsmail.xml test -listener org.apache.tools.ant.XmlLogger -logfile D:/antProject/src/log.xml");
         arg.setLine("-f build.xml "+ targetName + " -listener org.apache.tools.ant.XmlLogger -logfile /export/home/beamon/bin/log.xml");
         System.out.println("printing 2....");
        //exec.setOutput(new File("D:/antProject/logs/prob.txt"));
        exec.execute();
        System.out.println("printing 3....");
    -----------------------the JSP page is called as test.jsp
    <%@page contentType="text/html" %>
    <%@page import="java.io.*" %>
    <%@page import="java.util.*" %>
    <%@page import="java.net.*" %>
    <%@page import="RunTest" %>
    <HTML>
    <TITLE>TESTING ANT GUI</TITLE>
    <HEAD>
    <META HTTP-EQUIV="Refresh" CONTENT="3000" >
    <meta http-equiv="Cache-Control" content="no-cache">
    </HEAD>
    <BODY BGCOLOR="silver" TEXT="333333">
    <table border=0>
    <tr align="left"><td align="left"><FONT SIZE="-1"><B>  Test Page <FONT SIZE="-1"><B></td></tr>
    </table>
    <hr></center>
    <form action="./test.jsp" method="POST" name="testForm">
    <table>
    <tr>
    <td>
    <select name="appName" size=1>
    <option value="">Select Application Name
    <option value="scsmail">scsMail
    <option value="clientmanager">ClientManager
    </select>
    </td>
    <td>
    <select name="boxName" size=1>
    <option value="">Select Box Name
    <option value="testnet">TestNet
    <option value="production">Production
    </select>
    </td>
    </table>
    <table>
    <input type="submit" name="deploy" value="deploy">
    <input type="submit" name="undeploy" value="undeploy">
    </table>
    <%
       RunTest rt = new RunTest();
       rt.applicationName(request.getParameter("appName"));
        String deployButton = "";
        deployButton=request.getParameter("deploy");
        String undeployButton = "";
        undeployButton=request.getParameter("undeploy");
        if(!deployButton.equalsIgnoreCase("")){
            rt.buttonClicked(request.getParameter("deployButton"));
        if(!undeployButton.equalsIgnoreCase("")){
            rt.buttonClicked(request.getParameter("undeployButton"));
       rt.boxName(request.getParameter("boxName"));
        rt.goTest();
    %>
    </form>
    </table>
    </BODY>
    </HTML>

  • Help - import own classes in jsp

    Hey guys..
    I'm working on a Shopping cat project which is in the directory -
    C:\Tomcat 6\webapps\ROOT\cart
    I've written one code in shop-product.jsp as below -
    <%@ page language = "java" contentType = "text/html"
             import = "ShoppingBasket, Product, java.sql.*"
             errorPage = "errorpage.jsp" %>
    <html>
    <head> <title>Welcome to Shop</title></head>
    <body>
    <table width = "385" border="0" cellspacing="0">
    <tr>
    <td colspan="4">More Books from me</td>
    </tr><tr>
    <td colspan="4" align ="right">
    <a href = "<%=response.encodeURL("shop-basket.jsp") %>"> View Basket </a></td>
    </tr><tr>
    <td><b>Ref</b></td><b>Title</b></td>
    <td><b>Price</b></td></td></tr>
    <%
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    Connection connection = null;
    connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop", "root", "rahul");
    Statement stmt = null;
    ResultSet RS = null;
    stmt = connection.createStatement();
    RS = stmt.executeQuery("select * from items");
    int rowCounter = 0;
        while(RS.next())
          String item_id = RS.getString("id");
          String title = RS.getString("title");
          String desc = RS.getString("desc");
          String price = RS.getString("price");
          rowCounter=rowCounter+1;
          String bg=  (rowCounter % 2 !=0) ?"#C0C0C0":"#ffffff";
    %>
    <tr bgcolor = <%=bg%>">
    <td><%=item_id%></td>
    <td><b><%=title %></b><br/><%=desc%></td>
    <td><b><%=price %></b></td>
    <td>
    <a href =" <% response.encodeURL("shop-products.jsp?title="+title+"&item_id="+item_id+"&price="+price); %> "> Add to Cart </a></td>
    </tr>
    <% } RS.close(); connection.close(); %>
    </table>
    <jsp:useBean id = "basket" class = "ShoppingBasket" scope = "session"/>
    <% String title = request.getParameter("title");
       if(title!=null)
         String item_id = request.getParameter("item_id");
         double price = Double.parseDouble(request.getParameter("price"));
         Product item = new Product (item_id, title, price);
         basket.addProduct(item);
    %>
    </body></html>{code}
    in which ShoppingBasket and Product are the classes which I want to import. Where should I put those class files if my project path is 
    +C:\Tomcat 6\webapps\ROOT\cart+
    I've put class files into Tomcat_home/lib but it is giving me error
    {code}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:
    An error occurred at line: 6 in the generated java file
    The import ShoppingBasket cannot be resolved
    An error occurred at line: 7 in the generated java file
    The import Product cannot be resolved
    An error occurred at line: 62 in the jsp file: /cart/shop-products.jsp
    The method addProduct(Product) in the type ShoppingBasket is not applicable for the arguments (Product)
    59:      String item_id = request.getParameter("item_id");
    60:      double price = Double.parseDouble(request.getParameter("price"));
    61:      Product item = new Product (item_id, title, price);
    62:      basket.addProduct(item);
    63:    }
    64: %>
    65: </body></html>
    Stacktrace:
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
         org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.{code}
    Please assist me on, how to import my custom made class files..
    Thanks,
    Rahul...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    What You need to do is to place ShoppingBasket class in a package and import to fully qualified class name (which is class name with package name). I also discourage You to use scriptlets - it's an obsolete, old technology.

  • How to use class in JSP file?

    Hello All,
    I am new to Jsp.
    In Jsp file,I used class of myself.
    Why,the Constractor seems not working?
    Thanks in advance.

    Hi,
    You can import the class in a jsp file.
    Use <% page import = "">
    and call that class.
    If u want to import a funtion in your class, then u can insert that into scriplets like <%! ..%>
    Hope u got that!
    Artz

  • ADF : How to import a java class in jspx page

    Hi All,
    In jsp we have page directive to import a java class. Do we have anything similar to that in a jspx page?

    Hello,
    If you create a new jspx file in jdeveloper, the untitled file generated will be this:
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1">
    <jsp:output omit-xml-declaration="true" doctype-root-element="HTML"
    doctype-system="http://www.w3.org/TR/html4/loose.dtd"
    doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
    <jsp:directive.page contentType="text/html;charset=UTF-8" import="java.util.*"/>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>untitled1</title>
    </head>
    <body></body>
    </html>
    </jsp:root>
    You can see the page directive there!

  • Importing my own classes

    I have 2 simple classes in the same directory and I'd like to test the use of import to import one class into the other. Upon compilation of the class thats doing the import, I get a compilation error. Herewith the details, where could I be getting it wrong.
    ****code for class to be imported****
    import java.util.Date;
    public class printer
    public void print()
    System.out.println(new Date());
    System.out.println("Hello World");
    --The above code compiles with no problems.
    ***Code for the main class that imports the above*****
    import printer;
    public class myapp
    public static void main(String[] args)
    (new printer()).print();
    -upon compiling the second class above, myapp.java, I get the following errors:
    C:\java\source>javac myapp.java
    myapp.java:1: '.' expected
    import printer;
    ^
    myapp.java:1: ';' expected
    import printer;
    ^
    2 errors

    Moreover, classes do not need to import any class which is in the same package as their own, and since your printer class is in the default package (if you call that a package) you shouldn't need to import it into myapp anyway

  • Problem to Import my own classes

    I try to import own classes to unother class
    I have all classes in the same map
    import StockTablePanel;
    when I tried to compile the code it says
    �.� expected
    StockTablePanel;
    What is wrong?

    I try to import own classes to unother class
    I have all classes in the same mapAlso if by the same map you mean the same folder then you don't even have to import the class.

  • How to import a java class

    Hi
    I want to know how can i import some java classes to my application.
    I'm trying to write a little class as:
    package paco.view;
    import javax.faces.component.UIComponent;
    import javax.faces.context.FacesContext;
    import javax.faces.convert.Converter;
    import javax.faces.convert.ConverterException;
    import oracle.jbo.domain.ClobDomain;
    public class ClobConverter implements Converter {
    public ClobConverter() {
    public Object getAsObject(FacesContext context,
    UIComponent component,
    String value) {
    if (context == null || component == null) {
    throw new NullPointerException("FacesContext and UIComponent can not be null");
    if (value == null) {
    return null;
    try {
    return new ClobDomain(value);
    } catch (Exception ex) {
    final String message =
    String.format("Unable to convert boolean value \"%s\" into a oracle.jbo.domain.Number",
    value);
    throw new ConverterException(message, ex);
    public String getAsString(FacesContext context,
    UIComponent component,
    Object value) {
    if (context == null || component == null) {
    throw new NullPointerException("FacesContext and UIComponent can not be null");
    return value.toString();
    but I'got this message:
    Error(3,8): class javax.faces.component.UIComponent not found
    Error(4,8): class javax.faces.context.FacesContext not found
    Error(5,8): class javax.faces.convert.Converter not found
    Error(6,8): class javax.faces.convert.ConverterException not found
    What should I do?
    Thanks in advance
    FRANCISCO

    You need to add the faces library to you project. To do this, select the project properties, go to libraries and class path and select the faces library.
    Using JDev you can also choose one or more project technologies (project properties->technology scope) which will add the needed libraries to the project.
    Timo

Maybe you are looking for