Writing JSP dynamically & using  JSP includes

Need help with this one --
I am pulling data from various fields of the DB and then placing the data into session vars so that based on what a user selects, the right information is displayed.
My problem is this - I want to be able to display a jsp include file based on what the user selects. So the flow would go something like this
EXAMPLE
// USER selects a fruit (from a drop-down form) --> apple
"apple" is stored in session var named fruit.
// USER SUBMITS and expects to see a page based on his <%=fruit %> selection.
//show_page.jsp
I want to use the include tag that will call the right page based on the user selection -- like this:
<%@ include file="<%= fruit%>.jsp" %>
And in my thinking this would return - <%@ include file="apple.jsp" %> and thus include the right file for the user.
Anyone know if embeding JSP to include a session var is possible?
Thanks for any help
Mark
I know my synax is wrong. It's like I'm trying to embed a JSP tag inside inside a JSP include tag.
Is there any way to do this

learn the syntax...you won't get so many errors.
"Professional JSP", WROX Press is great.
scriplets ("<%....%>") can't have action tags in them.
example:
<%
String include = "some_page.jsp"
%>
<jsp:include page="<%=include%>" />
good luck.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Please!!!!!!   How can i add rows in html table dynamically [use jsp,bean]

    hello, i am a fresher in jsp. i want to add new rows in html table dynamically.In my coding, just only shows in one row . please help my problem with correct coding and i don't want to use database. Thanks ...............!
    Here is my coding-------------------
    ---------------- form.jsp --------------------->
    <%@ page import="java.util.*,newtest1.Validation" %>
    <jsp:useBean id="mybean" scope="page" class="newtest1.Validation" />
    <jsp:setProperty name="mybean" property="name" param="name" />
    <jsp:setProperty name="mybean" property="age" param="age" />
    <% s[i][j] %>
    <html>
    <head><title>Form</title></head>
    <body>
    <form method="get">
    <table border="0" width="700">
    <tr>
    <td width="150" align="right">Name</td>
    <td width="550" align="left"><input type="text" name="name" size="35"></td>
    </tr>
    <tr>
    <td width="150" align="right">Age</td>
    <td width="550" align="left"><input type="text" name="age" size="35"></td>
    </tr>
    </table>
    <table width="100%" border="0" cellspacing="0" cellpadding="5">
    <tr><td> </td></tr>
    <tr><td><input type="submit" name="submit" value="ADD"></td></tr>
    <tr><td> </td></tr>
    <tr><td width="100%" align="center" border=1>
    <% int count=mybean.getStart();
    for(int i=count; i<count+1; i++) { %>
    <tr>
    <td><jsp:getProperty name="mybean" property="name" /></td>
    <td><jsp:getProperty name="mybean" property="age" /></td>
    <td><%= count %></td>
    <% count+=1; %>
    </tr>
    <% } %></td></tr>
    </table>
    </form>
    </body>
    </html>
    ----------------- Validation.java ----------------->
    package newtest1;
    import java.util.*;
    public class Validation {
    private String name;
    private String age;
    static int start=0;
    public Validation() {    name=null;
    age=null;
    ++start;}
    public void setName(String username) { if(username!="")
    name=username;
    public String getName() { return name;  }
    public void setAge(String userage) {  if (age!="")
    {age=userage;}
    public String getAge() {  return age;   }
    public int getStart() {
    return start; }

    Hi, Do you mean to say,
    You have an HTML page in which you have a text field and an add button. If you enter anything in that text field and click on Add button the text field contents should be displayed in the same HTML page and you should be able to go on entering new values into the text field and you should be able to retain and display all the previously entered values..
    and finally the list of added items are not stored in the database..
    If this is the case
    i. Your html form should be submitted to the same page.
    ii. You need to have a Vector which holds the entered values.
    iii. Bind the vector object to the request object and collect the same vector object from the request and display its contents...
    I think this would help...

  • How can I write the action attribute of a form dynamically using JSP

    I would like to do something like this:
    If the 'Accept-Language' of the http request is 'en', write out this in JSP:
    <form name='myform action="http://127.0.0.1/myservlet/en/>
    else if
    the 'accept-language' is 'es', write out this instead:
    <form name='myform action="http://127.0.0.1/myservlet/es/>
    else if no match
    <form name='myform action="http://127.0.0.1/myservlet/default/>
    How can I do that in JSP? I think this is simple enough so that I don' t need to use any of the Java Web framework/Java Beans.
    Thank you for any help.

    you can use a simple javascript for this:
    function setAction(lang){
       if(lang=="en"){
         document.forms[0].action="putYourservletUrlhere";
       }else if(lang=="es"){
         document.forms[0].action="putYourservletUrlhere";
       }else{
         document.forms[0].action="putYourservletUrlhere";
    }

  • Plese Help...i have to create a table dynamically using JSP

    Hi all,
    Depending upon what user fills as year & month I have to create a table dynamically.The table should look like this...
    DAY     S     M     T     W
    DATE     1     2     3     4
    Name1     -     -     -     -
    Name2     -     -     -     -
    I know how to get total no available days of any month so i'll use for loop to create <tr>
    The info i need is-
    How to get the first day of the month ,the user entered using calendar because the first row should start with it.
    and the second thing is...
    How to keep incrementing it in the loop..like after sun-->mon-->tue....sat-->sun....
    & also..sat & sun cols should be of different colors than other weekdays
    Please help me.

    Sounds like you already knows about the Calendar class. You should use that class to get the first day of the month.
    Kaj

  • Can I have a JSP  inside another JSP??

    if so,
    say, I have a JSP inside another JSP then,
    how many servlets r generated by the JSP engine??

    Yes U can have JSP inside another JSP, ofcourse using jsp:include and in that case two servlets will be generated. Thats what i feel that happens.

  • How to dynamically include jsp files using jsf el in include tag ?

    Hi,
    I'm trying to get the jsp file name from my backing bean to use it in an include tag but I can't make it work
    When using this piece of code I can get the generated path
             <h:outputText value="/_partial/#{myBean.jspName}.jsp"/>whereas in this code the jsf el is not replaced by this value.
            <%@ include file="/_partial/#{myBean.jspName}.jsp" %> Have you any idea of how to solve this ? I'm currently developing for J2EE 1.4 platform.     
    Thanks for your help,
    Regards.

    If you're using JSF 1.2 and JSTL 1.2 at a JSP 2.1 environment, then you can just use <jsp:include> with unified EL.
    If you're using JSF 1.1, then you may find this article useful [http://balusc.blogspot.com/2007/01/dynamic-jsf-subviews.html]

  • Writing Html Content into PDF using JSP

    Dear All,
    I am using JSP to generate Employee payslip dynamically. Presently i am diplaying payslip as on-screen display.
    Here i want to give option "Save as PDF". I am able to create PDF file using IText Libraries. i want to integrate HTML code into the PDF file.
    Writing HTML Content (using HTML Tags) into PDF.

    Well it is a difficult ask and i believe we are trying to re-invent the wheel
    Just to make my life simple i could have choosen either sample API given below to serve my cause
    1).[http://xmlgraphics.apache.org/fop/] (Apache FOP one can simply write an XSL template of their and then substitute the values from respective DTO's by using XSL - XML transformations and can generate content in different formats which includes PDF aswell)
    2).[http://jasperforge.org/plugins/project/project_home.php?group_id=102] (Just design a simple report template using iReport and create a jrxml files and write a small code snipett such that you can pass few details at the runtime and can export the report in different formats which includes PDF aswell)
    3).[http://www.object-refinery.com/jfreereport/] (Is much similar to what jasper offers in order to compile these you can either use pentaho product IDE or BEA/Oracle Actuate report tools)
    You can simply try searching for different examples for getting more help on using the respective API's
    Hope that helps :)
    REGARDS,
    RaHuL

  • Dynamic select using jsp?

    grrrrr............ok so I'm kinda new to this, and just a little frustrated. I'm gonna ramble here, so any time I sound like I don't know what I'm talking about it 's because I don't..correct me. I want to include a bean in a jsp which will buil d a dynamic select box on the fly. That is, connect to an LDAP db and place each value returned in the query in a select box. Now, I can compile and run the bean in my IDE and watch the output in the console. It's correct because I see "<select><option value = hall>hall....</select>". In the buildSelectBox() method I'm using System.out.println to display each line of my select box (is that right?). Now, when I copy the .class file over to the server I was initially getting an error because the bean wasn't found. I resolved that by properly compiling the bean in a package. Problem is that if I call the bean.buildSelect() method in the .jsp nothing comes back. The page is left blank. What in the world is that about? Can someone push me toward a tutorial that can push me in the right direction or sumthin? Why am I having so much trouble with this? Should I be building the select on the jsp?
    regards,
    mat

    Hi!
    If i understand you correctly :-) you are doing not very right things. I don't want it to seem like I'm going to teach you, but:
    The Bean that has buildSelect() method is not a bean at all. Usualy Beans contain getter/setters and accumulate data. If you want to build html code dynamicaly then you should use servlets(Which is not very flexible in your situation, I think), not JSPs. And if you are using JSPs then you have to make Tag which will do this everything.
    Other way is to use Struts framework which is very good and flexible for building web applications - it has it's own tags for many cases. You can make loops in JSPs, use beans and all that stuff.
    Guys will correct me if I missed something.
    Good luck

  • Using jsp:include in showOneTab - main form not loaded on submit

    I have a JSP page with JSF and ADF components. It is a large JSP containing some main details and then an af:showOneTab component to create a set of tabs. It works fine with JDK 1.5 and Tomcat 5.0 but when changed to Oracle Application Server 9.0.4 and JDK 1.3 We get the following error:
    JspCompileException:.... code too large for try statement catch( Throwable e}....
    Finding this to be caused by large size of JSP, we divided the page as follows - a main jsp containing the main form details and 1 jsp for each tab. Whenever one of the tabs is clicked the corresponding JSP is dynamically loaded using jsp:include tag as follows:
    <af:showDetailItem text="Tab1" id="tab1" styleClass="menu">
              <f:subview id="viewTab1">
                   <jsp:include page="Tab1.jsp" />
              </f:subview>
    </af:showDetailItem>
    There is a Submit button in the main jsp, when this is clicked the main jsp is reloaded.
    But when the user navigates to any of the tabs and then clicks the Submit button in the main form, the main form is not reloaded - only the jsp for the currently selected tab is loaded.
    (I am using f:view and h:form in the main form, and no form tag in the included jsps)
    How to solve this problem?

    The af:selectOneChoice components are in the test.jsp page included in main.jsp with jsp:include tag.
    The code look like this:
                   <af:selectOneChoice label="#{msg.team}"
    id="soc1"
    value="#{myBean.selectedTeamID}"
    autoSubmit="true">
    <f:selectItems id="si1" value="#{myBean.teamList}"/>
    </af:selectOneChoice>
    <af:selectOneChoice label="#{msg.subteam}"
    id="soc2"
    value="#{myBean.selectedSubteamID}"
    partialTriggers="soc1"
    rendered="#{myBean.selectedTeamID!=null}"
    autoSubmit="true">
    <f:selectItems id="si2" value="#{myBean.subteamList}"/>
    </af:selectOneChoice>
    the code works fine in the seperate page, but when I include the page the second selectOneChoice component doesnt get rendered.
    Edited by: Migan on 2010-jul-13 08:36

  • ADF FACES EA16 Why survey demo don't use jsp:include for common part

    Is it a reason why the surveyPage1, surveyPage2 and others don't use jsp:include to load dynamically the actions, menuglobal and location facet ?
    These facet's contains the same adf components with same properties !
    Why not use a subview containing these flow management component and include this subview in the panelpage with the jsp:include ?
    I'm testing this approach but i'm not able to render these components ... may be i'm completely wrong ? I didn't find any example in the demo that demonstrate how to include subview in an adf document or panelpage.
    Help will be appreciate a lot !!!

    so what exactly is the problem here?
    what is not working?

  • Problem when using jsp:include.. / in JSP when run on OC4J903

    I have a very unusual JSP question when run in OC4J903(EM or standalone) version (previous OC4J version was ok). Here is the description
    1. run P1.jsp and a parameter(text1) will pass to P2.jsp
    2. In P2.jsp, include "includePage.jsp" before show the parameter.
    question:
    1. The P1.jsp parameter will be null if using "POST" method, but "GET" is work.
    anyone have a indea ? or is that a bug in OC4J903 version
    P1.jsp
    <html>
    <head>
    <title>Test</title>
    </head>
    <body>
    <form method=POST action='P2.jsp'>
    <input type=text name='text1' size=30>
    <input type=submit value='OK'>
    </form>
    </body>
    </html>
    P2.jsp
    <html>
    <head>
    <title>Test</title>
    </head>
    <jsp:include page="includePage.jsp" flush="true">
    <jsp:param name="importParam" value="P2 Export" />
    </jsp:include>
    <body>
    <%
    out.print("Here shows the param from P1: " + request.getParameter("text1")+"<br>");     
    %>
    </body>
    </html>
    includePage.jsp
    <%@ page import="java.io.*"%>
    <%
    out.print("Here runs the include page. The param from P2 is: " + request.getParameter("importParam")+"<br>");
    %>

    I have a very unusual JSP question when run in OC4J903(EM or standalone) version (previous OC4J version was ok). Here is the description
    1. run P1.jsp and a parameter(text1) will pass to P2.jsp
    2. In P2.jsp, include "includePage.jsp" before show the parameter.
    question:
    1. The P1.jsp parameter will be null if using "POST" method, but "GET" is work.
    anyone have a indea ? or is that a bug in OC4J903 version
    P1.jsp
    <html>
    <head>
    <title>Test</title>
    </head>
    <body>
    <form method=POST action='P2.jsp'>
    <input type=text name='text1' size=30>
    <input type=submit value='OK'>
    </form>
    </body>
    </html>
    P2.jsp
    <html>
    <head>
    <title>Test</title>
    </head>
    <jsp:include page="includePage.jsp" flush="true">
    <jsp:param name="importParam" value="P2 Export" />
    </jsp:include>
    <body>
    <%
    out.print("Here shows the param from P1: " + request.getParameter("text1")+"<br>");     
    %>
    </body>
    </html>
    includePage.jsp
    <%@ page import="java.io.*"%>
    <%
    out.print("Here runs the include page. The param from P2 is: " + request.getParameter("importParam")+"<br>");
    %>

  • DYNAMIC TABLE CREATION USING JSP

    I WANT TO CREATE A DATABASE TABLE IN AN INTERACTIVE WAY ie MY QUESTION IS: HOW TO CREATE A TABLE USING JSP WITH TWO ARRAYS(FIRST ARRAY CONTAINS FIELD(COLUMN) NAMES AND THE SECOND ARRAY CONTAINS ITS CORRESPONDING DATATYPE)BOTH ARRAYS ARE OF VARYING SIZE.IF THE USER ENTERS SUPPOSE '6' AS THE INPUT TO FORM A TABLE OF 6 FIELDS SO, THE QUERY SHOULD BE DYNAMICALLY FORME USING THE ARRAY NAME FOR FIELD AND THE ARRANAME FOR ITS CORRESPONDING DATATYPE.HAVE ANY IDEA ON THIS PLEASE LET ME KNOW.
    THANKS

    u need to know quite a few java technologies to make archieve your dream.
    JDBC, dynamic array and JSP.
    after reading tutorial regarding to these 3 materials, you should be able to get your job done.

  • Dynamic Tree Creation using JSP, Struts framework

    I urgently require tips/information/code snippet for creating a Dynamic Tree structure.
    Tree is the hierarchical folder structure that we see in windows operating system.
    Dynamic tree in the sense that all nodes shall be populated from database & a radio button shall be present at each node that can be selected & submitted to form.
    Tree should be done using JSP (& if required Javascript).
    I am using Struts framework .
    [email protected]

    u need to know quite a few java technologies to make archieve your dream.
    JDBC, dynamic array and JSP.
    after reading tutorial regarding to these 3 materials, you should be able to get your job done.

  • Problem using jsp:include from inside a custom tag

    Hi, All !
              I have a problem using <jsp:include> from inside a custom tag. Exception is:
              "java.lang.ClassCastException: weblogic.servlet.jsp.BodyContentImpl"
              Apparently, weblogic tries to cast BodyContentImpl to JspWriterImpl and
              could not do this. Is it a bug, since in the 1.1 spec is said: "The
              BodyContent is a subclass of JspWriter that can be used to process body
              evaluations so they can retrieved later on."
              My code is:
              <wfmklist:items>
              <jsp:include page="item.jsp" flush="true"/>
              </wfmklist:items>
              

    This is an area of contention with WL. It is not so tolerant with regards to
              the spec. I spent several days recently trying to convince it to accept the
              specification in regards to bodies and includes and it appears to have
              successfully rebuffed my efforts.
              Frankly, this is very disappointing. It appears that some shortcuts were
              taken on the way to JSP 1.1 support, and the result is a very hard-coded,
              inflexible implementation. As I have not seen the implementation myself, I
              hate to assume this, however one could posit that the term "interface" was a
              foreign concept during the implementation, other than as some annoying
              intermediary reference requiring an immediate cast to a specific Weblogic
              class, which in turn is apparently required to be final or have many final
              methods, as if being optimized for a JDK 1.02 JIT.
              I am sorry that I don't have any positive suggestions other than to use a
              URL object to come back in an execute the necessary "include" directly. You
              lose all context (other than session) and that can cause its own problems.
              However, you can generally get the URL approach to work, and you will
              hopefully avoid further frustration.
              Peace,
              Cameron Purdy
              Tangosol, Inc.
              http://www.tangosol.com
              Tangosol: How Weblogic applications are customized
              "Denis" <[email protected]> wrote in message
              news:[email protected]...
              > Hi, All !
              > I have a problem using <jsp:include> from inside a custom tag. Exception
              is:
              > "java.lang.ClassCastException: weblogic.servlet.jsp.BodyContentImpl"
              >
              > Apparently, weblogic tries to cast BodyContentImpl to JspWriterImpl and
              > could not do this. Is it a bug, since in the 1.1 spec is said: "The
              > BodyContent is a subclass of JspWriter that can be used to process body
              > evaluations so they can retrieved later on."
              >
              > My code is:
              > ...
              > <wfmklist:items>
              > <jsp:include page="item.jsp" flush="true"/>
              > </wfmklist:items>
              > ...
              

  • Using jsp:include in jsf

    I want to include a jsp page in another jsp page. My code is as follows:
    1)
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jstl/core"
    version="2.0">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Page Title</title>
    </head>
    <body>
    <f:subview id="sub">
    <jsp:include page="/demo.jsp"/>
    </f:subview>
    </body>
    </html>
    </jsp:root>
    2) demo.jsp is given below
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jstl/core"
    version="2.0">
    <ui:composition>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Page Title</title>
    </head>
    <body>
    <h:outputText value="Hello"/>
    </body>
    </html>
    </ui:composition>
    </jsp:root>
    but when i run this application i get error as follows:
    javax.servlet.ServletException: @15,48 <jsp:include> Tag Library supports namespace: http://java.sun.com/JSP/Page, but no tag was defined for name: include
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:270)
         org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
         org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
         org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
         org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)

    You're mixing two view technologies with each other: JSP and Facelets. You cannot do that. Use the one or the other. In Facelets you can just use <ui:include>. Leave all of those legacy <jsp> tags out when using Facelets.
    By the way, although the <f:subview> is superfluous in Facelets and only used in JSP, I wanted to tell you, this tag is better to be placed in the include file, not in the parent file. Otherwise you may risk "duplicate component ID" problems.

Maybe you are looking for

  • One characteristc for multiple plants

    Hello All, In our project we have two company codes and two plants in each company code. In first company QM module is already implemented and we are doing roll out for second company codes. Major QM activities and batch charactristics are same as pr

  • How can I buy LR4+PS6?

    Hi, I would like to get the chance to buy LR4 and Photoshop CS6 instantly in order to get the discount that Adobe is offering (I want to buy the downloadable version of both programs), but I cannot figure out the way to buy both programs at once, jus

  • Reverse event bubbling/dropping

    Hi! I use custom components to organize my application. Event bubbling from a nested component to the application works fine. Is it also possible to notify any component tested in the application with an event triggered by the appplication or another

  • Iweb on Google

    I have just received my copy of Ilife 06 and now want to create a web site for my music school in the UK. If I use a .mac account with the long web address how do I get my web site on the google search engine. I have looked at many of the sites made

  • Long placeholder and Textarea

    Developing web Long placeholder doesn't return to the line if the size exceed the textarea size. happen only on Safari, but when i put a long text into the placeholder on my textarea it doesn't return to the line, it's like if the overflow of the tex