Jsp:usebean, @page import & CLASSPATH

I hav given jsp:usebean for using the classes and then used import package mypack.* in my jsp file. But this is not recognised. I tried putting mypack (which has the class files) in webapps/ROOT/WEB-INF/classes. Still it is not working. My jsp working directory is /usr/tomcat405/webapps/examples/jsp/mydir wher my jsp file resides. I tried giving this dir in CLASSPATH and exported it in my .bashrc file in my linux system. Still the import is not working. What could b the reason?

If you put your jsp in the examples context, then put your classes into
/usr/tomcat405/webapps/examples/WEB-INF/classes/mypack
This should work even without the import line because the "classes" directory is in Tomcat's classpath.
Also be aware of case sensitivity.
hav given jsp:usebean you should use
<jsp:useBean (upper case B)

Similar Messages

  • Which one better to use - jsp:useBean or import statement

    Hi,
    I just want to know that which one is better to use jsp:useBean or import statement .
    I can instantiate and call method of myclass -
    1) by importing the class through import tag in jsp as <%@page import="myclass"%. or
    2). by using <jsp:useBean tag....
    i have these two option to do the same thing. i know that basically useBean is used to call setter and getter method of bean class and but it can be used to call a normal java file that have some logic .
    so what should i used , which one is better and why?
    useBean provides scope and object instance so no need to create object by new operator. and with import you have to create an instance .
    but which tag should i use in my jsp?
    i am confused???

    ok, means i can use jsp:useBean tag for all my
    classes that are not actually bean. so it will be
    instantiated at run time and provide efficiency .No. Jsp:useBean is used for java bean components.
    >
    but when should i use import statement in my jsp and
    it happen at translation time so will it create any
    type of burden for my code if i import multiple
    classes.For non-java beans, you need to import the classes, period.
    It's not a burden, it's a necessity.

  • Access Java class in my JSP/JSF page and conditionally open a new browser

    When the user clicks on a button in my JSP page, I'd like to launch a new browser and display certain things in that browser window while leaving the original browser window open.
    My thought was to invoke a javascript method in 'onLoad' which would determine if the new window needs to be launched.
    This is kinda what my page looks like:
    <jsp:root version="1.2" ................>
        <jsp:directive.page import="java.util.*, com.test.Configuration" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
        <f:view>
         <ui:body binding="#{Page1.body1}" id="body1" onLoad="launchWindow();">     
         </ui:body>
       </f:view>
       <script type="text/javascript">
            function launchWindow(){
             if (Configuration.openWindow()) {
              window.open("hello.jsp", "newWindow", 'toolbar,width=400,height=400');            
        </script>     
    </jsp:root>My problem is that the call to "Configuration.openWindow()" does not resolve correctly. If I remove that call and simply make a call to "window.open()" all works. But once I put the condition in, nothing happens. I do not see an exception in my browser window but a new browser window does not open.
    Is my syntax correct. Can I make a call to the static method 'openWindow()' in my class 'Configuration.java'.
    thanks,
    tsc

    I have made some changes so that I do not directly access the 'Configuration' class in my javascript.
    I have a hidden field on my form and when the user clicks the button, in my back bean, I set a value for the hidden field. In the javascript function 'launchWindow()' I check if a value has been set for the hidden field and if yes, I open a new window.
    <ui:body binding="#{Page1.body1}" id="body1" onLoad="launchWindow(document.forms[0]);">
    <h:inputText id="hiddenField" value="#{formBean.hiddenValue}" />
    <script type="text/javascript">
            function launchWindow(form){
                alert("in lw");
                var test = form["form1:hiddenField"].value;
                alert("got test");
                if (test !=  "")
                    window.open("hello.jsp", "newWindow", 'toolbar,width=400,height=400');            
                alert ("done test");
    </script>When my page is first loaded, the launchWindow() is called and all the alerts popup as expected.
    When I click on the button (the back bean sets the value on the hidden field), my page is reloaded but this time its blank.
    Any ideas as to why this maybe the case?
    thanks,
    tsc

  • JSP tag for import

    Hi,
    I have a problem while trying to import java classes using
    <jsp:directive.page import....... tag.
    though the <%@page import = ....... tag works fine...
    any help would be appreciated..

    I can just tell you that this is not working.
    Some of the XML JSP tags are simply not implemented by all servlet engines.

  • Help in jsp registration page/form

    hello! i am new with jsp. and i am having problems with my registration page. i does't seem to add data into my database and worse, it doesn't seem to connect to the database. appreciate the help. thanks.
    registration.jsp
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ page import="java.sql.*" %>
    <%
        String connectionURL = "jdbc:mysql://localhost:3306/petdepot?user=root&password=12345";
        Connection connection = null;
        Statement statement = null;
        ResultSet rs = null;
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        connection = DriverManager.getConnection(connectionURL, "root", "12345");
        statement = connection.createStatement();
    %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Pet Depot</title>
    </head>
    <body>
    <%
        String uname = "";
        String pwrd = "";
        String pwrd2 = "";
        String dbname = "";
        String dbaddress = "";
        String dbcontactNo = "";
        String dbemailAd= "";
        String dbnote="";
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String password2 = request.getParameter("password2");
        String name = request.getParameter("name");
        String address = request.getParameter("address");
        String emailAd = request.getParameter("emailAd");
        String contactNo = request.getParameter("contactNo");
        String note="";
        if ((username!=null)&&(password!=null))
                if ((username== "")||(password== "") ||(name== "")|| (address== "") || (emailAd== "")||(contactNo== "") )
                    note = "Please complete all the fields.";
                if ((username== "")&& (password== "") && (name== "")&& (address== "") && (emailAd== "")&& (contactNo== "") )
                    note = "You did not enter any information. Fill-up the form to register.";
                else if ((username!= "")&& (password!= "") && (password2!= "") &&(name!= "") && (address!= "") && (emailAd!= "") && (contactNo!= "") )
                    int pwdOneLength = password.length();
                    int pwdTwoLength = password2.length();
                    if (pwdOneLength == pwdTwoLength )
                        if ((pwdOneLength >= 6))
                            if (password.equals(password2))
                                String found = "NO" ;
                                rs = statement.executeQuery("Select * from useraccounts where username = '"+username+"' ");
                                try{
                                while(rs.next())
                                    found = "YES";                             
                                }catch(SQLException e){out.println(e.getMessage());}
                                if ( found.equals("NO"))
                                        statement.executeUpdate("Insert into useraccounts (username, password) values('"+username+"','"+password+"'");
                                        statement.executeUpdate("Insert into userprofile (name,address,contactNo, EmailAd) values ('"+name+"','"+address+"', '"+contactNo+"', '"+emailAd+"'");
                                        username = "";
                                        password = "";
                                        password2 = "";
                                        name = "";
                                        address = "";
                                        emailAd = "";
                                        contactNo = "";    
                                else
                                    note = " <span class=\"style1\">The username you entered is already in use. Change your username </span> ";
                            else
                                note = " <span class=\"style1\">Please enter the password and the password confirmation correctly.</span> ";
                    if ((username== null)|| (password== null) || (address== null) || (name== null) || (emailAd== null) || (contactNo== null) )
                password = "";       
                password2 = "";
                if (username== null)
               {    username = ""; }
                if (address== null)
                {  address = ""; }
                if (name== null)
                {  name = ""; }
                if (contactNo== null)
                {  contactNo = ""; }
                if (emailAd == null)
                {  emailAd = ""; }
    %>
           <p>REGISTRATION FORM   <br> <br> <%= note %></p>
           <p>Fill-up all the fields below and click the SUBMIT button </p>
    <form id="form1" name="form1" method="post" action="">
      <label>username: 
      <input name="username" type="text" id="username" /></label>
      <p>
        <label>password:
        <input name="password" type="password" id="password" />
        </label>
    </p>
      <p>
        <label></label>
      </p>
      <p>
        <label>Name:
        <input name="name" type="text" id="name" />
        </label>
    </p>
      <p>
        <label></label>Address:
        <input name="address" type="text" id="address" />
      </p>
      <p>Email Address:
        <input name="emailAd" type="text" id="emailAd" />
      </p>
      <p>ContactNos:
        <input name="contactNo" type="text" id="contactNo" />
    </p>
      <p> </p>
      <p> </p>
      <table width="396" border="0">
        <tr>
          <td width="46"> </td>
          <td width="144"><input name="uname" type="text" id="uname" /></td>
        </tr>
        <tr>
          <td> </td>
          <td> </td>
        </tr>
      </table>
      <p>   </p>
      <p>
        <label>
        <input type="submit" name="Submit" value="Submit" />
        </label>
      </p>
    </form>
    </body>
    </html>

    String connectionURL = "jdbc:mysql://localhost:3306/petdepot?user=root&password=12345";The connectionURL is WRONG
    Probably it could be like ..
    String connectionURL = "jdbc:mysql://localhost:3306/petdepot"
    I hope petdepot is your DB name and mysql is installed locally on your machine.
    Class.forName("com.mysql.jdbc.Driver").newInstance();Remove .newInstance() and it should be ..
    Class.forName("com.mysql.jdbc.Driver");
    I suggest you make a java bean for DBConnection as below ..
    package yourpackage;
    import java.sql.DriverManager;
    import java.sql.Connection;
    import java.sql.SQLException;
    * The class file will be responsible for returning the database connection information.
    * @author Rohit Kumar
    * @version 1.0
    * @date 17-Dec-2004
    public class DbConnection
         * This method shall be used for getting Client Connection.
         * @return Connection
         * @throws Exception
        public Connection getClientConnection() throws Exception
            try
                Class.forName(ApplicationPropertyRead.getProperty("DBDRIVER"));
            catch (Exception e)
                System.out.println("Exception :"+e);
            Connection oCon=DriverManager.getConnection(ApplicationPropertyRead.getProperty("DBURL"),
                                                        ApplicationPropertyRead.getProperty("DBUSER"),
                                                        ApplicationPropertyRead.getProperty("DBPASSWORD"));
            return oCon;
    }Instead of my method call ApplicationPropertyRead.getProperty("..") you may hardcode it for now as you are learning JSP.
    Then check if your connection is successful or not in your JSP.
    <%@ page import="yourpackage.DbConnection*" %>
    <%
    DbConnection dbConn = new DbConnection()
    Connection connection = null;
    try
         Connection connection = dbConn.getClientConnection();
        System.out.println("connection :"connection);
    catch (Exception e)
        System.out.println("Exception Error :" + e);
    finally
         if (connection != null)
              connection.close();
    %>Only if the above steps is successful then you should proceed with DB transactions.
    Regards
    Rohit

  • Jsp:useBean vs page import in JSP

    Hi,
    What is the difference between jsp:useBean vs page import in JSP?
    By using page import also I can call the method of the class, apart from jsp:useBean does have scope associated with it. I don't think there is any change between both the 2. Yes by using jsp:useBean we can set the property and get the property as well.
    Is there any major differences between the 2 and when to use which ? Please clarify.
    Thanks.

    797836 wrote:
    Hi,
    What is the difference between jsp:useBean vs page import in JSP?
    By using page import also I can call the method of the class, apart from jsp:useBean does have scope associated with it. I don't think there is any change between both the 2. Yes by using jsp:useBean we can set the property and get the property as well.
    Is there any major differences between the 2 and when to use which ? Please clarify.
    Thanks.Yes there is a difference.
    If you use import, then you have to create/use the reference object to use the class methods. And you can't define the scopes like session, page .. etc. Apart from this you will be using scriptlets <% %>.
    if you are using jsp:useBean , then you can skip the above activities. useBean takes care of it.
    or you can say jsp has provided a utility to access the beans without creating its object or using scriptlets.

  • @ page import=..... OR jsp:useBean id.....

    I'm a newbie in JSP, and I found uses <@ page import=.....> to run the java (*.class) is similar as uses <jsp:useBean id.....>, can anyone tell me what's the different between them??
    Thx a lot~

    I didn't find any necessary to use "import" tag before use "<jsp:useBean...>" when I used "Weblogic 5.1/6.0", "JRun 3.0/3.1". But I'm sure "Tomcat4.0" have to "import" first. Some documents showed the "import" tag was not necessary in "Tomcat" before version "4.0". I don't know the special feature from this version is good or not. Could someone tell me whether it's the future feature in JSP?

  • A  classpath error while  importing a class with @page import property

    Hi ,
    I am using Tomcat contaniner for jsp applications. I have developed a page that i have import a class. when i use
    <%@ page import="myclass" &>
    i got an error that myclass not found. I have placed into tomcat\webapps\myproject\web-inf\classes directory. So How will I set the classpath for myclass to work?
    thanks.

    I was able to simulate your problem when I created a mismatch in the case of the name of the class.
    for example if my program is called MyClass.java
    and in the import I do <@page import="myclass" %>
    Are you sure about the case of class name that you are using? Please check that the file is called myclass.java the class defined inside it is called myclass and the class file that is copied into the WEB-INF/classes directory is also myclass.class. There should be no difference in the case of the names. like MyClass.java or MyclaSS.class
    Other things to check are
    1. If myclass is defined in a package then you have to import with the package.
    2. Make sure that your jsp is located in the myprojects directory and the class file is copied under myprojects/WEB-INF/classes.
    Let me know if things still don't work
    regards,
    Abhishek.

  • JSP page import problems

    Hi,
    i've got a problem with importing java classes into my jsp file. i use the following method:
    <%@ page import="Person" %>
    Person is originally a selfwritten class which lies in the subdirectory WEB-INF/classes of my webapps directory of my tomcat server. when i use the above method i get the following error output:
    org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 125 in the jsp file: /ShowPersonsView.jsp Generated servlet error:
    [javac] Compiling 1 source file 3 3 /usr/local/tomcat/work/Standalone/localhost/address/ShowPersonsView_jsp.java:7: '.' expected
    import Person;
    ^
    /usr/local/tomcat/work/Standalone/localhost/address/ShowPersonsView_jsp.java:231: cannot resolve symbol
    symbol : class Person
    location: class org.apache.jsp.ShowPersonsView_jsp
    Person tempperson;
    ^ An error occurred at line: 125 in the jsp file: /ShowPersonsView.jsp Generated servlet error:
    /usr/local/tomcat/work/Standalone/localhost/address/ShowPersonsView_jsp.java:238: cannot resolve symbol
    symbol : class Person
    location: class org.apache.jsp.ShowPersonsView_jsp
    tempperson = (Person)it.next();
    ^
    3 errors at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:120)
    at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
    at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:313)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:324)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:474)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:184)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
    at ShowPersonsPrepare.doGet(ShowPersonsPrepare.java:51)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:380)
    at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:533)
    at java.lang.Thread.run(Thread.java:536)
    Thus, the Person class can not be found but i dunno why. Where do I have to make an entry? I already tried to set a classpath to this file, but it doesn't work. Has anyone an idea?
    Thanx

    Put the class in a package and call it accordingly. Example:
    WEB-INF
       |
        --- classes
               |
                --- example
                       |
                        --- Person.java
    //then in Person add:
    package example;
    //and in jsp
    <%@ page import="example.Person" %>

  • Trying to page import directive in a JSP  access a class in default package

    I am trying to import a class the is in my default package directory for Tomcat 4.1.18 (context-root\web-inf\classes\*.java). I am getting the following error
    This is error using Tomcat 4.1.18
    org.apache.jasper.JasperException:Unable to compile class for JSP
    C:\Program Files\Tomcat4.1\work\Standalone\localhost\csc297\HTML\SearchByName_jsp.java:9: '.' expected
    import Product;
    C:\Program Files\Tomcat4.1\work\Standalone\localhost\csc297\HTML\SearchByName_jsp.java:10: '.' expected
    import Category;
    This is error using Tomcat 4.0.6
    org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
    C:\forte4j\tomcat401\work\localhost\C_3A_5Cforte4j_5Ctomcat401_5Cwebapps_5Ccsc297\HTML\SearchByName$jsp.java:5: Class Product not found in import.
    import Product;
    ^
    C:\forte4j\tomcat401\work\localhost\C_3A_5Cforte4j_5Ctomcat401_5Cwebapps_5Ccsc297\HTML\SearchByName$jsp.java:6: Class Category not found in import.
    import Category;
    Here is snippet of code from my JSP:
    <%@ page import= "java.util.*"%>
    <%@ page import= "java.text.DecimalFormat"%>
    <%@ page import="Product"%>
    <%@ page import="Category"%>
    Remember these classes are in my default package of my context-root
    Any ideas would greatly appreciated

    Weird error. Never seen this one before.
    Try packaging your classes eg:package myClasses;and import them:<%@page import="myClasses.*"%>Should fix the problem.
    Anthony

  • JSP page import directive

    I'm running JSPs and servlets under Netscape (Tomcat) web server and am getting errors with my jsp file's first line:
    [%@page import="java.util.*, myclass" %]
    Netscape server throws an error saying that it can't import myclass. I've put the myclass.class file in various locations in the server but it still can't find it. Does anyone know a foolproof way to make the server find such a class when it's compiling jsp's?
    Thanks,
    David

    I think you have to specify package name of your class & not your calss name.

  • How can i load A gui JTable bean through jsp:useBean tag in a jsp page

    Hi,
    i am chiranjit , i am in a jsp project . i am desparately looking a solution for below stated problem:
    i want to make a jsp page for master entry , that why i want to load a GUI Java bean in my jsp page.This GUI Bean contaning a JTable in which allow grid type data entry in the jsp page. But i am unable load that bean in the jsp page through jsp:useBean tag in my page.So if you have any solution then send in the forum as early as possible.
    Thank you
    chiranjit

    No can do. JSPs can only output plain HTML (and javascript...) They are not used like normal Java classes.
    If you need a complex GUI then you might use an Applet instead. If you want to use a JSP then you are stuck using normal HTML components, like <table> <form...> <input type="text"> etc...

  • jsp:useBean error== The value for useBean class is invalid

    Can anybody tell me why am i getting the error for the JavaBean.
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: /SimpleBean.jsp(9,0) The value for the useBean class attribute com.stardeveloper.bean.test.SimpleBean is invalid.
         org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
         org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
         org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
         org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1272)
         org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
         org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
         org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
         org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
         org.apache.jasper.compiler.Generator.generate(Generator.java:3426)
         org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:216)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
         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.20 logs.
    Apache Tomcat/6.0.20
    my jsp file is in path c:\tomcat6\webapps\dev\SimpleBean.jsp
    my JavaBean compiled class is in path
    c:\tomcat6\webapps\dev\WEB-INF\classes\com\stardeveloper\bean\test\SimpleBean.class
    and my SimpleBean java class declaration is
    package com.stardeveloper.bean.test;
    public class SimpleBean implements java.io.Serializable
    and my jsp page SimpleBean.jsp pages call to useBean is as follows
    <jsp:useBean id="simple" class="com.stardeveloper.bean.test.SimpleBean">
         <jsp:setProperty name="simple" property="name" value="Sujoy" />
         <jsp:setProperty name="simple" property="age" value="26" />
    </jsp:useBean>
    Please help me anybody.

    First, try restarting Tomcat :-)
    Main 3 reasons for "useBean class is invalid"
    - class must be in a package (ok)
    - class must be public, and have public constructor that takes no arguments (check)
    - class must be compiled, valid and on the classpath. Normally this means the WEB-INF/classes directory.
    From what you have told us, everything seems to check out.
    Try recompiling the .class file to ensure it is valid.
    Does your constructor do anything which might thrown an exception?
    Can you invoke it in scriptlet code without getting an exception?
    <%@ page import="com.stardeveloper.bean.test.SimpleBean" %>
    <% SimpleBean sb = new SimpleBean() %>Trying it in scriptlet code like this might give you a different error message that might help your diagnosis.
    cheers,
    evnafets

  • Use classes in JSP without jsp:useBean

    hi
    i want to instantiate my own classes within a jsp.
    the classes are in web-inf/classes/chat/
    there is one main class which is used all over the app, so i use it with the jsp:useBean and scope on application.
    The messages are saved in objects of the class Message. now i want to use this class in my JSP without useBean.
    Is this possible without extra setting the classpath?!
    I get the error because the interpreter searchs in a package from tomcat itself..
    Thanks a lot and rgds
    Ruven

    I think you can use any class in your jsp file without the <jsp:useBean>, this implies that you have to declare your class in the ordinary way i.e
    <% MyClass c = new MyClass() ;
    //other code
    %>
    the important thing is to use the page directive's import attribute i.e include this line in your jsp page
    <%@ page import="mypackage.inner.MyClass" %> the web containers when sees this line will assume that you have the following directory structure in your web application ( /mywebapps/web-inf/classes/mypackage.inner/* )
    I hope this helps
    Regards

  • Jsp:useBean and assigning a value to that bean

    Hello,
    I have a type called Country and I have declared a bean using the "jsp:useBean" syntax.
    I then try to assign a value to that bean in a scriptlet. Eventually I try to retrieve the values using "jsp:getProperty". The problem is that it appears to null.
    Here is the code of the jsp
    <%@ page language="java" %>
    <%@ page import="com.parispano.latinamericaguide.*" %>
    <%
    /* We retrieve the Countries object from the servlet context. */
    ServletContext sc = getServletContext();
    Countries cs = (Countries)sc.getAttribute("countries");
    %>
    <jsp:useBean id="country" class="com.parispano.latinamericaguide.Country"/>
    <%
    /* If the request contains a country id, then we set the variable. */
    country = cs.getCountryFromId(Integer.parseInt(request.getParameter("countryID")));
    %>
    <html>
    <head>
    <title>Country details</title>
    </head>
    <body>
    <table>
    <tr><td>Name</td><td><jsp:getProperty name="country" property="name"/><!-- This is not working--></td></tr>
    <table>
    <%
    out.println(country.getName());//This is working
    %>
    </body>
    </html>This is the code for the bean
    package com.parispano.latinamericaguide;
    * @author Julien Martin
    * Represents a country.
    public class Country implements Comparable {
         private int id;
         private String name;
         private int landArea;
         private String capital;
         private String currency;
         private String flag;
         private String internet_domain;
         private String dialling_code;
         private float literacy;
         private float male_life_expectancy;
         private float female_life_expectancy;
         private String map;
         private int population;
         private int population_year;
         private float birth_rate;
         private int birth_rate_year;
         private float death_rate;
         private int death_rate_year;
         private int gdp;
         private int gdp_per_head;
         private int gdp_year;
         private float unemployment_rate;
         private int unemployment_rate_year;
         public Country() {
         public Country(
              int id,
              String name,
              int landArea,
              String capital,
              String currency,
              String flag,
              String internet_domain,
              String dialling_code,
              float literacy,
              float male_life_expectancy,
              float female_life_expectancy,
              String map,
              int population,
              int population_year,
              float birth_rate,
              int birth_rate_year,
              float death_rate,
              int death_year_rate,
              int gdp,
              int gdp_year,
              float unemployment_rate,
              int unemployment_rate_year) {
              this.id = id;
              this.name = name;
              this.landArea = landArea;
              this.capital = capital;
              this.currency = currency;
              this.flag = flag;
              this.internet_domain = internet_domain;
              this.dialling_code = dialling_code;
              this.literacy = literacy;
              this.male_life_expectancy = male_life_expectancy;
              this.female_life_expectancy = female_life_expectancy;
              this.map = map;
              this.population = population;
              this.population_year = population_year;
              this.birth_rate = birth_rate;
              this.birth_rate_year = birth_rate_year;
              this.death_rate = death_rate;
              this.death_rate_year = death_year_rate;
              this.gdp = gdp;
              this.gdp_year = gdp_year;
              this.unemployment_rate = unemployment_rate;
              this.unemployment_rate_year = unemployment_rate_year;
         public float getBirth_rate() {
              return birth_rate;
         public int getBirth_rate_year() {
              return birth_rate_year;
         public String getCapital() {
              return capital;
         public String getCurrency() {
              return currency;
         public float getDeath_rate() {
              return death_rate;
         public int getDeath_rate_year() {
              return death_rate_year;
         public String getDialling_code() {
              return dialling_code;
         public float getFemale_life_expectancy() {
              return female_life_expectancy;
         public String getFlag() {
              return flag;
         public int getGdp() {
              return gdp;
         public int getGdp_per_head() {
              return gdp / population;
         public int getGdp_year() {
              return gdp_year;
         public int getId() {
              return id;
         public String getInternet_domain() {
              return internet_domain;
         public float getLiteracy() {
              return literacy;
         public float getMale_life_expectancy() {
              return male_life_expectancy;
         public String getMap() {
              return map;
         public String getName() {
              return name;
         public int getPopulation() {
              return population;
         public int getPopulation_year() {
              return population_year;
         public int getLandArea() {
              return landArea;
         public float getUnemployment_rate() {
              return unemployment_rate;
         public int getUnemployment_rate_year() {
              return unemployment_rate_year;
         public void setBirth_rate(float f) {
              birth_rate = f;
         public void setBirth_rate_year(int i) {
              birth_rate_year = i;
         public void setCapital(String string) {
              capital = string;
         public void setCurrency(String string) {
              currency = string;
         public void setDeath_rate(float f) {
              death_rate = f;
         public void setDeath_rate_year(int i) {
              death_rate_year = i;
         public void setDialling_code(String string) {
              dialling_code = string;
         public void setFemale_life_expectancy(float f) {
              female_life_expectancy = f;
         public void setFlag(String string) {
              flag = string;
         public void setGdp(int i) {
              gdp = i;
         public void setGdp_per_head(int i) {
              gdp_per_head = gdp/population;
         public void setGdp_year(int i) {
              gdp_year = i;
         public void setId(int i) {
              id = i;
         public void setInternet_domain(String string) {
              internet_domain = string;
         public void setLiteracy(float f) {
              literacy = f;
         public void setMale_life_expectancy(float f) {
              male_life_expectancy = f;
         public void setMap(String string) {
              map = string;
         public void setName(String string) {
              name = string;
         public void setPopulation(int i) {
              population = i;
         public void setPopulation_year(int i) {
              population_year = i;
         public void setlandArea(int i) {
              landArea = i;
         public void setUnemployement_rate(float f) {
              unemployment_rate = f;
         public void setUnemployment_rate_year(int i) {
              unemployment_rate_year = i;
         public String toString() {
              return name;
         public int compareTo(Object o) {
              Country c = (Country)o;
              int cmp = name.compareTo(c.name);
              System.out.println(cmp);
              return cmp;
    }Can anyone please help?
    Thanks in advance,
    Julien.

    Thanks,
    I have added scope="application". It still show "null" indicating that the bean is not initialized with the properties. I would like a quicker way to initialize a bean property than invoking the setProperty tag for each property.
    Here is a simple example that demonstrates the problem:
    <%@ page language="java" %>
    <%@ page import="com.tests.*" %>
    <jsp:useBean id="monBean" class="com.tests.MonBean" scope="application"/>
    <%
    MonBean mb = new MonBean();
    mb.setName("toto");
    monBean= mb;
    %>
    <html>
    <head>
    <title>Lomboz JSP</title>
    </head>
    <body bgcolor="#FFFFFF">
    <jsp:getProperty name="monBean" property="name"/>
    </body>
    </html>And the bean
    package com.tests;
    public class MonBean {
    private String name;
    public String getName() {
         return name;
    public void setName(String name) {
         this.name = name;
    }This show "null".
    Any other idea why this is not working?
    Thanks,
    Julien

Maybe you are looking for

  • How to call servlets in sunone webserver

    hi, I am using sunone web server , I deployed but how to call servlets in sunone webserver any one tell me bye

  • Web page redirecting to another page

    Hi, I have an issue of web pages redirecting to a specific web page (bad content). This issue occurred in safari first and then when i started using google chrome and firefox the same issue arrised. When i google something and open it in a new tab it

  • MRP - Quota arrangement

    Dear Sir, When I run MRP, System picks first BOM and Routing. here I need that system should pick some quantity say 60% from BOM Alt 1 and 40% BOM alt 2. Can i do this with quoata arrangement functionality. I am working with Repetitive manufacturing.

  • MPE GPU renders interlacing artifacts

    I got a 60D and a Sony DV for shooting videos of some events. And I shot the videos using the 60D with 720p50 setting, and the DV was on 1080i50. What I tried to do is to produce a DVD that will have "smooth" motion instead of the 25 fps feel. So I d

  • Workflow - real time

    Hi, Can some one give me common workflow senarious in the real time concerning vendor/customer/material.  2 or 3 senarios on each of vendor/customer/material will help me to have good insight of each specific workflows. Thanks