Jsp:useBean and Tomcat

Hi!
I have installed Tomcat as localhost and succeed in running scriplets. But now I want to try using jsp:useBean
I have compiled a simple class, test1.class and placed it under webapps/root together with the jsp-file.
When I use �
<jsp:useBean id="test1" scope="page" class="test1"/>
to start test1, Tomcat tries to find it in org.apache.jsp
Then I tried to add - package myFolder; - in test1 but it won�t work.
So! These are my questions.
Is it possible for Tomcat to find a class placed in the webapps/root folder?
Where can I find org/apache/jsp, is it in a .jar-file somewhere? I can�t fint it when I use - search files/folders.
Where should I place test1.class and how do I write the useBean-tag to make it work?
Thanks for any answer
Regards Peter

your beans should always be under /web-inf/classes
so if you want to put it in the root directory it should look like this
tomcat-path/webapps/root/web-inf/classes
in your jsp file, don't forget to import the bean i.e
<%@ page import="package_name.mybeans.*" %>
then use the jsb:useBean the way you did
<jsp:useBean id="test1" class="test1" scope="page" />
it should then work fine,
regards

Similar Messages

  • JSP useBean and Tomcat NoClassDefFoundError

    Hi,
    I have a webapp on tomcat whose structure is like this
    /tomcat
    --/webapps
    ----/mywebappname
    ------/WEB-INF
    --------/classes
    ----------MyBean.java
    When I use useBean class="MyBean" I get a NoClassDefFoundError for this particular class.
    I suspect this is some kind of classpath issue but do not know how to fix it. Help appreciated.

    place u'r class file in <tomcat-root>/classes folder.
    if there's no such folder ,u'll have to create it.

  • JSP:useBean in Tomcat with external libraries

    Hi!
    I would like to use netbeans 4.1 for developing jsp-pages, but are facing a problem when trying to use the built-in jsp compiler.
    in my code I use something like:
    <jsp:useBean id="id" class="package.Classname" scope="application" />while package is an external package initially created from JAXB. To include it into netbeans, I have put the directory containing all the classes into the build libraries and also into the test libraries. In the 'Projects'-Explorer it shows all the classes contained.
    When I try to run the jsp-File, I get an error like this:
    Compiling 1 source file to C:\Develop\ApplicationDescriptionGenerator\build\generated\classes
    C:\Develop\ApplicationDescriptionGenerator\build\generated\src\org\apache\jsp\general_jsp.java:48: cannot find symbol
    symbol: class Classname
    location packageI do not understand this behaviour, especially, as the 'web' folder created by netbeans includes all necessary classes, and when I copy it to my tomcat installation, it works fine.
    Does anybody know, what I have to change, so that I can test it from inside netbeans?
    Thanks a lot!

    Here is the java program or bean class that I'm using, UserData.java compiled into UserData.class:
    public class UserData {
    String username;
    String email;
    int age;
    public void setUsername( String value )
    username = value;
    public void setEmail( String value )
    email = value;
    public void setAge( int value )
    age = value;
    public String getUsername() { return username; }
    public String getEmail() { return email; }
    public int getAge() { return age; }
    To put the data into the session, I used the following form:
    <HTML>
    <BODY>
    <FORM METHOD=POST ACTION="SaveName.jsp">
    What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR>
    What's your e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20><BR>
    What's your age? <INPUT TYPE=TEXT NAME=age SIZE=4>
    <P><INPUT TYPE=SUBMIT>
    </FORM>
    </BODY>
    </HTML>
    and SaveName.jsp is this:
    <jsp:useBean id="user" class="UserData" scope="session"/>
    <jsp:setProperty name="user" property="*"/>
    <HTML>
    <BODY>
    Continue
    </BODY>
    </HTML>

  • Is there any difference between "jsp:useBean" and "scriptlet" ?

    A few days ago, I asked similar question. But I didn't get the answer I wanted.
    I want to know the differnce between <jsp:useBean../> and <% .. %>(scriptlet).
    I tested in three environments(Oracle Jserv, OC4J, and Apache Tomcat).
    In Oracle Jserv and OC4J, a problem occured. But, Apache Tomcat does not occur a problem.
    For example,
    1) TestClass.java (Bean)
    public class TestClass {
    private String txt;
    public class TestClass {
    txt = "Test"; ----- (g
    public String getTxt() {
    return txt;
    2) test.jsp
    <html><body>
    <% TestClass test = new TestClass(); %> ---(h
    <%= test.getTxt() %>
    </body></html>
    Assume that I visit "http://localhost:8888/test.jsp".
    In Tomcat, if I change "Test"(number(g) to "Test1" and compile the browser shows the change.
    But Oracle Jserv and OC4J does not do that. They also show the old String.
    So, I changed <% TestClass test = new TestClass(); %>(number(h) to <jsp:useBean id="test" class="TestClass" />. That is, I changed "Scriptlet" to "JSP useBean Tag".
    Then, Oracle Jserv and OC4J also show the changes.
    To conclude, is there any difference between "JSP useBean Tag" and "Scriptlet"?
    Can't I use a scriptlet (to make a class) in Oracle Servlet Engine?
    Thanks.

    It could be as simple as the JSP not recompiling between java recompiles - ie, it compiles in the link to the old class.
    Try changing the JSP file (add and delete a space) after you change the java code, and then see what happens.
    Jonny
    null

  • 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

  • Jsp:useBean and definition of bean inside jsp:declaration

    I use the following code where I define a bean in jsp:declaration
    Its name is localBean. the problem is that jsp:useBean causes
    a crash and my page is not working without understanding why.
    When I replace the localBean in the jsp:useBean with another Bean
    which is an actual class that resides in the system I have not a problem.
    Any suggestions???
    <HTML>
         <jsp:declaration>          
              static public class localBean {
                   private String value;
                   public String getValue() {
                        return value;
                   public void setValue(String value) {
                        this.value = value;
         </jsp:declaration>
         <jsp:useBean id="localBean" scope="page" class="localBean">
              <jsp:setProperty name="localBean" property="value" value="World"/>
         </jsp:useBean>
         <%-- Whatever HTTP parameters we have, try to set
              an analogous bean property -- %>          
         <jsp:setProperty name="localBean" property="*"/>
         <head>
              <title>Hello World JavaBean</title>
         </head>
         <body>
              <center>
                   <p><h1>
                        Hello
                        <jsp:getProperty name="localBean" property="value"/>
                   </h1></p>
                   <form method="post">
                        Enter a name to be greeted:
                        <input type="text" size="32" name="value"
                        value="<jsp:getProperty name='localBean' property='value'/>">
                        <br>
                        <input type="submit" value="submit"/>
                   </form>
              </center>
         </body>
    </html>          

    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

  • Running jsp using Beans (jsp:useBean) on Tomcat 3.2.1 on Linux 7.0

    Hi all,
    In which folder do I keep my java bean class files so that my jsp can use jsp:useBean tag while my jsp's are stored in /webapps/examples/jsp/seet folder.
    Thanks in advance.
    Seetesh

    If their just .class files put them into /webapps/project/WEB-INF/classes
    If they're packaged as a JAR put them into /webapps/project/WEB-INF/lib
    These folders are automatically added to Tomcats classpath.

  • 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

  • How to assign the class value dynamically  in jsp:useBean ?its urgent

    Hi
    I want to set the class value of <jsp:useBean> dynamically
    when i am trying to this way
    <jsp:useBean id="<%=id %>" class="<%=beanclass %>" scope="request">
    <jsp:setProperty name="<%=id %>" property="*"/>
    </jsp:useBean>
    where beanclass is .class file that is to be used by the usebean tag
    i am getting following error
    The value for the useBean class attribute <%=beanclass %> is invalid.
    please help as soon as possible
    regards,
    Rameshwari

    You can not do that.The jsp:useBean and jsp:setProperty are action tags and not custom tags. Action tags get translated into Java code in the translation unit and are then compiled. Custom tag are backed by classes and the tag get translated into a method call of the class.

  • Jsp:useBean giving error while compiling JSP's in JDeveloper

    Hello,
    I am having another problem with JSP's in JDeveloper 10.1.3. jsp:useBean and jsp:setProperty are all giving problems. I am not sure what I need to do to get rid of this error
    Thanks,
    Lakshmisri

    Your original post mentions issues with jsp:useBean and jsp:setProperty, now you're talking about tag libraries and directives. Can you be more specific about what you're trying to do? Are you having problems getting JDev to recognize a tag library or are you having problems with the tag library when running the app? What directive are you trying to use that causes the termination error?

  • jsp:useBean  class="  expression "   .......

    I need to put the class value of the <jsp:useBean> and take it from a java class on the server.
    I use a method with this signature:
    public String getClassname(...){
    return newclass.toString();
    and put it in the jsp element like:
    <jsp:useBean id="bean1" scope="session" class="<%=utility.getClassName()%>" />
    It does not work while had never problems with a forward element instead like this:
    <jsp:forward page="<%=util.getPage()%>" />
    Did somebody suceed or any suggestions?
    best regards
    Joan

    thanks gray man.
    the
    beanName="=<% classfactory.getHandler()%>"
    inserted in a usebean tag compiles
    but when i call a
    <jsp:setProperty name="bean" property="*"/>
    on this bean I find that all the values are set empty
    like if it is the parent class that gets called and not
    the real subclass that I am casting to with the dynamic
    beanName="=<% classfactory.getHandler()%>" .
    Not found a solution yet wether casting to an interface
    or to a superclass.

  • Jsp:useBean gives cannot be resolved to a type in Tomcat

    Hi, I am using Tomcat 5.5
    I have a simple JavaBean for test purposes :
    import java.io.Serializable;
        public class testBean implements Serializable {
            int number;
            public testBean() {
            public int getNumber() {
                return number;
            public void setNumber(int newValue) {
                number = newValue;
        }In a file called testBean.java
    I have successfuly compiled it and put the class file the WEB-INF/classes directory.
    I have the following JSP page :
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <jsp:useBean id="pub" scope="session" class="testBean" />
    <jsp:setProperty name="pub" property="number" value="1" />
    <html>
    <head>
    </head>
    <body>
    <jsp:getProperty name="pub" property="number" />
    </body>
    </html>When I open this jsp page I get the following error:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 2 in the jsp file: /test.jsp
    Generated servlet error:
    testBean cannot be resolved to a typeThis example is pretty minimal and I don't understand why it doesn't work. The error seems to be coming from the first JSP statement.
    Any help would be greatly appreciated.
    Thanks in advance.

    1. Put your bean class in a package.
    package test;
    import...........2. Put the .class file in web-inf/classes/test/testBean.class
    3. Specify the fully qualified name of the class in the useBean declaration.
    <jsp:useBean class="test.testBean" .../>Note: You'd be better off following the java bean naming conventions. Specifically your class name should be TestBean (first letter caps).
    ram.

  • Problem launching a jsp page with eclipse and tomcat

    Hi,
    I have just started using eclipse and tomcat for creating dynamic web pages. I tried to launch a jsp page after starting the tomcat server with the URL: http://locahost:8080/HelloWorld/, an error page was displayed as below:
    HTTP Status 404 -/
    type Status report
    message /_
    description The requested resource (-) is not available
    Apache Tomcat/5.5.17
    I didn't get any error at the console and when i just typed http://localhost, a pop up menu saying that the connection was refused when attempting to contact localhost.
    I'm not sure what is the problem here. Could it be the permssion to the localhost is not granted by the system as the eclipse IDE is running using linux?
    Hope someone can help.
    Thanks.

    http://www-128.ibm.com/developerworks/library/os-ectom/

  • jsp: useBean.. and c: coding

    I am trying to understand this coding.
    1. What does the <jsp: useBean .. class="coreservlets.ShoppingCart"> mean? Are we bringing in the content of the ShoppingCart class?
    If we use <% import="coreserlets.*"> at the top of JSP, wouldn't this work to apply all the class in the application?
    2.What is the <c:> coding? I have never seen this before (I am pretty new with Java). Is this new version of Java?
    Thanks.
    Here is coding sample.
    <jsp:useBean id="cart" class="coreservlets.ShoppingCart" scope="session"/>
    <c:choose>
      <c:when test="${empty cart.itemsOrdered}">
        <h2><i>No items in your cart...</i></h2>
      </c:when>
      <c:otherwise>
        <table border=1 align="center">
        <tr bgcolor="#FFAD00">
          <th>Item ID</th>
          <th>Description</th>
          <th>Unit Cost</th>
          <th>Number</th>
          <th>Total Cost</th>
        </tr>
        <c:forEach var="item" items="${cart.itemsOrdered}">
           <tr>
             <td><c:out value="${item.itemID}"/></td>
             <td><c:out value="${item.shortDescription}"/></td>
             <td><fmt:formatNumber value="${item.unitCost}" type="currency"/>        
           </tr>
        </c:forEach>
        </table>
      </c:otherwise>
    </c:choose>

    I am trying to understand this coding.
    1. What does the <jsp: useBean ..
    class="coreservlets.ShoppingCart"> mean? Are we
    bringing in the content of the ShoppingCart class?You're telling the JVM that you're going to use an instance of that class.
    >
    If we use <% import="coreserlets.*"> at the top of
    JSP, wouldn't this work to apply all the class in the
    application?No, that's not what import does.
    2.What is the <c:> coding? I have never seen this
    before (I am pretty new with Java). Is this new
    version of Java?It's the JSP Standard Tag Library, or JSTL. It has core tags <c>, xml tags <xml>, formatting tags <format>, and SQL tags <sql>
    <jsp:useBean id="cart"
    class="coreservlets.ShoppingCart" scope="session"/>Looks like there's a ShoppingCart object in session scope.
    >
    Check to see if the shopping cart has items.
    c:choose>If no items, say so.
    >
    <c:when test="${empty cart.itemsOrdered}">
    <h2><i>No items in your cart...</i></h2>
    /c:when>If there are items, display them in a table.
    >
    <c:otherwise>
    <table border=1 align="center">
    <tr bgcolor="#FFAD00">
    <th>Item ID</th>
    <th>Description</th>
    <th>Unit Cost</th>
    <th>Number</th>
    <th>Total Cost</th>
    /tr>
    <c:forEach var="item"
    items="${cart.itemsOrdered}">
    <tr>
    <td><c:out value="${item.itemID}"/></td>
    <td><c:out
    value="${item.shortDescription}"/></td>
    <td><fmt:formatNumber
    value="${item.unitCost}" type="currency"/>
    </tr>
    c:forEach>
    </table>
    c:otherwise>
    </c:choose>
    If you're new to Java, best to learn the base language before tackling JSPs.
    %

  • Question concerning Eclipse and Tomcat Plugin and JSP

    I have a Tomcat-Project that I am working on in Eclipse and quite a few external JARs. Everything works fine, when I run my Test class within my project (in Eclipse). But as soon, as I am trying to call the jsp in my browser I get Exceptions: "java.lang.NoClassDefFoundError: org/apache/log4j/Logger" for example, which tells me that in the browser it can't find the JARs... I'm guessing something's wrong with the classpath but I was thinking that Eclipse would handle those things for me...
    I've added the JARs to my project via Eclipse (Properties -> Java Build Path -> Libraries -> Add external JARs). And I've created a subdirectory for my jsp files and allowed my project to update the .xml file for the settings and all... Do I need to do anything else? What have I done wrong so far, have I forgotten to do?

    I solved the problem...

Maybe you are looking for