Generic id attribute in jsp:useBean

hi!
i use JSP 1.2 and would like to fill the id-attribute with a constant that i have declared in an interface. I import this interface into my jsp and then write
<jsp:useBean id='%= Constants.REQ_ATTRIB_ARTICLEBEAN %'
class="com.my.content.ArticleBean" scope="request"/>FAILURE: "JspTranslate: Runtime Expr Value
"%=Constants.REQ_ATTRIB_ARTICLEBEAN %" is not permitted for attribute
"id" for jsp element jsp:useBean."
I tried also the following, but it didn't work either...
<jsp:useBean class="com.my.content.ArticleBean" scope="request">
  <jsp:attribute name="id">
    <%= Constants.REQ_ATTRIB_ARTICLEBEAN %>
  </jsp:attribute>
</jsp:useBean>FAILURE: "JspTranslate: jsp:useBean is missing an id attribute."
Thanks for the help!

Isnt the error message succint enough ?
FAILURE: "JspTranslate: Runtime Expr Value
"%=Constants.REQ_ATTRIB_ARTICLEBEAN %" is not permitted for attribute
"id" for jsp element jsp:useBean."IMO, you cannot use Runtime expressions for the id attribute values.
cheers,
ram.

Similar Messages

  • 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 How to get value of an object from a bean

    I am new to JSP and am struggling from past few days to solve a problem. Consider the below scenario
    Class Book{
    private String author;
    public void setAuthor(String author)
    public String getAuthor(){
    return author; }
    Class Rack{
    private Book []books;
    public []Book getbooks()
    return books;
    public void setbooks([]Book val){....}
    Suppose Books gets populated only using Rack and I have Rack populate in my session, using jsp:usebean or any other tag how can I get value of author? Does using tag handle null value check of books, if books are not set by any chance?
    Regards,
    Dhyan

    I got a way out to access the attribute, i feel it is
    <jsp:usebean id="myRack" class="settings.Rack"/>
    <c:foreach var="book" item="myRack.books">
    </c:foreach>
    I am not able to check if this is correct or not because myRack.books is not having any value set by me in the request scope. How do i get instance of Rack class set by another page in the current request? I can get the value if i use scriptlet but i dont want to use scriptlet.
    I am continiously trying, if I get an answer, I shall post, else pls somebody guide.

  • Why do we need jsp:useBean???

    Hi All,
    I am going over both the J2EE tutorial and JSP1.2 spec.
    As far as I read, it seems to me that "jsp:useBean" is a way of creating a bean object.
    <jsp:useBean id="local" scope="application" class="Mylocales">
    If I put the class file in the import statement, can I create the object in the scriptlet
    <% Mylocales local = new Mylocales(); %>
    and set/get properties by calling
    local.setName(); // assume these methods are in the class
    local.getName();
    without using "jsp:setProperty" and "jsp:getProperty".In this way, isn't it a redundancy to have "jsp:useBean" in JSP spec? We can always create any kind of objects in the scriptlets.
    Since "jsp:useBean" has been there for years, I believe something must be wrong with my rationale. However, both the spec and the tutorial couldn't answer this question. Can anyone clear it up to me?
    Thx in advance.
    Kevin

    There's nothing wrong with your rationale; useBean IS a redundant tag, but it does provide some compact functionality without having to write extra code.
    http://java.sun.com/products/jsp/tags/11/syntaxref1115.html covers the syntax of this tag; one advantage of using this tag is the 'scope' attribute, that allows you to define, at object creation, just how long the object will be around. You can limit an object's scope to the page that declared it, or allow it to be accessed by any page that shares the same session, or request, or application.
    I do believe that the main point of this tag comes in at the design level; one of the strongest reasons to use JSPs at all is to separate out the application logic from the page presentation. This means that anyone who can use HTML should be able to maintain the JSP pages in the application. Instead of having to teach a non-programmer a little bit of code, just demonstrate the use of a single tag that can be reused throughout the application. The logical extension of this idea is the tag library.
    Myself, I mix and match as needed, but there are never more than a few lines of scriptlet code in my JSP pages. If there's more code than HTML in my JSP page, I'll go ahead and use a servlet instead.
    Anyway, I guess my point is that JSP pages are flexible, you can pick the functionality that you want to use, and the useBean tag isn't quite superfluous.

  • Setting attributes in jsp is not working

    i want to recieve the "stuBean" object in the servlet by setting it in following jsp page.In this jsp page i am retrieving that object sent by a servlet and then again i want to forward it to another servlet through this jsp page. And in the servlet i want to recieve this object is giving me null pointer exception.
    CoDe for JSP page
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body  >
            <%
                LoginRemote stuBean=(LoginRemote) request.getAttribute("stuBean");
                out.print(stuBean.getPassWord());
                request.setAttribute("stuBean", stuBean);
    %>
      <center>  <form  action="passChangeServlet" method="POST">
                <table  border="1">
                    <tbody >
                        <tr>
                            <td>Current Password</td>
                            <td><input  type="password" name="currentPass" value="" /></td>
                        </tr>
                        <tr>
                            <td>New Password</td>
                            <td><input type="password" name="newPass" value="" /></td>
                        </tr>
                        <tr>
                            <td>Confirm Password</td>
                            <td><input type="password" name="confPass" value="" /></td>
                        </tr>
                        <tr>
                            <td><input type="reset" value="Reset" name="reset" /></td>
                            <td><input type="submit" value="Submit" name="process" /></td>
                        </tr>
                    </tbody>
                </table>
            </form>
            <a href="http://abc">Continue....</a></center>
        </body>
    </html>
    Code for servlet
    LoginRemote stuBean=(LoginRemote)request.getAttribute("stuBean");
            out.print(stuBean.getUserName());

    Request attributes last for one "request".
    If you want to remember a value across multiple HTTP requests, use Session scope.
    Also rather than scriptlet code in a JSP, it would be better to have a <jsp:useBean> and <jsp:setProperty> tag.

  • Jsp:useBean

    I really shouldn't be trying to use JSP any more ...
    I have been having problems using JavaBeans in JSP pages now - every time a problem is solved, that other little thing that always wanted a go at annoying me arrives ...
    The code is:
    <jsp:useBean id="pollResult" scope="application" class="com.ora.jsp.beans.poll.PollBean" />Because another JSP page I created (using JavaBeans) worked, using a JavaBean from the directory com.ora.jsp.beans.userinfo.UserInfoBean, I assumed that THIS would work - but it didn't! The error was:
    org.apache.jasper.JasperException: /calculate.jsp(11,2) According to TLD or attribute directive in tag file, attribute test does not accept any expressionsAnother problem, is there a solution?
    Sincerely, I'm sorry to plague everyone out there with all my problems - maybe I should give up and become a potato farmer instead ...

    Hi
    My Calculate.jsp looks like this:
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <jsp:useBean id="pollResult" scope="application"
      class="com.ora.jsp.beans.poll.PollBean" />
    <jsp:useBean id="answer" class="com.ora.jsp.beans.poll.AnswerBean" >
      <jsp:setProperty name="answer" property="*" />
    </jsp:useBean>
    <c:choose>
      <c:when test="${answer.valid}" >
        <c:set target="${pollResult}" property="answer"
          value="${answer}" />
        <jsp:forward page="result.jsp" />
      </c:when>
      <c:otherwise>
        <jsp:forward page="poll.jsp" />
      </c:otherwise>
    </c:choose>I am using JSTL 1.1.

  • 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

  • Namespace resolution in jsp:useBean

    If I define an object using <jsp:useBean id="name" scope="application"/>, how can I find it using jsp:useBean in another JSP, if possible?

    By using <jsp:useBean id="name" scope="application"/> in the other JSP. Note : you also need a class / type attribute in the useBean tag.

  • Why do you use jsp:useBean?

    Hi,
    I have one "simple" question :) : When or why do you are using <jsp:useBean>,<jsp:getProperty> and <jsp:setProperty>?
    For practice, I am creating a form, sends the data to a servlet and the servlet "packs" the parameter into a Bean and put this Bean into a request- or SessionScope. After that, my resultpage could access the property name of the bean with (for instance) sessionScope.Bean.name.
    I wanted to use the 3 tags above first, but after I realised the way I describes above I didn't have to use these three jsp tags. Therefore I wonder when you are using these tags.
    Thnx
    Alex

    hi
    The component model for JSP technology is based on JavaBeans component architecture. JavaBeans components are nothing but Java objects which follow a well-defined design/naming pattern: the bean encapsulates its properties by declaring them private and provides public accessor (getter/setter) methods for reading and modifying their values.
    Before you can access a bean within a JSP page, it is necessary to identify the bean and obtain a reference to it. The <jsp:useBean> tag tries to obtain a reference to an existing instance using the specified id and scope, as the bean may have been previously created and placed into the session or application scope from within a different JSP page. The bean is newly instantiated using the Java class name specified through the class attribute only if a reference was not obtained from the specified scope. Consider the tag:
    sun site

  • Jsp usebean sharing issues

    Hi,
    I am using a bean called productTransfer in two different JSP's:
    JSP 1:
    <jsp:useBean id="transferbean" class="transactions.productTransfer" scope="session"/>
    JSP 2:
    <jsp:useBean id="invTransfer" class="transactions.productTransfer" scope="session"/>
    While I am still in the same session, if I first use JSP 1 and then use JSP 2 after that, will my instance of productTransfer (invTransfer) be the same as the instance used in JSP 1 as transferBean?
    i.e. Is there just one instance created of productTransfer irrespective of what the bean ID is in different JSps?
    Thanks
    Luanne

    No.
    The beans are unique by their "id"
    When it comes across a useBean tag it looks in the session for an attribute with that id:
    ie session.getAttribute("invTransfer"). If it can't find one, it instantiates a new object of that type.
    You could 'hotwire' it with the code: session.setAttribute("invTransfer", session.getAttribute("transferbean"));
    ie - put the bean in session under both names.
    Good luck,
    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 /jsp:useBean

    Hi,
    I am really sorry for the inconvenience.I wrongly mentioned name in place of id vice versa.
    I am trying to use the beans within the JSP page by sending its input to other class which i used it in Bean.The tags and contents listed are as follows:
    <jsp:useBean id="register1" class="/rms/reigister">
    <jsp:setProperty name="register1" property="*"/>
    </jsp:useBean>
    On executing it i get the error as the class attribute /rms/register is invalid.
    <jsp:useBean name="register1" class="org.apache.catalina.rms.reigister">
    <jsp:setProperty id="register1" property="*"/>
    </jsp:useBean>
    On executing it i get the error as the class attribute "org.apache.Catalina.rms.register" is invalid.
    Thanks in advance

    Hi,
    I am really sorry for the inconvenience.I wrongly mentioned name in place od id vice versa.
    I am trying to use the beans within the JSP page by sending its input to other class which i used it in Bean.The tags and contents listed are as follows:
    <jsp:useBean id="register1" class="/rms/reigister">
    <jsp:setProperty name="register1" property="*"/>
    </jsp:useBean>
    On executing it i get the error as the class attribute /rms/register is invalid.
    <jsp:useBean name="register1" class="org.apache.catalina.rms.reigister">
    <jsp:setProperty id="register1" property="*"/>
    </jsp:useBean>
    On executing it i get the error as the class attribute "org.apache.Catalina.rms.register" is invalid.
    Thanks in advance

  • 2 jsp:useBean in a jsp pg

    is it possible to use 2 bean pages in a jsp pg, ie having 2
    <jsp: useBean...>
    <jsp: useBean...>

    yes, you can do that, but the attribute id must not same.

  • How come property attribute of jsp:getProperty  knows which method to call

    Hello friends,
    I could not understand How come property attribute of <jsp:getProperty knows which method to call
    <jsp:useBean id="test" class="BeanTest.testing" scope="page" />
    <jsp:getProperty name="test" property="name" />
    there is no method "name" in testing.class file
    if u see the existing examples "date" given in TOMCAT , it is using many <jsp:getProperty tag, but the property name is not equal to the method method name in the Bean file
    thanks,

    First do you know what a
    bean property sheet is?
    If not say so.
    Second, to your question
    The Java Runtime Environment (JRE) uses introspection to identify the appropriate get() or set() methods of that bean. What is introspection?
    Introspection is a process that allows the class to expose its accessable variables and methods and allows other classes to see what they can do with that class when requested. Eg:
    public class MyBean{
    private String someValue = null;
    public MyBean(){
    someValue = "Some String Value";
    //Introspection will reveal this method
    public String getSomeValue(){
    return someValue;
    } and
    <jsp:getProperty name="...." property="someValue" />
    will call the getSomeValue() method

  • Is this true about jsp:usebean?

    Hi, let me explain this.....i have a Jsp, a business class and a business entity (Country)
    Let's say that the business class connects to a database and retrieve some information (List of Countries with all their attributes)...so the business class instanciates a business entity (Country) with the variable "entityCountry" and encapsulates the information retrieved in the "entityCountry". Then in my JSP i want to display a list of countries....so i use
    <jsp:usebean id="entityCountry" scope="session" class="Country"/>This catches the object, the business class previously instanciated, with all the information it was retrieved from the database? it doesn't create another object with null attributes? is it the same??

    As described [url http://java.sun.com/products/jsp/syntax/1.2/syntaxref1217.html#8865]here
    If the attribute is found in session scope, then it uses the value already created.
    If it is not found, then it instantiates a new instance.
    This code in a JSP
    <jsp:usebean id="entityCountry" scope="session" class="Country"/>
    translates to approximately this java code
    Country entityCountry = session.getAttribute("entityCountry");
    if (entityCountry == null) {
      entityCountry = new Country();
    }

Maybe you are looking for