Using jsp variables within JSP tag

I have a variable defined within a JSP:
<%
String cust_id = request.getParameter("cust_id");
%>
I want to use this variable as a parameter to a custom tag:
<%@ taglib uri="/tlds/DBTags.tld" prefix="db" %>
<db:MultiColumnSelect columns="c.id, c.po" name="ccar_id" table_name="ccar_headers c, ccar_rmas r" selectString="r.ccar_id = c.id AND c.cust_id = <%= cust_id %>"/>
The selectString value that is passed to my tag is:
r.ccar_id = c.id AND c.cust_id = <%= cust_id %>
The <%= cust_id %> is not replaced by the actual variable value.
How would I accomplish using this variable within my JSP tag?

Your definition of the selectString attribute must indicate that it can accept runtime expressions.
<%
String cust_id = request.getParameter("cust_id");
String selectString = new String("r.ccar_id = c.id AND c.cust_id = " + cust_id);
%>
<%@ taglib uri="/tlds/DBTags.tld" prefix="db" %>
<db:MultiColumnSelect columns="c.id, c.po" name="ccar_id" table_name="ccar_headers c, ccar_rmas r"
selectString="<%= selectString %>"/>

Similar Messages

  • How to use session variable in JSP function  & How to use both JSP  Servlet

    Hi,
    I am new to JSP and servlets
    Still I am devloping a website in JSP. I am not mixing JSP with servlets, but I do create Java files for bean, logic and database works.
    I try to keep the hard coding part out of JSP.
    I dont how to use both JSP and Servlets in combination.
    Hence If needed I write some functions in JSP.
    but it gives me error
    +<%! public void abc()+
    +{+
    int intUserId = Integer.valueOf((Integer) session.getAttribute("MySession_UserID"));
    +}+
    +%>+
    Saying cannot find symbol session
    1) So can u please tell how can I access session variables within JSP function
    2) And also give me some links/tutorials about useing both JSP and Servlets in combination.
    Thanks
    Venkat

    The application architecture when you use Servlets and JSP in a standard MVC pattern is explained here (under the heading "Integrating Servlets and JSP Pages") and here ...

  • Using JSTL variables in JSP or Javascript. Possible ?

    Hi All,
    Is it possible to share or use the variables which are declared are used by JSTL in JSP expression or scriplet code and in Java Script.
    Example:
    This Works:
    <fmt:set var="test" value="JSTL" />
    <fmt:out value="${test}" />
    But, this gives error:
    <% out.println(test) %>
    And passing the value of variable 'test' to Java Script code also gives error.
    How to use JSTL variables in JSP and in Javascript ?
    Yours,
    Sankar.B

    By default, JSTL variables are kept in servlet
    attributes. Default is to store it in the page
    context. You can make it request/session/application
    scope as required by an attribute of the set tag.Hi there,
    Can anyone advise how to access JSP variables in JSTL?
    Can it be done as the same method through request/session/application scope?
    Thnks...

  • How to use bind variables in JSP applications ?

    Hi,
    How will i use bind variables in jsp applicaions ?
    Any links that give a clear understanding ?
    TIA,
    jj

    Hi,
    Try this link, this may help you.
    http://www.oracle-base.com/articles/misc/WebScriptingForOracle.php
    Thanks

  • How to use a variable of jsp custom tag in my java code?

    hi folks,
    i got a folderList tag like this:
    ArrayList list = new ArrayList(20);
    %>
    <foo:folderList path="${attributes.newsPath}" var="year" contentType="folder">
    <%
              list.add(${year.contentEntryName});   // of course, this doesn't work
    %>
    </foo:folderList>I think, its clear what I want to do. I am just wondering how I can use my Variable "year" in the Java code between <% %>...

    <% list.add(year.getContentEntryName()); %>
    You have to have defined in the custom tag that "var" relates to a scripting variable that you want defined.
    <tag>
      <variable>
        <name-given>var</name-given>
        <variable-class>myPackage.myClass</variable-class>
        <declare>true</declare>
        <scope>NESTED</scope>
      </variable>
    </tag> Cheers,
    evnafets

  • Accessing JSP Variables in Custom Tag Handler.

    Hi,
    I am creating a custom tag which builds a list view. I have certain String array in my JSP and I need to pass the same into my Tag Handler class. I tried following ways :
    1. In doStartTag() implementation I used
       public int doStartTag() {
             String[] myArray = (String[])pageContext.getAttribute("mystringarray", PageContext.PAGE_SCOPE;
       }This is not recognizing the String array variable defined in my JSP.
    2. I used separate attribute which is passed from the JSP to the custom tag as parameter having "rtexprvalue" as true. But I cann't pass a Sting array into my tag handler class. I can pass only String.
    How can I access variables which are defined in the JSP using declaration block. i.e.
    <%!
    String[] myArray = new String[100];
    %>
    Thanks for the time.

    You should be able to pass any type you like as an attribute to the tag.
    You just have to define its type as String[] in your tld:
    <attribute>
    <name>stringArray</name>
    <required>false</required>
    <rtexprvalue>true</rtexprvalue>
    <type>java.lang.String[]</type>
    </attribute>
    Alternatively, If you declare your array like:
    <%!
    String[] myArray = new String[100];
    %>You can do this:
    pageContext.setAttribute("mystringarray", myArray);
    which will put it into the page context for you to pick up in your custom tag.
    Hope this helps,
    evnafets

  • Using bean methods within JSP declaration

    Is it true that bean methods will not work in JSP Methods ?
    For example:
    // get the bean
    <jsp:useBean id="FormValidate" scope="session" class="fsm.frontendCtr.FormValidate" />
    // build a new method in jsp
    <%!
    boolean validate(HttpServletRequest req, String submitFlag) {
    FormValidate.checkMandatory("ADRNACHNAME");
    %>ServletExec return:
    Undefined Variable or class name: FormValidate
    If i use the bean Methods outside the method it worx.
    Is there a trick with which I can use BeanMethods in a JSP Method?

    Is it true that bean methods will not work in JSP
    Methods ?
    For example:
    // get the bean
    <jsp:useBean id="FormValidate" scope="session"
    class="fsm.frontendCtr.FormValidate" />
    // build a new method in jsp
    <%!
    boolean validate(HttpServletRequest req, String
    submitFlag) {
    FormValidate.checkMandatory("ADRNACHNAME");
    %>ServletExec return:
    Undefined Variable or class name: FormValidate
    If i use the bean Methods outside the method it worx.
    Is there a trick with which I can use BeanMethods in a
    JSP Method?FormValidate is this Object. If you need others, pass them from parameters. Try to understand the structure of servlet generated by your JSP.
    <%!
    boolean validate(HttpServletRequest req, String submitFlag) {
    this.checkMandatory("ADRNACHNAME");
    %>
    hope this helps,
    yang

  • How do I use a variable within a sql statement

    I am trying to use a local variable within an open SQL step but I keep getting an error.
    My sql command looks like this "SELECT BoardDetailID FROM BoardDetails WHERE SerialNumber = " +  locals.CurrentSerialNo
    If I replace the locals.CurrentSerialNo with an actual value such as below the statement works fine.
    "SELECT BoardDetailID FROM BoardDetails WHERE SerialNumber = " +  " 'ABC001' " 
    Can someone tell me how to correctly format the statement to use a variable?

    Hi,
    Thanks for the reply. I have changed the required variable to a string, but with no success. I have reattached my updated sequence file and an image of the error.
    When looking at the Data operation step I see that the sql statement is missing everything after the last quotation mark.
    Thanks again,
    Stuart
    Attachments:
    Database Test Sequence.seq ‏10 KB
    TestStand error.JPG ‏37 KB

  • Using CPM Variable within SEM BSC

    Hi,
    My client would like to have scorecard in Europe. he would like also drilldown through different structure :
    - Europe
       - Country (France, UK...)
         - Department (HR, Finance)...
    I thought It was possible to use CPM variable with Structure object and create only one scorecard (scorecard is the same for every structure). Unfortunately, I didn't success in using CPM variable.
    Is there a way to achieve this (creation of multiple scorecards...) ?
    Thanks in advance

    Hi,
    Thanks for your answer.
    I agree with you when you say that if you maintain values in CPM variable, it will point to either cointinent or country and not both. That's what we want.
    I need to know the best way to have a scorecard for Europe, one for France, one for UK....
    Do we have to create one scorecard by element or is it possible to use CPM variable to achieve this ?
    I didn't find a way, as we can do in Management cockpit, to change directly in the presentation the value of the variable CPM.
    Thanks in advance

  • Javazoom UploadBean - using UploadBean properties within jsp tags

    I am working on a jsp web application and integrating the UploadBean from javazoom.net into it. I am using a MySQL database to capture all informaion about mp3 files being uploaded - filename, date, filetype, etc.
    Can someone guide me as to whether it is possible to reference the properties of the UploadFile class within a jsp tag?
    What I am trying to do is this - I want to capture the filename of the file I upload and store it in a MySQL database. Within the SimpleUpload.jsp page, the filename is accessed within scriplet code as follows:
    file.getFileName();
    (Where file is a variable representing an instance of the UploadFile class, and getFileName() is a method in this class that returns the file name you are uploading).
    What I would like to do is use this method so that this same filename can be used in a a sql:update tag to populate a database with the filename and with the other details of the file which is uploaded.
    Can anyone advise as to if this is possible and how? I tried to create a sql:update statement to populate the database with the result of file.getFileName();
    The problem is that the sql:update jsp tag can't see the file.getFileName() object and method - it doesn't know about this object and method.
    Thanks!

    I'd still appreciate an answer to this if anyone can help.
    Thanks.

  • How to use enviroment variables in JSP code?

    I�m developing a web server with JSP�s, and I need to move the application to others computers. I need to access to a directory, but I don�t know it because the user can install the Application in the directory he wants. So I need to access to that directory in the JSP code.
    The directory is "C:\Program Files\....\tomcat\webapps\ROOT\upload". I have the CATALINA_HOME enviroment variable defiened as "C:\Program Files\....\tomcat\", so I need to use something like "CATALINAHOME\\webapps\upload\", but I don�t know how to mekr the JSP code to understand the enviroment variable CATALINA_HOME.
    I�ve tried with %CATALINA_HOME%, but the Tomcat server doesn�t recognize it. How can I access to that directory?
    Thanks (Sorry about my english)

    My JSP�s are in: %CATALINA_HOME%\webapps\ROOT\
    I wan�t to access to %CATALINA_HOME%\webapps\ROOT\upload\
    My JSP code:
    <% ...
    String DPATH = "C:\\Program Files\\JBuilder7\\jakarta-tomcat-4.0.3\\webapps\\ROOT\\upload\\";
    File newfile = null;
    newfile = new File(DPATH+filename);
    %>
    I want the JSP to locate the directory \webapps\ROOT\upload\ without knowing the complete route "c:\Program Files\...", because I have the enviroment variable CATALINA_HOME with the value "C:\Program Files\JBuilder7\jakarta-tomcat-4.0.3\". SO the user of the aplication only has to set the CATALINA_HOME variable and the aplication should access the upload directory throught the CATALINA_HOME variable.
    I can�t explain it better. Sorry.

  • Using Javascript variable in JSP

    I m setting a variable named btn to the value of the button which was clicked but the problem here is that i m nt getting its value whn i want to set it to a request.setAttribute() method.

    > Yes... nw i get the prob... thanx yaar .... bt cn u
    suggest me wht cn i do fr this situation
    My first suggestion, beyond all others, is to use real words. Your writing is practically unintelligible.
    Please make the extra effort to write out words such as "now", "problem", "thanks", "but", "can", "you", and "for" (I have no idea what "yaar" means). The extra keystrokes won't cost much in the way of time, and the enhanced clarity will be appreciated by those communicating on a forum with international readership. Also, it will give the appearance that you take your question seriously, which will in turn make your question look more interesting to answer.
    ~

  • Using static variables in JSP

    Hi All,
    I have written the following code, but its not compiling saying that "Class or interface declaration expected. static "
    I dotn know whats wrong in this scriplet though.. any help is greatly appretiated.
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!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=ISO-8859-1">
    <title>JSP Scriplet</title>
    </head>
    <body>
    <%
    static int counter = 15;
    for(int i = 0; i < 15; i++){
    int p = returnCounter();
    if(p == 0)
    System.out.println("I am the 15th user");
    public static int returnCounter(){
    counter = counter - 1;
    System.out.println("counter : " + counter);
    return counter;
    %>
    </body>
    </html>

    Simply put, you're Java code is wrong.
    The detail is that essentially all of the code in your JSP file is in one big method.
    So, here's what your code looks like to the compiler:
    public void _internalJspDoPageCode() {
        static int counter = 15;
        public static int returnCounter() {
    }You can't simply nest methods like this in Java.
    If you want to, you can try this:
    <%
        public class mycounter {
            static int counter = 15;
            public static int returnCounter() {
                counter = counter - 1;
                return counter;
        for (int i = 0; i < 15; i++) {
            int p = mycounter.returnCounter();
            if(p == 0)
                System.out.println("I am the 15th user");
    %>That will create an inner class with a static member, which is basically what you're trying to do.
    But note that this inner class is only accessible from this JSP page, and no where else.

  • Problems using a variable with a tag of a webapp

    I have a webapp where I've built a field in the database for the item is active or not, depending if my client chooses if it's free or not.
    The name of the tag that I want to use as a variable is { tag_estado } and has two values:
    Gratis
    Pago
    When in jQuery I create a variable to store the value of this tag and created a conditional to activate the link and icon of the item, always the tag value prints it on "Pago", even though the webapp item has the value of "Gratis"
    I appreciate your time to help me resolve this issue.
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
              var linkleccionGratis = function() {
                        $(".linkLeccion").attr('href', '{tag_itemurl_withhost}?tab=video');
              var linkleccionPago = function() {
                        $(".linkLeccion").attr('href', '#dataaaaaaaa');
              var imagenGratis = function() {
                        $('.videoIcono').each(function(){
                              //Change the src of each img
                              $(this).attr('src', '/Comportamiento-Video/Iconos/1365805563_movie_studio-android-r_1.png');
              var imagenPago = function() {
                        $('.videoIcono').each(function(){
                              //Change the src of each img
                              $(this).attr('src', '/Comportamiento-Video/Iconos/1365805563_movie_studio-android-r_0.png');
        var EstadoLeccion = "{tag_estado}";
              if(EstadoLeccion == "Pago"){
                                  linkleccionPago();
                                  imagenPago();
              else if(EstadoLeccion == "Gratis"){
                                  linkleccionGratis();
                                  imagenGratis();
                        else{
                                  linkleccionPago();
    </script>
    <div style="width: 921px; margin-bottom: 10px;">
    <div class="FranjaSuperiorTituloLeccion">
    <div class="TituloContenedorLeccionWebApp">
    <div class="TituloLeccionWebApp">Lecci&oacute;n {tag_num_leccion}: {tag_titulo_leccion}</div> </div> <div class="ImagenesBotonesLeccionWebApp">
    <a class="linkLeccion" href="#data" id="inline"><img alt="Video" class="videoIcono" src="http://www.excelvirtual.org/Comportamiento-Video/Iconos/1365805563_movie_studio-android-r_ 0.png" style="margin-top: 6px; width: 31px; height: 31px;" />
    </a>
    </div>
    <div class="ImagenesBotonesLeccionWebApp">{tag_actividad url}</div>
    <div class="ImagenesBotonesLeccionWebApp">
    <a href="{tag_cuestionario}" target="_blank">
    <img alt="Cuestionario" src="http://www.excelvirtual.org/nuevodiseno/images/actividaddef2.png" style="width: 41px; height: 41px;" />
    </a>
    </div>
    </div>
    </div>

    It's tough to tell without seeing the page but it looks like your code may be defaulting to the else statement. You could delete the else and see if it does anything

  • How do I use a variable within paragraphFormat?

    I would like to insert the firstname of a client within paragrapgFormat(). ie: paragraphFormat(Hi #firstname#, your info......) When I output this the firstname just shows as #firstname#. Is there a way to get his to work?

    The first instance of 'FirstName' is a variable name. Whereas the last instance is a substring within the string defined by getInfo.message. I am assuming that the message you have saved in the database is:
    "Hi"  & FirstName & ",
      We are writing to you to inform you that we received your request to schedule the...
    You could modify the code as follows. Give the queries separate names, say, getUser and getMessage. Omit the columns userID and messID from the respective queries. This is because the where-clauses already specify the values.
    What you could then do is replace the substring "  & FirstName & " in getMessage.message with the variable getUser.FName. The result would be something like
    <!--- grabbing firstname --->
    <CFQUERY Name="getUser" datasource="#application.dsn#">
    SELECT fNname, lName, email, company, phone
    FROM users
    where userID = 1
    </CFQUERY>
    <cfset firstNameString = " " & trim(getUser.fName) & " ">
    <!--- grabbing message --->
    <cfquery name="getMessage" datasource="#application.dsn#">
    select name, message
    from messages
    where messID = 1
    </cfquery>
    <table width="300" cellpadding="0" cellspacing="0" border="1">
    <tr><td>
    <cfoutput query="getMessage">
    <cfset msg = replaceNoCase(message, '"  & FirstName & "', firstNameString)>
    #paragraphFormat(msg)#
    </cfoutput>
    </td></tr>
    </table>
    Having said that, there are still 2 things I fail to understand. Firstly, why loop across the query when there is just one row? Secondly, why do you save a static message in the database when you could just save it in the CFML code as a string variable?

Maybe you are looking for