Using variables in a jsp:useBean tag

10-11  Source: Network gathering  Views:2 

Advertisement
I was wondeing if it is possible in any way to use variables in a jsp:useBean tag. Here is an example of what I am trying to do.
<%
String beanType = request.getParameter( "bean" );
if( beanType.equals( "Bean1" ) ) {
beanClass = "com.myCompany.Bean1";
} else {
beanClass = "com.myCompany.Bean2";
%>
<jsp:useBean name="<%= beanType %>" class="<%= beanClass %>"/>
I also tried using this approach
<%
if( beanType.equals( "Bean1" ) ) {
%>
<jsp:useBean id="bean" class="com.myCompany.Bean1"/>
<%
} else if( beanType.equals( "Bean2" ) ) {
%>
<jsp:useBean id="bean" class="com.myCompany.Bean2"/>
<%
%>
Neither approach seems to work. Is there any way around this problem?
Thanks,
Marcus.
Hi,
check:
http://forum.java.sun.com/thread.jsp?forum=45&thread=398998&tstart=75&trange=15
Related articles
  • Using variables in a jsp:useBean tag 10-11

    I was wondeing if it is possible in any way to use variables in a jsp:useBean tag. Here is an example of what I am trying to do. <% String beanType = request.getParameter( "bean" ); if( beanType.equals( "Bean1" ) ) { beanClass = &qu

  • Unable to use jsp:useBean tag 11-30

    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

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

    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 a

  • Calling an inner class in a jsp:usebean tag 10-11

    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 paramete

  • Type="Class"  in the jsp:useBean tag 11-30

    Hi every one I create a class named quiz containing four Strings question,answer1,answer2,answer3 I initialize them in the constructor. I made four get methods ...getQuestion(), getAnswer1 ...and so on. I made the class implement the serializable int

  • How to use "scope " attrubute in useBean tag 10-11

    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 Pers

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

    Hi, I just want to know that which one is better to use jsp:useBean or import statement . I can instantiate and call method of myclass - 1) by importing the class through import tag in jsp as <%@page import="myclass"%. or 2). by using <jsp

  • Why do you use jsp:useBean? 11-30

    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 par

  • How can i use JAVA BEAN and JSP? 10-11

    well, i have developed all my web apps by using pure JSP only, i know this sucks, but i dont know how to start on using beans... what directory should i put them into... etc... what are the good programminmg practices/standards/techniques when incorp

  • Using java beans in jsp using tomcat 10-11

    hi i have made a form to enter user first name and last anme with html and then i have made a value javabean in which i want to store the information filled bu user. i want to display the information stored in java bean in jsp page i have made the fu

  • How to use .class files from jsp 11-30

    hi i want to use .class files in my jsp program can any one help meso if you are using pacakges here is normal example... say you .java code is something like... package com.util; public Class BeanUtility{ }place the .class file at WEB-INF/classes/co

  • 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 10-11

     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 qui

  • Using EL variable in struts bean:message tag(not struts EL tag) 10-11

    Is there any work around to use an EL variable inside struts bean:message tag as key: I have like this: <bean:message key="${bean.keyName}"/> which is throwing error , I know this can be resolved by using struts-el tags but i cannot use th

  • Using variables in jsp:include 10-11

    Hello, I'm still working wih the JSP 1.2 specs and I want to use a variable in my jsp:include. For example <jsp:incude page="${vUrl}/> Where vUrl is defined as <c:url value="/doesnotmatter" var="vUrl"/> Something like

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

    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 instan

  • Problem in SELECT TAG using variables 11-30

    Hi all, I have a JSP page which updates the record for a user.Now there is a HTML select tag and when the user queries its data this SELECT tag will automaticaly select the user stored item in database automatically. It means the select tag will have

  • The element type jsp:useBean must be terminated by the matching end-tag 11-30

    Hi, I have deployed an application under WLS 8.1 SP4 and I get this error, when I try to access a page. I searched through the BEA site and it does refer to solution id S-13709 which says issue has been fixed in WLS 7.0. Hence should I not be seeing

  • INSERT statement in JSP using variables 10-11

    People, I am having problems inserting data from JSP into a MySQL database. For example the following works perfectly fine: String query = "INSERT INTO `test2` (`name`, `topic`, `message`) VALUES ('Jane Doe', 'Hi there', 'Example message')"; But

  • How to use JSP custom tag lib in PAR file? 10-11

    Hi All, I am trying to customize mastheaderpar file. For that I have downloaded relevant par file and making the changes accordingly. As part of the changes I would require to use JSP custom tag library in my par file. I have the TLD file and relevan

  • Populating combobox in jsp page from javabean using jsp:getProperty tag 10-11

    hi, i am new to jsp, so i don;t know how to populate a combobox in jsp page with productid attribute from a javabean called Bid . i want to have a code to automatically populating combobox using the attribute value from javabean. please reply me. <js