Using JavaBeans into JSP

I have a simple example for using Beans in JSP and the problem is that i get this error: org.apache.jasper.JasperException: /BeanCounter.jsp(8,0) The value for the useBean class attribute Counter is invalid.
The program's ideea is to count how many times i've accesed the bean
This is the code: (i'm using Apache Tomcat 5.5)
My bean (Counter):
import java.io.Serializable;
public class Counter implements Serializable{
int count = 0;
public Counter() {
public int getCount() {
count++;
return this.count;
public void setCount(int count) {
this.count = count;
and the code for BeanCounter.jsp :
<HTML>
<HEAD>
<TITLE>JSP Bean Example</TITLE>
</HEAD>
<BODY>
<%@ page language="java" %>
<jsp:useBean id="counter" scope="session" class="Counter" /> //i guess that here is the problem but i don't have a package or anything else
<jsp:setProperty name="counter" property="count" param="count" />
<%
out.println("Count from scriptlet code : "
+ counter.getCount() + "<BR>");
%>
<!-- Get the bean's count property, -->
<!-- using the jsp:getProperty action. -->
Count from jsp:getProperty :
<jsp:getProperty name="counter" property="count" /><BR>
</BODY>
</HTML>
The Counter.class is in WEB-INF/classes
I just cannot understand why it doesn't work. Please help :) Thanks in advance

So put your class in a package, and it should work fine.
package mypackage;
import java.io.Serializable;
import java.io.Serializable;
public class Counter implements Serializable {
     int count = 0;
     public Counter() {
     public int getCount() {
          count++;
          return this.count;
     public void setCount(int count) {
          this.count = count;
}and in your JSP:
<jsp:useBean id="counter" scope="session" class="mypackage.Counter" />
The class then moves to be WEB-INF/classes/mypackage/Counter.class
Also, your original post was missing a closing '}' on the Counter class.

Similar Messages

  • Using JavaBean with JSP...will not work no matter what

    Hi guys. Sorry that this is such a common, newb question, but I don't know where else to turn.
    I'm new to web application development, Tomcat, and JSP. I'm trying to use a simple JavaBean in a JSP to store some user information. The JSP is located in $CATALINA_HOME\webapps\art , and the UserBean I'm trying to use is in $CATALINA_HOME\webapps\art\WEB-INF\classes . I've tried adding a context in the Tomcat server.xml file, but nothing seems to work, even putting the .class file into the \art directory along with the JSP. The error I get is the following:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 1 in the jsp file: /welcome.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\art\welcome_jsp.java:43: cannot resolve symbol
    symbol : class UserBean
    location: class org.apache.jsp.welcome_jsp
    UserBean user = null;
    ^
    The source code is:
    welcome.jsp
    <%@ page import="java.sql.*" %>
    <jsp:useBean id="user" class="UserBean" scope="session"/>
    <html>
    <head>
    <title>Art Webapp Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <h1>Art Site</h1><br><br>
    <h3>Welcome Page</h3><br><br>
    <%
         user.setUsername("joe");
    user.setTitle("admin");
    %>
    </body>
    </html>
    UserBean:
    public class UserBean {
    private String username = null;
    private String title = null;
    public UserBean()
         this.username = null;
         this.title = null;
    public String getUsername()
         return this.username;
    public String getTitle()
         return this.title;
    public void setUsername(String inName)
         this.username = inName;     
    public void setTitle(String inTitle)
         this.title = inTitle;     
    }//UserBean
    Thanks for any and all help anyone could give me about this. It seems such a simple thing, to get a JavaBean working in a JSP...and it's very frustrating to have it NOT work when it seems I've done everything possible to get it to.

    Ok, I figured out what the problem was. My Bean was not a part of any specific package. It was never made clear to me that Beans are required to be a part of some package...I had no idea (though they always put them in packages in the tutorials, you think I would have picked up on it!).
    So I just added the following line to the Bean:
    package com.art;
    Then compiled it and copied the .class file to CATALINA_HOME\webapps\art\WEB-INF\classes\com\art
    Ta-da
    Thanks for the help and sorry for taking up space on this board.
    -Matt

  • Have a question about using javabean in jsp

    Hello,
    Could I have a constructor with arguments in javabean?
    Thanks.

    Yes, but if you want to instantiate the bean using that constructor you have to do it in a snippet of java code, not using a jsp tag:
    You can use
    <%
    MyBeanClass mbc = new MyBeanClass(arg1, arg2, ...);
    %>You can't use
    <jsp:useBean id="mbc" class="MyBeanClass">

  • Error while using Beans in JSP

    I am using netbeans to develop the applications and am using tomcat version (jakarta-tomcat-4.1.18).
    When I execute the following program i get the below mentioned error::
    StringBean.java
    package test;
    import java.beans.*;
    public class StringBean {
    private String message = "No message SPECIFIED";
    public String getMessage() {
    return message;
    public void setMessage(String message) {
    this.message = message;
    StringBean.jsp
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE>Using JavaBeans with JSP </TITLE>
    <LINK REL=STYLESHEET HREF="JSP-Styles.css" TYPE="text/css" >
    </HEAD>
    <body
    <jsp:useBean id = "SB" class = "test.StringBean" />
    initial value is : <jsp:getProperty name = "SB" property= "message"/>
    <jsp:setProperty name= "SB" property = "message" value= "this the message after the change"/>
    final value is :<jsp:getProperty name = "SB" property= "message"/>
    </body>
    </HTML>
    javax.servlet.ServletException: test/StringBean
    at org.netbeans.modules.tomcat.tomcat40.runtime.IDEJspServlet.service(IDEJspServlet.java:349)
         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:243)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
         at java.lang.Thread.run(Thread.java:536)
    Root Cause
    java.lang.NoClassDefFoundError: test/StringBean
         at java.lang.Class.getDeclaredConstructors0(Native Method)
         at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
         at java.lang.Class.getConstructor0(Class.java:1762)
         at java.lang.Class.newInstance0(Class.java:276)
         at java.lang.Class.newInstance(Class.java:259)
    at org.netbeans.modules.tomcat.tomcat40.runtime.IDEJspServlet$JspServletWrapper.load(IDEJspServlet.java:106)
         at org.netbeans.modules.tomcat.tomcat40.runtime.IDEJspServlet$JspServletWrapper.loadIfNecessary(IDEJspServlet.java:150)
         at org.netbeans.modules.tomcat.tomcat40.runtime.IDEJspServlet$JspServletWrapper.service(IDEJspServlet.java:160)
         at org.netbeans.modules.tomcat.tomcat40.runtime.IDEJspServlet.serviceJspFile(IDEJspServlet.java:246)
         at org.netbeans.modules.tomcat.tomcat40.runtime.IDEJspServlet.service(IDEJspServlet.java:339)
         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:243)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
         at java.lang.Thread.run(Thread.java:536)

    Ok The class isn't found, so your classpath settings of netbeans (if you are using the run function in netbeans) isn't set.
    and if you aren't using netbeans to run it, then the class isn't in the webapp/WEB-INF/classes
    good luck

  • Why JavaBeans with JSP

    Hi,
    I know its an easy question and probably a silly one to ask, but still please take time to answer this. Why do we use JavaBeans with JSP to make use of reusable code. Cant we use simple classes for this?
    Thanks in advance

    Hi,
    JavaBeans technology is the component architecture for the Java 2 Platform, Standard Edition (J2SE). Components (JavaBeans) are reusable software programs that you can develop and assemble easily to create sophisticated applications. By using Java beans, JSP allows you to keep much more of your code separate from the html than other html embedded languages. Java beans basically let you keep all the logic of your page (like the code to connect to a database, manipulate data etc�) in a separate file known as a Java bean. Then from within your html page - all you do is use one tag to 'use' the bean, and then a few other short tags to send data to and from the bean.
    the website http://java.sun.com/products/jsp/html/jsptut.html is a good start, simple and easy understand.
    Good luck!
    jmling

  • What is the difference of using JavaBean and regular classes?

    Experts,
    I am new to JavaBean(not EJB), and wondering what is the difference of using JavaBean for JSP page compared with using regular Java class?
    I know there are Bean tags which save some lines, what else?
    What does "serialization" mean compared with "not serializable"?
    thanks very much.

    No.
    A JavaBean is a regular JavaClass that:
    1) implements java.io.Serializable
    2) Its data members are private, and its data is accessed via getters and setters. You must define the getters and setters. Getters retrive the property, and must be in the format:
    public PropertyType getPropertyName()
    for most cases. The exception is when the PropertyType is a boolean, in which case you use:
    public boolean isPropertyName()
    Setters assign values to the property, and are in the form:
    public void setPropertyName(PropertyType propValue)
    3) There is also a PropertyChangeEvent model that needs to be followed.
    A marker interface has no methods you need to implement. It just marks the class as supporting certain operations. In the case of Serializable, it means the class can be written to be an ObjectOutputStream for persistant storage.
    As far as an example of JavaBean persistance, take a search on the java.sun.com site for Serializeable
    Also, take a look at this: http://java.sun.com/developer/onlineTraining/Beans/beans02/
    It concentrates mainly on gui component beans, but not all beans need to be gui parts... There are other pages to look at, but I can't find them at the moment, and I have to run...

  • Challenging: Importing HTTPClient into a JavaBean used in a JSP

    I have a BankBean.class file, which I'm using in a JSP, main.jsp. The BankBean.java file contains the line:
    import HTTPClient.*;
    I have the following directory structure:
    jeff
    -->pc
    ----->door
    -------->main.jsp
    -->WEB-INF
    ----->classes
    -------->pc
    ----------->BankBean.java
    ----------->BankBean.class
    ----------->\HTTPClient
    -------------->HTTPClient classes
    I successfully compile the BankBean.java to create the BankBean.class. However, when I call the main.jsp I receive the following jsp compile error:
    Package HTTPClient not found in import.
    import HTTPClient.*;
    ^
    1 error
    THE JSP IS NOT COMPILING.
    NOTE THE FOLLOWING:
    *The HTTPClient folder resides in the same directory as the JavaBean.java and JavaBean.class files.
    *The JavaBean.java file compiles successfully to create the JavaBean.class file.
    I don't understand how the bean can compile successfully, but the JSP cannot compile. Please help!!!
    Thanks!

    Adding the following:
    import pc.HTTPClient.*;
    failed.
    It seemed logical, but didn't work.
    After working on it for a few hours, I finally got it to work by moving the HTTPClient directory up from the pc directory into the classes directory with the other class directories. The successful directory structure is the following:
    -->pc
    ----->door
    -------->main.jsp
    -->WEB-INF
    ----->classes
    -------->pc
    ----------->BankBean.java
    ----------->BankBean.class
    -------->\HTTPClient
    ----------->HTTPClient classes
    Thanks for the help, though. It did get me thinking in the right direction.

  • Using JavaBeans in a JSP Page

    I wan't to know the advantages and disadvantages of using JavaBeans in a JSP page.
    Like for example general traditional approach for a database connection
    is to create a connection and access the database from that and close the connection
    at the end of the page, instead of the If I use a common connection bean for making connections,
    is that suggestable and then when should i close the connection then.
    One good application of JavaBeans is using a Set and Get methods for form fields in
    a registration form to get back the values.
    So may i know how best can we use the JavaBeans other than this application.
    ThanX in advance,
    kiran
    [email protected]

    I believe putting processing and query code in the JavaBean was one of the reasons for putting JavaBeans support in JSP in the first place. The original idea was to use the setXXX methods to populate the bean's data from the posted form, then do the processing (or database query), then use the getXXX methods to display the bean's data.
    Efficiency-wise, it's exactly the same as putting all the code in-line in the JSP page (actually, it might be a bit slower, because of the reflection required to do it.) Code-wise though, it makes the JSP easier to read.
    Of course, we have EJBs now too, which tie very closely and can match database queries almost one-to-one, one way to incorporate these is inside the JavaBean you reference from the JSP, another way from a servlet you redirect the JSP to, etc...

  • Using a JavaBean in JSP

    Hello,
    I am very new at this, and I am doing a very simple tutorial to use a JavaBean in JSP. I have followed all the procedures from my tutorial, and I get the following error:
    org.apache.jasper.JasperException: Can't find a method to write property 'make' of type 'java.lang.String' in a bean of type 'com.wrox.cars.CarBean'
    I have the bean:
    package com.wrox.cars;
    import java.io.Serializable;
    public class CarBean implements Serializable {
    private String make = "Ford";
    public CarBean(){
    public String getMake(){
    return make;
    public void SetMake(String make)
    this.make = make;
    and the JSP:
    <jsp:useBean id="myCar" class="com.wrox.cars.CarBean" />
    I have a <jsp:getProperty name="myCar" property="make" /><br>
    <jsp:setProperty name="myCar" property="make" value="Ferrari" />
    Now I have a <jsp:getProperty name="myCar" property="make" /><br>
    The only thing I am missing is this step, where I have been looking for these JAR files and can't find them
    I have downloaded many JSTL libraries, and still can't find them/
    - dom.jar
    - jaxp-api.jar
    - jdbc2_0-stdext.jar
    - sax.jar
    - xalan.jar
    - xercesImpl.jar
    I really appreciate any help.

    Thanks a lot.
    Although I should know that, it seems that the error was in the tutorial.
    Thanks again,

  • Scope when using a JavaBean with JSP

    what is the meaning of this question .....?
    "Which of the following can not be used as the scope when using a JavaBean with JSP? "
    question 4
    site :http://java.sun.com/developer/Quizzes/jsptut/

    The question is clearly written. I don't see how you can be confused. But let's assume you are since you would not have posed the question.
    Dumbed-down:
    There are 4 scopes or areas of variable visibility in JavaServer Pages. Which of those can areas can not be used with JavaBeans?
    Does that help?

  • Urgent!!!!!How can i use javamail in jsp without using javabeans

    hello friend
    I m making a forum in which i want to send response to the user through mail I m not using javabean Can anyone help me.How to use javamail in jsp

    http://java.sun.com/developer/onlineTraining/JavaMail/exercises.html

  • Using javabean in tomcat(unable to compile class)

    Hello, I am using jakarta-tomcat-5.0.28, OS:WinXP
    I am getting the following error when i use javabean in tomcat (the example is executed just fine in another web server:Blazix)
    I am very new to this (JSP, Servlets and tomcat) so any help would be greatly appreciate.
    THE ERROR IS:
    ==============================================================
    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: 1 in the jsp file: /SaveName.jsp
    Generated servlet error:
    C:\Programs\internet\jakarta-tomcat-5.0.28\work\Catalina\localhost\JSPSession\org\apache\jsp\SaveName_jsp.java:42: cannot resolve symbol
    symbol : class UserData
    location: class org.apache.jsp.SaveName_jsp
    UserData user = null;
    ^
    An error occurred at line: 1 in the jsp file: /SaveName.jsp
    Generated servlet error:
    C:\Programs\internet\jakarta-tomcat-5.0.28\work\Catalina\localhost\JSPSession\org\apache\jsp\SaveName_jsp.java:44: cannot resolve symbol
    symbol : class UserData
    location: class org.apache.jsp.SaveName_jsp
    user = (UserData) jspxpage_context.getAttribute("user", PageContext.SESSION_SCOPE);
    ^
    An error occurred at line: 1 in the jsp file: /SaveName.jsp
    Generated servlet error:
    C:\Programs\internet\jakarta-tomcat-5.0.28\work\Catalina\localhost\JSPSession\org\apache\jsp\SaveName_jsp.java:46: cannot resolve symbol
    symbol : class UserData
    location: class org.apache.jsp.SaveName_jsp
    user = new UserData();
    ^
    3 errors
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
         org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
         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)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
    ===============================================================
    ERROR END
    I use the folowing files:
    GetName.html
    SaveName.jsp
    NextPage.jsp
    UserData.java
    My Dir Structure is:
    /JSPSession
        GetName.html
         SaveName.jsp
         NextPage.jsp
       /WEB-INF
          /classes
             UserData.java
             UserData.class
       /libThe Code for the files is:
    GetName.html
    <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>---------------------------------------------------------------------------------------------------
    SaveName.jsp
    <jsp:useBean id="user" class="UserData" scope="session"/>
    <jsp:setProperty name="user" property="*"/>
    <HTML>
    <BODY>
    <A HREF="NextPage.jsp">Continue</A>
    </BODY>
    </HTML>-----------------------------------------------------------------------------------------------------
    NextPage.jsp
    <jsp:useBean id="user" class="UserData" scope="session"/>
    <HTML>
    <BODY>
    You entered<BR>
    Name: <%= user.getUsername() %><BR>
    Email: <%= user.getEmail() %><BR>
    Age: <%= user.getAge() %><BR>
    </BODY>
    </HTML>------------------------------------------------------------------------------------------------------------
    UserData.java
    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; }
    }

    A very common question. Tomcat dislikes classes which are not packaged. So, add a package statement in your UserBean.java
    package beans; // or something like thatand then place the compiled class file UserBean.class into WEB-INF/classes/beans.
    Put the import statement into the JSP accordingly and try again.
    ***Annie***

  • JavaBeans in JSP on iPlanet server problem

    Hi-
    I have deployed several JSPs, but this is my first attempt at using JavaBeans in the pages. We are using the iPlanet 4.1 web server.
    The following is my JSP code (MyTest.jsp):
    <html>
    <head>
    <title> Test case</title>
    </head>
    <body>
    <jsp: useBean id="myBean" class="Beans.MyBean" />
    </body>
    </html>
    The following is the bean code:
    package Beans
    public class MyBean {
    private String message = "No Message";
    public String getMessage() {
    return(message);
    public void setMessage(String message) {
    this.message = message;
    I have the JSP and bean in the same directory. I'm not clear on where to put it on an iPlanet server. The bean compiles fine, and iPlanet seems to be able to see it. However, when I compile the JSP I get the following error on iPlanet:
    recompiling JSP file: /<dir path>/Beans/MyTest.jsp
    JSP compilation error: java.lang.Exception: JSP parse error (line24) - Incomplete tag ending of /jsp:useBean, stack: java.lang.Exception: JSP parse error(line 24) - Incomplete tag ending of /jspuseBean
    I've looked through several books and the JSP coding to useBean looks fine. Is this error related to iPlanet? Is it tied to the directory structure? We are using JDK1.3, is it set up for JavaBeans - or do we need to download some other files?
    Any help is welcomed!
    Thanks,
    Leilani

    Leilani,
    Have you got your JSP and beans to work. I'm having a similar problem. I am getting the following error when trying to load the JSP:
    [10/Dec/2001:11:46:42] info ( 1688): Internal Info: loading servlet /wacc/jsp/pickProgram.jsp
    [10/Dec/2001:11:46:47] info ( 1688): JSP: JSP1x compiler threw exception
    org.apache.jasper.JasperException: Unable to compile class for JSPC:\iPlanet\Server4\https-wacc\config\..\ClassCache\_jsps\_wacc\_jsp\_pickProgram_jsp.java:86: Undefined variable or class name: menu
    menu.setUserId(userId);
    ^
    1 error
         at org.apache.jasper.compiler.Compiler.compile(Compiler.java:260)
         at com.netscape.server.http.servlet.NSServletEntity.load(NSServletEntity.java:230)
         at com.netscape.server.http.servlet.NSServletEntity.update(NSServletEntity.java:149)
         at com.netscape.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:463)
    [10/Dec/2001:11:46:47] warning ( 1688): Internal error: Failed to get GenericServlet. (uri=/wacc/jsp/pickProgram.jsp,SCRIPT_NAME=/wacc/jsp/pickProgram.jsp)
    My iPlanet "Configure JVM Attributes" has the path to the beans directory (I have also tried adding it to the Windows CLASSPATH variable):
    C:\dir\dir\beansdir;
    and here is the JSP code snippet:
    <%@ page info="Pick Program into page" %>
    <HTML>
    <HEAD>
    </HEAD>
    <BODY BGCOLOR="#ffffff">
    <USEBEAN name="menu" type=ford.wacc.beans.Menus lifespan=page></USEBEAN>
    <%
    PrintWriter myOut = response.getWriter();
    // get logged in user id
    String tmpStr = "userid";
    String userId = tmpStr.toUpperCase();
    // store user id in bean
    try {
    menu.setUserId(userId);
    } catch (Exception ex) {
    // global variables
    String[] menuItems = null;
    %>
    <%= tmpStr %>
    <%= userId %>
    </BODY>
    </HTML>
    I believe I have my iPalnet server configured correctly but it seems to me that it is a path problem. If anyone can point me in the right direction, I'd appreciate it. Thanks.

  • Using javabean

    I try to use javabean
    after I compile the javabean and put the class file at WEB-INF\lib
    but I get errors like below at jsp page
    ( I use sun java studio as tool ,is there any reference )
    testpage_jsp_jsp.java [67:1] cannot resolve symbol
    symbol : class simpleMath
    location: class jsps.test_page_jsp_jsp
    simpleMath pagecounter = null;
    ^
    testpage_jsp_jsp.java [70:1] cannot resolve symbol
    symbol : class simpleMath
    location: class jsps.test_page_jsp_jsp
    pagecounter= (simpleMath)
    ^
    testpage_jsp_jsp.java [75:1] cannot resolve symbol
    symbol : class simpleMath
    location: class jsps.test_page_jsp_jsp
    pagecounter = (simpleMath) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "simpleMath");
    ^
    thanks for the help

    class file go into WEB-INF/classes
    You also should packages and import the classes into your jsp

  • Using JNI in JSP

    Hi
    i am going to develop a DI COM viewer in web.
    so that it uses lot of shared libraries (.dll).
    i tried JNI with servlet it works fine.
    but when i try to load a same DLL for another page it gives an error saying
    ".dll loaded in another class loader"
    So that i tried to write JNI wrapper as a component using java beans.
    and i can use as multiple instances.
    package BeanDir;
    import java.util.*;
    //This file must be compiled Manually using javac
    //cd D:\tomcat\webapps\examples\WEB-INF\classes\BeanDir\mysimplebean.java
    public class mysimplebean
         static
              System.loadLibrary("HelloWorld");
         public String getceoname()
              String ceonameval = "Tom Hanks CEO of Tom Hanks INC";          
              return ceonameval;
         public String ceoemail()
              String ceoemailval = "[email protected]";          
              return ceoemailval;
         public double findtakehome(int salary,String designation)
              double takehomeamt;
              if(designation=="Developer")
                   takehomeamt = salary+salary*0.15; //15 % Raise in Salary
              else
                   takehomeamt = salary+salary*0.10; //10 % Raise in Salary
              return takehomeamt;
         public native String sayHello();      
    }Then i added the Java bean in JSP:
    <%@ page import = "BeanDir.mysimplebean" %>
    <jsp:useBean
         id="mybeanid"
         class="BeanDir.mysimplebean"
         scope="session"/>
    <jsp:setProperty
         name="mybeanid"
         property="*"/>
    <html>
    <head><title>JSP - Java Bean Demo </title></head>
    <body bgcolor="white">
    <font size=2 face=verdana>
    <center><strong>Simple JSP with JAVA Beans Demo Application Form</strong> <br>
    <%
    //Auto Compiled by JSP Engine dont use Javac
    //No Parameters Passed into Bean
    //cd E:/tomcat/webapps/examples/jsp/testdir/testme2.jsp
    String ceoname_ret;
    ceoname_ret=mybeanid.getceoname();          
    out.println("<br>CEO Name : "+ceoname_ret);
    //No Parameters Passed into Bean
    String ceoemail_ret;
    String s;
    ceoemail_ret=mybeanid.ceoemail();
    out.println("<br>CEO Email : "+ceoemail_ret);
    out.println("<br><br>");
    out.println("<table border=1 bordercolor='maroon' cellspacing=4 cellpadding=4 align=center>");
    out.println("<tr align=center valign=middle>");
    out.println("<td bgcolor=maroon><font face='verdana' size=2 color=white> Calling From JSP </font></td>");
    out.println("<td bgcolor=maroon><font face='verdana' size=2 color=white> BEAN BEANING CALLED </font></td></tr>");
    double takehomeamt_ret;     
    double totalcost=0;
    takehomeamt_ret = mybeanid.findtakehome(5000,"Developer") ;     
    totalcost=totalcost+takehomeamt_ret;
    out.println("<tr align=center valign=middle><td><font face='verdana' size=2>Take Home : James Smith  </font></td>");
    out.println("<td><font face='verdana' size=2>"+takehomeamt_ret+"</font></td></tr>");
    takehomeamt_ret = mybeanid.findtakehome(5000,"Designer") ;     
    totalcost=totalcost+takehomeamt_ret;
    out.println("<tr align=center valign=middle><td><font face='verdana' size=2>Take Home :  Andrew  </font></td>");
    out.println("<td> <font face='verdana' size=2>"+takehomeamt_ret+"</font></td></tr>");
    takehomeamt_ret = mybeanid.findtakehome(7000,"Developer") ;     
    totalcost=totalcost+takehomeamt_ret;
    out.println("<tr align=center valign=middle><td><font face='verdana' size=2>Take Home : Peter O Neal  </font></td>");
    out.println("<td> <font face='verdana' size=2>"+takehomeamt_ret+"</font></td></tr>");
    out.println("<tr align=center valign=middle><td><font face='verdana' size=2><strong>TOTAL COST FOR COMPANY </strong>  </font></td>");
    out.println("<td> <font face='verdana' size=2>"+totalcost+"</font></td></tr>");
    out.println("</table>");
    out.print("My dll should be somewhere here: "+System.getProperty("java.library.path"));
    s = mybeanid.sayHello();
    out.println("<br>Output from JNI"+s);
    %>  </center>
    </font>
    </body>
    </html>Error which i am getting is :
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.UnsatisfiedLinkError: BeanDir.mysimplebean.sayHello()Ljava/lang/String;
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
         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)
    root cause
    javax.servlet.ServletException: java.lang.UnsatisfiedLinkError: BeanDir.mysimplebean.sayHello()Ljava/lang/String;
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
         org.apache.jsp.jsp.callbean_jsp._jspService(callbean_jsp.java:121)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
         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)
    root cause
    java.lang.UnsatisfiedLinkError: BeanDir.mysimplebean.sayHello()Ljava/lang/String;
         BeanDir.mysimplebean.sayHello(Native Method)
         org.apache.jsp.jsp.callbean_jsp._jspService(callbean_jsp.java:109)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
         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

    Hi friends,
    i got the solution for using JNI in JSP.
    But not with Javabean
    I created a class that loads the library and define the native method.
    import the above said class package in your JSP program
    create the object for the class
    access the native method with that object.
    copy your .dll file in system32 folder
    if you have declared package in java program change the method according to that
    other wise you will get unsatisfied link error
    for ex
    package sam.jni;
    import java.io.*;
    public class Helloworld
    static
    static.loadlibrary("HelloWorld");
    public native String sayHello();
    }Method name in your c++ program looks like
    JNIEXPORT jstring JNICALL Java_sam_jni_HelloWorld_sayHello
      (JNIEnv *env, jobject obj) {
        return  env->NewStringUTF("krishnakumar");

Maybe you are looking for

  • Problem sending mail since downloading update

    I cannot send email from my IPad since downloading update. I can receive but not send. Is there a fix?

  • Posting a Parked Invoice

    Hi All, I am developing a report to post the parked invoices. For this i have used the function module 'MRM_INVOICE_READ' and the function module 'MRM_PARKED_INVOICE_POST'. But when i select a parked invoice from the ALV Grid display and click on the

  • How do I solve Interlacing issue?

    Hi All, I am trying to create a a Wedding DVD. But I every time I import in trans coded file  encore cs6 it and preview it appears to as interlaced.However if I play as a normal file in VLC player it plays fine. The sequence format is HD1080P 23fps.

  • Error message in Dreaweaver upon Start-up....

    Hi, I'm running Dreaweaver CS4 on a windows 7 system, which has been running smoothly up until 2 days ago.  Now, every time I start-up Dreaweaver, I keep getting the following error message "Unable to find file SME.htm in the Configuration/Floaters d

  • Re-trigerring availability check in sales order

    Hello, I want to re-trigger availability check based on some critical field changes in sales order (like ship to party, delivery date etc ). how to achive the same. ? regards Pamela