Constructor parameter and useBean -tag

Greetings,
Is there a way to pass a contructor parameter when using the JSP tags:
<%@ page import="DBTool" %>
<jsp:useBean id='manager' scope="application" class=DBTool/>
The DBTool class needs init parameters in the contructor, but I don`t know any way how to do it when using the useBean tag?
Regards,
Eki

This is as close as you are going to get. The code within the jsp:useBean tag will only get executed when the object needs to be created. With a scope of application, it will only get run once unless you call application.removeAttribute("manager") OR getServletContext().removeAttribute("manager").
Hope this helps
<%@ page import="DBTool" %>
<jsp:useBean id="manager" scope="application" class="DBTool">
       <%
           manager.setProperty1(13);
           manager.setMyProperty2("MyProperty");
       %>
</jsp:useBean>OR if you want it to be cleaner
<%@ page import="DBTool" %>
<jsp:useBean id="manager" scope="application" class="DBTool">
       <% manager.init(parms); %>
</jsp:useBean>

Similar Messages

  • ConnCacheBean sample and useBean tag?

    Hi,
    In the ConnCacheBean sample code (JDBC 9i Sample Code), the Bean is instantiated in a scriptlet in each of the JSPs in the example:
    // Instantiate and get instance of the Bean
    ConnCacheBean myBean = ConnCacheBean.getInstance();
    If you are using ConnCacheBean from more than one JSP, would it make more sense to have a useBean tag with application scope in each JSP:
    <jsp:useBean id="ccb" class="packagename.ConnCacheBean" scope="application">
    Just wondering if there is any particular reason that I am missing, that the code was written in the way it was?
    thanks
    Rob

    Robert,
    I would suggest you to keep this class as a singleton class. This is because, at any time, there should be only one copy of this class on the server or the JVM. Multiple copies of this class means that there is more than one place from where a class/JSP can get a connection. This means that the connection is instantiated more than once which defeats the whole purpose of Caching connections. You should avoid this.
    What you are suggesting is fine if you are writing a small application, but you dont want multiple copies of this class even by mistake in a big application.
    Thanks.

  • Calling an inner class in a jsp:usebean tag

    Hi everybody !
    Here's my problem : working in my project on multiple pages, I'm using inner classes/beans to limitate my '.java' files but I'm stuck when calling that 'inner-bean' in my jsp:usebean tag.
    First, I tried to declare in the class parameter : 'class="MyPrincipalBean.theInnerBean" but jsp returns me a 'not found' message.
    I tried an other issue with this :
    'class="MyPrincipalBean$theInnerBean" but I encountered a 'Attempt to use a bean type without a void constructor in jsp:useBean tag (JSP 1.1 specification, 2.13.1)'. Since I can't find that specification, I'm sending an SOS.
    Am I on the good way ? If somebody as encoutered that sort of problem, it would be very kind of you to help me.
    Thanks for your help !
    [email protected]

    Thanks for your help!
    I must recognize that my explainations weren't really precise.
    My principal bean owns a table of my inner-class type :
    public class FirstBean extends EntityBean {
    private SecondBean[] tabSB;
    public SecondBean[] getTabSB() {...}
    public void setTabSB(SecondBean[] p_tabSB) {...}
    public class SecondBean {...}
    So I can call a specific bean from the tab in my Servlet for another page.
    But I think I have the solution and I need your advise :
    I tried this :
    <jsp:useBean id="FirstBean" class="<...>.FirstBean" scope="session" />
    <jsp:useBean id="SecBean" beanName="<...>.FirstBean$SecondBean" type="<...>.FirstBean$SecondBean" scope="request" />
    And would you believe it ? It seems to work ! But I have to test this farther to be sure. What do you think of it ?

  • How to use "scope " attrubute in useBean tag

    Can anyone please tell me if I can use the same JavaBean Class to hold information form different pages? well, let me explain exactely what I want to do:
    I have a Java bean Class that holds a property 'Name':
    package ContactManager;
    public class Person {
    private String name="%";
    public String getName () {
    return this.name;
    public void setName (String my_name) {
    name = my_name + "%" ;
    I'm using this class to store temporarly the Criteria of search from a JSP/HTML page to send to a database for search and for UPDATE -> this of course is done in different HTML/JSP pages. The problem I have is that the first time I set the properties (when the user make a search) this value remains unchanged [-> the second time when the user asks for update, I try to use the same bean to keep the value => unfortuntly it returns me the old value]
    My question is: is the use of 'scope' attribute of the "jsp:useBean" tag can solve this problem? if yes how to use it? I've tryed to set the scope of the bean to page but that does not help :-(
    Pleaze help, I'm stuck.... Bellow is the 4 JSP pages for:
    - person_search.jsp / person_result.jsp
    - request_modify.jsp/ DoModify.jsp
    1 -person_search.jsp
    <%@ page import="java.sql.*" %>
    <HTML>
    <HEAD><TITLE>Person Search</TITLE></HEAD>
    <BODY><CENTER>
    <form method="POST" action="person_result.jsp">
    Name <input type="text" name="name" size="47"></p>
    <input type="submit" value="Submit" name="B1">
    <input type="reset" value="Reset" name="B2"></p>
    </form></body>
    </html>
    2- person_result.jsp
    <%@ page import="java.sql.*" %>
    <HTML><BODY>
    <jsp:useBean id="theBean" class="ContactManager.Person"/>
    <jsp:setProperty name="theBean" property="*" />
    Name<BR>
    <%
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    System.out.println("JDBC driver loaded");
    catch (ClassNotFoundException e) {
    System.out.println(e.toString());
    %>
    <%
    try {
    Connection con = DriverManager.getConnection("jdbc:odbc:ContactManager");
    Statement s = con.createStatement();
    String sql = "SELECT Client.ClientID, Client.Name FROM Client where Client.Name like " + "'" + theBean.getName() + "'";
    ResultSet rs = s.executeQuery(sql);
    while (rs.next()) {
    String myId = rs.getString(1);
    %>
    <TR>
    <TD><%= myId %></TD>
    <TD><a href="person_detail.jsp?id=<%= myId %>"><%=rs.getString(2)%></a></TD>
    <TD><a href="delete_person.jsp?id=<%= myId %>">Delete</a></TD><BR>
    </TR>
    <%
    rs.close();
    s.close();
    con.close();
    catch (SQLException e) {
    System.out.println(e.toString());
    catch (Exception e) {
    System.out.println(e.toString());
    %>
    </BODY>
    </HTML>
    3- request_modify.jsp
    <%@ page import="java.sql.*" %>
    <html>
    <head><title>AddressBook: Modifying Person <%= request.getParameter ("id") %></title> </head>
    <body bgcolor="#ffffee">
    <%
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    System.out.println("JDBC driver loaded");
    catch (ClassNotFoundException e) {
    System.out.println(e.toString());
    %>
    <%
    int rowsAffected = 0;
    try {
    Connection con = DriverManager.getConnection("jdbc:odbc:ContactManager");
    Statement s = con.createStatement();
    String sql = "SELECT Client.ClientID, Client.Name FROM Client where ClientID ="+ request.getParameter("id");
    ResultSet rs = s.executeQuery(sql);
    if (rs.next()) {
    %>
    Client Name is <input type=text name=name value=<%= rs.getString(2) %>> <br>
    <TD><a href="person_do_modify.jsp?id=<%= rs.getString(1)%>">Confirm Modify</a></TD>
    <%
    rs.close();
    s.close();
    con.close();
    catch (SQLException e) {
    System.out.println(e.toString());
    catch (Exception e) {
    System.out.println(e.toString());
    %>
    </BODY> </HTML>
    4- do_modify.jsp
    <%@ page import="java.sql.*" %>
    <html>
    <head><title>AddressBook: Modifying Address <%= request.getParameter ("id") %></title></head>
    <body bgcolor="#ffffee">
    <jsp:useBean id="theBean" class="ContactManager.Person" scope="page"/>
    <jsp:setProperty name="theBean" property="name"/>
    <%
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    System.out.println("JDBC driver loaded");
    catch (ClassNotFoundException e) {
    System.out.println(e.toString());
    %>
    <%
    int rowsAffected = 0;
    try {
    Connection con = DriverManager.getConnection("jdbc:odbc:ContactManager");
    PreparedStatement preparedStatement = con.prepareStatement ("UPDATE Client SET Name=? WHERE ClientID =?");
    preparedStatement.setString (1, theBean.getName());
    preparedStatement.setString (2, request.getParameter("id"));
    rowsAffected = preparedStatement.executeUpdate ();
    preparedStatement.close ();
    if (rowsAffected == 1) {
    %>
    done
    <%
    else{
    %>
    Not Modified
    <%
    con.close();
    catch (SQLException e) {
    System.out.println(e.toString());
    catch (Exception e) {
    %>
    </BODY></HTML>
    Thank you for the help.
    Sammy

    While a quick search on the <jsp:useBean> tag and the scope attribute will probably yield more information than I can summarize in a few sentences, I'm pretty sure that using the scope="page" attribute on a bean will cause that bean to be instantiated every time the page is loaded. In order for a bean to persist longer than the existance of that page (whether you're loading a new page, or reloading the same one), you'd need to set the scope to session or application (you'd probably want session).

  • 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...

  • Hi, I have quick question about use of USEBEAN tag in SP2. When I specify a scope of SESSION for the java bean, it does not keep the values that I set for variable in the bean persistent.Thanks,Sonny

     

    Make sure that your bean is implementing the serializable interface and that
    you are accessing the bean from the session with the same name.
    Bryan
    "Sandeep Suri" <[email protected]> wrote in message
    news:[email protected]..
    Hi, I have quick question about use of USEBEAN tag in SP2. When I
    specify a scope of SESSION for the java bean, it does not keep the
    values that I set for variable in the bean persistent.Thanks,Sonny
    Try our New Web Based Forum at http://softwareforum.sun.com
    Includes Access to our Product Knowledge Base!

  • WL5.1: Using JSPC with pages that include usebean tags

    Hi All,
              I'm trying to get JSPC to correctly compile my JSP pages (which compile with
              no problems from within Weblogic itself) and for each page that contains a
              <userbean> tag, it seems as though java is trying to instantiate the bean as
              it turns the JSP page into a servlet.
              I can stop this happening by changing the <usebean class="foobar"/> tag to a
              <usebean type="foobar"/>, but according to the documentation, this technique
              is only supposed to be used when the bean's object is expected to be in
              scope already, which is not the case.
              Is there anyway to tell JSPC not to instantiate the beans in the <usebean>
              tags?
              bye
              

    Hi All,
              I'm trying to get JSPC to correctly compile my JSP pages (which compile with
              no problems from within Weblogic itself) and for each page that contains a
              <userbean> tag, it seems as though java is trying to instantiate the bean as
              it turns the JSP page into a servlet.
              I can stop this happening by changing the <usebean class="foobar"/> tag to a
              <usebean type="foobar"/>, but according to the documentation, this technique
              is only supposed to be used when the bean's object is expected to be in
              scope already, which is not the case.
              Is there anyway to tell JSPC not to instantiate the beans in the <usebean>
              tags?
              bye
              

  • Is it possible to Remove the inbuf and outbuf tags from a SALT exposed Tuxedo Service?

    Hi All,
    Currently I have the need to expose my tuxedo Service in a pre-created WSDL file (with all the fields names and namespaces already defined). Searching the web and the examples presented in the Tuxedo and Salt Package, I was able to configure most of the fields but  still can't remove the wrapper inbuf tag.
    Is there any parameter or configuration I can use to eliminate this tag so I can expose the SALT generated WSDL the way I want? Or is it a requirement for every tuxedo service to have his input exposed that way by using SALT?
    If you need anything else in order to provide an answer for this, please let me know. I'm also open to any sugestions.
    Thanks in advance,
    Brunno Attorre

    Hi,
    You would need to set the environment variable GWWS_WSDL_NO_BUF_WRAPPER="Y" (and restart the GWWS server).
    This should prevent the <inbuf> and <outbuf> tags from being added but it may depend upon the SALT release and rolling patch
    level you are using(i.e. if it is included or not) 
    Regards,
    Bob Finan

  • Unable to use jsp:useBean tag

    when I use
    <jsp:useBean id="addressBean" class="AddressBean" scope="session"/>
    I get the following error
    Exception Details: org.apache.jasper.JasperException
    Unable to compile class for JSP No Java compiler was found to compile the generated source for the JSP. This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK to the common/lib directory of the Tomcat server, followed by a Tomcat restart. If using an alternate Java compiler, please check its installation and access path.
    So my question is how to use the <jsp:useBean> tag in JSC

    Please see my message How to set developer's mode for oracle jsp engine.
    As a very early warning of the future, this way of setting configuration paramemter in web.xml for oracle jsp engine will be deprecated in the next major version of oc4j and desupported probably later on. Yes, it is still supported in 10.1.3 and the next major version, though.

  • Usebean Tag

    What are the advantages of usebean tags in jsp.
    Is there any benefits, if i'm not using any SQl queries in JSP.
    If i used Javabeans set & get methods and store them in a vector, in a web application. How far it will increase the performaance?

    Its not a question of performance.
    Its a question of design and maintainability.
    Pages with lots of java scriptlet code mixed in with HTML are difficult to read and understand, and harder to maintain than JSPs with no scriptlet code.
    The same reason for not including sql code in your JSP.
    The aim is to have the SQL code in ONE place, so if it changes, then you only have to change it in one place.
    If you have bits of SQL scattered through 5-6 jsp pages it becomes that much more difficult.

  • Need help with the jsp:useBean tag

    Dear Fellow Java/JSP developers:
    I am trying to use the <jsp:useBean> tag in a jsp that displays the values from a javaBean that gets populated by another class.
    <%@ page contentType="text/html" pageEncoding="UTF-8"%>
    <%@ page import = "java.util.ArrayList"%>
    <%@ page import = "java.util.Iterator"%>
    <%@ page import = "salattimes.CalendarParse" %>
    <%@ page import = "salattimes.Salat" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <jsp:useBean id="test" scope="session" class="calendar.Time" />
            <% CalendarParse sTime = new CalendarParse();
                Time mytime = sTime.runExample();%>
            <%=mytime.getA() %>
            <%=mytime.getB() %>
            <%=mytime.getC() %>
            <%=mytime.getD() %>
            <%=mytime.getE() %>
        </body>
    </html>However, up to now, I am only able to display the values on my JSP page using the scriptlet
    <% CalendarParse sTime = new CalendarParse();
                Time mytime = sTime.runExample();%> to declare and create the object (the method call sTime.runExample(); populates the fields in the Java Bean), and the expressions:
    <%=mytime.getA() %>
             <%=mytime.getB() %>
             <%=mytime.getC() %>
             <%=mytime.getD() %>
             <%=mytime.getE() %>to present the values on the screen. What I would like to do is assign the object that I create to a javaBean reference declared in a <jsp:useBean> tag as follows:
    <jsp:useBean id="test" scope="session" class="calendar.Time" />
            <% CalendarParse sTime = new CalendarParse();
                test = sTime.runExample();%>and then present the values stored in the bean to the JSP page as follows:
    <jsp:getProperty name="test" property="a" />
            <jsp:getProperty name="test" property="b" />
            <jsp:getProperty name="test" property="c" />
            <jsp:getProperty name="test" property="d" />
            <jsp:getProperty name="test" property="e" />
            <jsp:getProperty name="test" property="f" />Is this possible? When I try the above, I get "null" as my output on the screen. When I try the first approach listed above, I get the values I am looking for. Is there a way to accomplish this using the <jsp:useBean> approach?
    Thanks to all those who reply.
    Sincerely;
    Fayyaz

    The code:
    <jsp:useBean id="calendar" class="calendar.CalendarParse" scope="session"/>
    <c:set var="time" value="${calendar.time}"/>Would be roughly equivalant to:
    calendar.CalendarParse calendar = new calendar.CalendarParse();
    Object time = calendar.getTime();I assumed that the CalendarParse object was in the calendar package because that was were your Time class was (when you used <jsp:useBean id="test" scope="session" class="calendar.Time" />"), but when I look back at your original post I see I was wrong and the use of calendar as both the incorrect package and the variable name was confusing. To make the code more similar to your original post the code should have read:
    <jsp:useBean id="sTime" class="salattimes.CalendarParse"/>
    <c:set var="myTime" value="${sTime.time}" scope="session"/>
    ${myTime.a}
    ${myTime.b}
    ${myTime.c}
    etc...Here is an explanation of the parts:
             /* name of the variable */  /* fully qualified class name, package.className */
    <jsp:useBean id="sTime"           class="salattimes.CalendarParse"/>
      /* name of the new object from bean */  /* source of object, variable.property */    /* Scope of new object */
    <c:set var="myTime"              value="${sTime.time}"             scope="session"/>
    /* data to display variable.property */
    ${myTime.a}Where a 'property' in a bean is defined as a method in the form of getProperty(). So the 'time' property is getTime() and the 'a' property is getA().

  • Query about tag extensions and custom tags

    Hello,
    Can u please clarify me where are these tag extensions and custom tags are actually used. (in which conditions)
    What are the advantages in using them...
    thanks in advance..
    Jaagy.

    You have to remember that .tag are, in a way, jsp pages, so you can use other custom tags, etc.
    We use them when we need template that are mostly html, with a little bit of logic in them that we want to reuse.
    For example, we made one for or header and footer. In header.tag, we set all of our http info, from doctype to body, including default css, title, etc if they are not supplied as parameter, and in our footer we put the /body and /html tags. Now, our typical pages look like
    <%@ taglib tagdir="/WEB-INF/tags" prefix="custom" %>
    <custom:header title="Page title" />
    ... page content
    <custom:footer />Now, if we want to change some attribute for the whole page, or to put a signature in each page, we just have to change the corresponding .tag file and the whole site is update.
    Also, .tag file can be used to display selectively page fragment.
    Take a look at Sun's tutorial for more info:
    http://java.sun.com/webservices/docs/1.3/tutorial/doc/JSPTags5.html#wp89664
    Hope this helps!
    Patrick

  • UseBean tag location

    I have a small login application that uses JSP pages and servlets and EJBs. The flow of the application is as follows:
    login form (jsp) posts to:
    servlet that calls a login method of a bean, redirects to:
    logged in page (jsp) links to:
    change password form (jsp) post to:
    servlet that calls bean method to change password, redirects to:
    logged in page.
    My question:
    The bean with the login method is first created on the login form with a useBean tag. This one works just fine. However the bean with the change password method cannot be found with a request.getAttribute as the other bean can be. This is true when I first create this bean on the change password form with a use bean tag. Strangly enough if I put this useBean tag on the login form (the page I run from Jdeveloper) I have no problem using the request.getAttribte method. Both beans have a scope of session.
    Can any tel me why this is?
    null

    Thank you very much! My problem has been solved. I did not know that JBOSS or Tomcat do not support non packaged java bean any more.
    Xin

  • I need to monitor a transducer block parameter and save it to a CSV file.

    How can I monitor a transducer block parameter and save it to a CSV file?  The reason is that I need to do some long-term testing of an FFb device we are developing, and I need to read the primary output parameter of the transducer block (not the scheduled AI block) every second or two and save to a CSV file.
    I have tried to figure out a way to do that with FBUS Configurator, unsuccessfully, and I purchased FBUS Monitor, as that was recommended by an industry expert, but I have been unsuccessful at getting that to work as well.

    Hi Wpinson,
    Neither FBUS Configurator nor Monitor can meet your requirement. However, there are other approaches. NI-FBUS provides APIs for C, LabVIEW, VB and C#. You can use these APIs to read a parameter value of any block and use standard file IO functions to save the date into CSV file. The LabVIEW APIs are highly recommended because they are easy-to-use and LabVIEW also provides APIs for CSV file operations. You can build the application w/ LabVIEW in a short time.
    You can find the examples of the FBUS APIs in the following folders:
    1. C: C:\Program Files\National Instruments\NI-FBUS\MS Visual C\examples
    2. VB: C:\Program Files\National Instruments\NI-FBUS\MS Visual Basic\example
    3. C#: C:\Program Files\National Instruments\NI-FBUS\MS .NET\examples\CsharpExample
    4. LabVIEW: search "fieldbus" in the LabVIEW example finder.

  • (ios5 ipad bugs)I can't get changes of album art, artist, album and other tags to show up in the iPad music player, but they show up correctly in the iTunes device view. Certain random songs do not sync correctly.   Wifi sync hasn't worked yet.

    (ios5 ipad bugs)I can't get changes of album art, artist, album and other tags to show up in the iPad music player, but they show up correctly in the iTunes device view. Certain random songs do not sync correctly.   Wifi sync hasn't worked yet.
    I mostly use technology for education and professional audiovisuals and lights.
    I don't sync  music because I use music from at least 4 different computers. (manually mange music)
    I use my iPad to play performance tracks for church and a local gospel group out of our church, Won4Christ.
    I chose to buy the iPad because the laptop of one of the group members (dellxps running iTunes) was randomly losing and mixing up music and I wanted a more stable option that was bigger than my iPod touch.
    I tried to add some data to music libraries that I previously added to my iPad, but the data only shows up when looking at the device in iTunes.
    Wifi sync has not worked on either my laptop or desktop ( both running windows 7 enterprise 64 and newest iTunes) not really a big issue, but very annoying
    When browsing through library playlist albums on the iPad, random artwork shows up on playlists with no artwork that you touch while dragging, and it does not go away until you change to another navigation tab and back.
    Random songs out of hundreds that I added showed up in iTunes grayed out with a sync circle beside them.  Those songs would play back okay on the iPad but were unplayable through the iTunes device view.  I had to delete the songs manually through the library along with the playlist and add them again. 
    These seem to be major stability bugs in the "new" music app and iTunes.  My only option right now seems to be to delete the songs that I want to change and re-add them with the changes already applied rather than changing the id3 tags and artwork on the existing music. I hope apple will release updates to resolve these issues. 
    Thank you for actually making it to the end of this manuscript of annoyances.

    Just wondered if anyone had any other suggestions.

Maybe you are looking for

  • How to edit contents of Form in PE51 in  HR Module

    Dear Experts, I need to add some fields in Payslip through PE51 and edit some field also,pls tell me how to do it. Thanks n regards Anwar Edited by: Anwar Jamal on Feb 15, 2008 2:25 PM

  • Numbers functions problem

    I can't get my functions to show.  I have used them before but can't now.  If I dump the Numbers program and reload will I be charged again and wii I lose my spreadsheets?

  • RE: Accessing multiple Env from single Client-PC

    Look in the "System Management Guide" under connected environments page 72. This will allow services in your primary environment to find services in your connected environment. However, there is a bug reported on this feature which is fixed in 2F4 fo

  • Does TV have to be on for sound?

    I'd like to be able to feed ATV sound directly to my stereo and listen to music with the TV power off. Will ATV audio output still play with the TV off or does it stop playing sound if no TV is detected. (I'd like to avoid experimenting with the wiri

  • Adapter Status Grey and Cache Error in acessing Integration Directory

    Dear All While going through the following path RWB-->Component Monitoring->Adapter Engine->Cache Connectivity Test i got the following result " Cache notification from Integration Repository failedError when accessing the Integration Directory " RWB