Using jsp variable in java code

Hey guys,
I need some help hope you guys can help me.
I've declared a variable "error" in a jsp. how do I access this variable in the java code whice resides in the same jsp page.
I know I can use java variable in jsp code using
<%= sVariable %>
where sVariable was declared in the java code. but how do I access a jsp variable in java code??
Thanks very much in advance

Thanks for the reply.
This is what I want to do.
I've declared a variable "error" using <c:catch var="error">I want to check the value of this variable and suppose if it contains XYZ (error variable will have a long string so I just want to check if it contains a specific value) I want to do step1 and if the variable of error is not XYZ I want to do step 2
Problem is I dont know how to check if error contains the XYZ in jsp thats why I thought java code would help here.
Can you guys suggest a better way to solve my problem.
Thanks again

Similar Messages

  • Using JSP variable inside Java Script's alert function.

    Hi Gurus,
    We are trying to use alert function with one of the string variables populated inside JSP code, but its not working.
    Here is the code snippet, please advice.
         <%
         oracle.apps.qot.util.RequestCtx.log("qotcustom.jsp",AOLMessageManager.getMessageSt(QotUtil.QOT_APPS_CODE, "XDPYY_DISC"));
         %>
         var alert_text="<%=AOLMessageManager.getMessageSt(QotUtil.QOT_APPS_CODE, "XDPYY_DISC")%>";
         alert(alert_text);
         Here in the first line we are using API to get text message defined in database, the line is getting executed properly and we could see output text message in debug log file, after this in the 4th line, we are assiging this string output of API to java script variable alert_text and further using alert function with the variable alert_text as argument. But alert function is failing, no errors are thown in debug log file.
    Please advice whether we are doing any thing wrong.
    Thanks in advance.

    What pgeuens means is that you can't mix javascript and jsp/java code in this way.
    ALL of the jsp/java code gets executed at the server end.
    This produces an HTML page (with embedded javascript) which gets sent to the client.
    The client then runs javascript code in response to events (onLoad, onClick, onChange etc etc)
    So in this case, the jsp:forward will always be executed, because as far as the server is concerned, the javascript is just template text.
    If you WANT to do a conditional forwarding on the server side you do it in java ie (horribly using scriptlet)
    <%
    if (testCondition){
    %>
      <jsp:forward>
    %<
    %>Or if you want to test what the client has entered client side, all you can do is submit the form, or navigate to a URL
    <script>
    function test()
    if(document.f.htemp.value=="true")
    alert("jus");
    else
    var s=document.f.htemp.value;
    alert(s);
    document.f1.action="success.jsp";
    document.f.submit();
    </script>You cannot run JSP code based on your javascript code.
    Java. Javascript. Not the same thing.
    Hope this helps,
    evnafets

  • How to use odi variable in java code.

    Hi,
    I am trying to calculate check sum of a file and need to capture that in a odi variable...
    I wrote code like this(selected technology as java bean shell)
    <@
    import java.io.*;
    import java.util.zip.*;
    public class checksum {
    public static void main(String[] args) throws Exception {
    FileInputStream fis = new FileInputStream(new File("c:/dummy.txt"));
    CheckedInputStream cis = new CheckedInputStream(fis, new CRC32());
    BufferedInputStream in = new BufferedInputStream(cis);
    while (in.read() != -1) {
    #checksum = cis.getChecksum().getValue();
    }@>
    But I am not able to get that value...
    I tried in another way like this
    <@
    import java.io.*;
    import java.util.zip.*;
    public class checksum {
    public static void main(String[] args) throws Exception {
         long result;
    FileInputStream fis = new FileInputStream(new File("c:/dummy.txt"));
    CheckedInputStream cis = new CheckedInputStream(fis, new CRC32());
    BufferedInputStream in = new BufferedInputStream(cis);
    while (in.read() != -1) {
    result= cis.getChecksum().getValue();
    @>
    In odi variable refreshing mode i selected schema as memory_engine and wrote
    select '<@=result@>' from dual;
    even this wont work for me :(
    Anyone pls help me in this...
    Thanks in advance
    Pavan

    Hi Phani,
    Thanks for the reply. I resolved this. The mistake is I wrote java code in a class,in main function. I removed class and main function. Now I am able to capture value into Odi variable...
    I modified code as
    <@
    import java.io.*;
    import java.util.zip.*;
         long result;
    FileInputStream fis = new FileInputStream(new File("C:/dummy.txt"));
    CheckedInputStream cis = new CheckedInputStream(fis, new CRC32());
    BufferedInputStream in = new BufferedInputStream(cis);
    while (in.read() != -1) {
    result=cis.getChecksum().getValue();
    @>
    finally retrieving result value from dual
    select '<@=result@> from dual
    Edited by: 908443 on Jan 16, 2012 10:42 PM

  • How to use host variable in Java?

    How do I use host variable in java? I am getting SQL code of -404 and description of SQL code is The UPDATE or INSERT statement specifies a String that is too long column-name SQLSTATE=22001. Below is my code:
    * i n s e r t M e s s a g e
    * insertMessage: This method will retrive detail message and other fields for
    * selected item from screen1.
    public final Collection insertMessage(String businessId,String messageNumber,String messageType,
    String messageTitle,String printStyle,String statusIndicator,
    String approverId,String lastUpdateId,String longMessage) {
    MessageTransport msi = new MessageTransport();
    PreparedStatement ps = null;
    Connection connection = null;
    MessageTransport msi1 = new MessageTransport();
    PreparedStatement ps1 = null;
    Connection connection1 = null;
    ArrayList list = new ArrayList();
    try {
    if (businessId != null) {
    businessId = businessId.trim();
    if (messageNumber != null) {
    messageNumber = messageNumber.trim();
    if (messageType != null) {
    messageType = messageType.trim();
    if (messageTitle != null) {
    messageTitle = messageTitle.trim();
    if (printStyle != null) {
    printStyle = printStyle.trim();
    if (statusIndicator != null) {
    statusIndicator = statusIndicator.trim();
    if (approverId != null) {
    approverId = approverId.trim();
    if (lastUpdateId != null) {
    lastUpdateId = lastUpdateId.trim();
    if (longMessage != null) {
    longMessage = longMessage.trim();
    int len = longMessage.length();
    if (len > 254) {
    int constant = 254;
    int k = len % constant; //k will hold value that has number of loops including initial insert.
    k = k - 1; //this is for total number of loop.
    int j = len / constant; //this will have remainder if any to insert rest of longmessage.
    System.out.println("Display remainder: " + k);
    System.out.println("Display divisible: " + j);
    System.out.println("Display Length of longMessage: " + len);
    StringBuffer sql = new StringBuffer();
    sql.append("INSERT INTO " + MESSAGE_TBL + " ( MT_BUS_ID,MT_MSG_NBR,MT_MSG_TYPE,MT_MSG_TITLE,MT_PRINT_STYLE,MT_APV_STATUS,MT_APV_ID,MT_APV_DT,MT_APV_TM,MT_LAST_UPDATE_ID,MT_LAST_UPDATE_DT,MT_LAST_UPDATE_TM,MT_MSG_TXT ) VALUES ");
    sql.append("(");
    sql.append("'");
    sql.append(businessId).append("'");
    sql.append(",").append(messageNumber);
    sql.append(",").append("'I'");
    sql.append(",").append("'").append(messageTitle).append("'");
    sql.append(",").append("'").append(printStyle).append("'");
    sql.append(",").append("'P'");
    sql.append(",").append("' '");
    sql.append(",").append("CURRENT DATE");
    sql.append(",").append("CURRENT TIME");
    sql.append(",").append("'").append(lastUpdateId).append("'");
    sql.append(",").append("CURRENT DATE");
    sql.append(",").append("CURRENT TIME");
    sql.append(",").append("'").append(longMessage).append("'");
    sql.append(")");
    System.out.println("Display SQL Statement: " + sql);
    connection = DriverManager.getConnection(DATABASE_URI, USER, PASS);
    ps = connection.prepareStatement(sql.toString());
    ps.executeUpdate();
    System.out.println("Refreshed Record: ");
    catch (SQLException sqle) {
    System.out.println("SQLException: "+ sqle + ". SQLSTATE=" + sqle.getSQLState()+" SQLCODE=" + sqle.getErrorCode());
    finally {
    if (ps != null) {
    try {
    ps.close();
    ps=null;
    catch (Exception e) {}
    if (ps1 != null) {
    try {
    ps1.close();
    ps1=null;
    catch (Exception e) {}
    if (connection != null) {
    try {
    connection.close();
    connection = null;
    catch (Exception e) {}
    if (connection1 != null) {
    try {
    connection1.close();
    connection1 = null;
    catch (Exception e) {}
    return list;
    if my longMessage is smaller like one line then everything works fine, but as soon as my longMessage if greater than 254 it starts giving me -404. How do I work around or Is there any way to use host variable in Java?
    All kind of help is appreciated. Any question then please email me at [email protected].
    Thank you.

    This is what you got to do to insert a larger value.
    //Assuming that message length is less than 254+ 254 characters.
    //If larger then run the update loop that many times.
    String longMessage = "Blah blah ... ";
    String firstPart = "";
    String secondPart = "";
    int messageLength = longMessage.length();
    if (messageLength > 254)
         try
              firstPart = longMessage.subString(0, 253);
              secondPart = longMessage.subString(254, message);
         catch (IndexOutOfBoundsException e)
    //In the first insert  set the first 254 characters
    ps.setString(1, firstPart);
    int result = ps.executeUpdate();
    if (result != 0)
           System.out.println("Insert  sucessful  ");
           if (messageLength > 254)
                //now update with the second part.
                static String UPDATE_SECOND_PART = UPDATE my.table SET LONG_COL = LONG_COL || ? WHERE KEY_COL = ?;
                ps2 = connection.getPreparedStatement(UPDATE_SECOND_PART);
                ps2.setString(1, secondPart);
                ps2.setString(2, businessId);  //assuming that businessId is the primary key.
                int result2 = ps2.executeUpdate();
                if (result2 != 0)
                      System.out.println("Update  sucessful  ");
                else
                     System.out.println("Update failed ");
    else
           System.out.println("Insert failed ");
    }Hope this helps.

  • Search information using a VO by java code..?

    Search information using a VO by java code.
    Hi to all
    Im trying to retrieve specific   information by java  using the VO object that I have attaché to the EO. I need to know if this is possible and how to.
    For example lest say that I have the following information user name and password and I wand the telephone and other information.
    Can some pls help me with a link of an example of how to do this.
    Tanks to all.

    Hi JulianeE
    Yes it is possbile, please generate the VORowImpl file on the corresponding VO object. Even if your query return multple rows, it can . see the sample code below
    OAViewObject vo1 = (OAViewObject)am.findViewObject("EmployeeEOVO1");
    vo1.reset();
    if (vo1 != null)
    do
    if(!vo1.hasNext())
    break;
    vo1.next();
    EmployeeEOVORowImpl lcerl = (EmployeeEOVORowImpl)vo1.getCurrentRow();
    lcerl.getFullName();
    Thanks
    Sandeep

  • Setting Windows Envirnoment variables within Java code!!

    Hello All,
    How to setup Windows envirnoment variables within Java code dynamically.
    int customer = jList1.getSelectedIndex();
    System.out.println(customer);
    switch (customer)
    case 0:
    System.out.println("HOME1");
    break;
    case 1:
    System.out.println("HOME2");
    break;
    case 2:
    System.out.println("HOME3");
    break;
    case 3:
    System.out.println("HOME4");
    break;
    default:
    System.out.println("HOME5");
    break;
    }

    set windows %HOME% variableWhat is it?
    A system-wide resource? Something pertinent to the processes of a given user? Or does it apply only to your Java process?

  • Is it true that JSP creates Servlet java code?

    I am working with JSP.
    My web server is tomcat.
    Is it true that JSP creates Servlet java code of JSP files when it executes? If so how can I view them?

    Yes..it is true..
    to find out..do this..
    on purpose leave a bug in ur jsp that will generate a compilation error. So in ur browser some exception will be shown.That exception message will have the clue to the java file (e.g
    error in compiling _XYZ.java).You can manually search for this file..
    (If the copilation is successful, then this java file is deleted by the server.)

  • Using Textbox strings in Java code

    Hi,
    I wonder if anyone can help me with a problem I'm
    having with a JSP.
    I've got several text boxes on my JSP which are static and would like to access their contents from within some dynamic Java code contained within the same JSP. I.e If I have a text box whose name is my_text I
    would like to use my_text as a string within my Java code.
    Does anyone know how to do this?
    Thanks,
    Peter

    actually u can user java variable values in a html form/javacript but not vice versa.

  • Problem using jsp:forward in java script

    hi,
    when I use jsp forward tag inside java script i'm getting a problem that
    when the jsp is invoked it is getting forwarded to the page specified in the forward tag, without checking the if conditions. Following code may give you a better idea.
    <html>
    <script>
    function test()
    if(document.f.htemp.value=="true")
    alert("jus");
    else
    var s=document.f.htemp.value;
    alert(s);
    <jsp:forward page="success.jsp" />
    </script>
    <body>
    <form name="f" method=post>
    <input type=text name=htemp value="true">
    <input type=button onclick="test()">
    </form>
    </body>
    </html>
    please help me,thanks inadvance
    regards
    chandu

    What pgeuens means is that you can't mix javascript and jsp/java code in this way.
    ALL of the jsp/java code gets executed at the server end.
    This produces an HTML page (with embedded javascript) which gets sent to the client.
    The client then runs javascript code in response to events (onLoad, onClick, onChange etc etc)
    So in this case, the jsp:forward will always be executed, because as far as the server is concerned, the javascript is just template text.
    If you WANT to do a conditional forwarding on the server side you do it in java ie (horribly using scriptlet)
    <%
    if (testCondition){
    %>
      <jsp:forward>
    %<
    %>Or if you want to test what the client has entered client side, all you can do is submit the form, or navigate to a URL
    <script>
    function test()
    if(document.f.htemp.value=="true")
    alert("jus");
    else
    var s=document.f.htemp.value;
    alert(s);
    document.f1.action="success.jsp";
    document.f.submit();
    </script>You cannot run JSP code based on your javascript code.
    Java. Javascript. Not the same thing.
    Hope this helps,
    evnafets

  • Can I use OLAP variable in ABAP Code of infoobject filter

    I have 0FISCPER infoobject in filter section of info-package while loading data.
    Below OLAP varaibles has below dynamic values that are being calculated at run time.
    0P_PRFP2 -  (Current fiscal period - 2)   ex: 2010010
    0P_PRFP1 -  (Current fiscal period - 1)   ex: 2010011
    0FPER    -    (Current fiscal period )        ex: 2010012
    I want to write ABAP CODE FOR using filter values from 0P_PRFP2 to 0FPER. (Last 3 fiscal periods - ex: 2010010 to 2010012).
    how to  use above standard OLAP variables in ABAP CODE to assign l_t_range (low or  high).

    try this using ABAP routine option (6)
    DATA: curryear(4)           type N,
                 currperiod(2)         type N,
                 prevper1(2)           type N,
                 prevyear1(4)         type N,
                 prevper2(2)           type N,
                 prevyear2(4)         type N,
                 prevfiscperYr1(7)   type N,
                 prevfiscperYr2(7)   type N,
                 prevfiscper1(3)      type N,
                 prevfiscper2(3)      type N,
                 w_length1              type i,
                 w_length2              type i.
      curryear = SY-DATUM+0(4).
      currperiod = SY-DATUM+4(2).
      If currperiod EQ '01'.
        prevyear1 = curryear - 1.
        prevper1   =  '12'.
        prevyear2 = curryear - 1.
        prevper2   = '11'.
      elseif currperiod EQ '02'.
        prevyear1 = curryear.
        prevper1   = '01'.
        prevyear2 = curryear - 1.
        prevper2   = '12'.
      else.
        prevyear1 = curryear.
        prevper1   =   currperiod - 1.
        prevyear2 = curryear.
        prevper2   = currperiod - 2.
      endif.
      w_length1 = STRLEN( prevper1 ).
      If w_length1 = 1.
        concatenate '0' prevper1 into prevper1.
      Endif.
      w_length2 = STRLEN( prevper1 ).
      If w_length2 = 1.
        concatenate '0' prevper2 into prevper2.
      Endif.
      concatenate '0' prevper1 into prevfiscper1.
      concatenate '0' prevper2 into prevfiscper2.
      concatenate prevyear1 prevfiscper1 into prevfiscperYr1.
      concatenate prevyear2 prevfiscper2 into prevfiscperYr2.
      l_t_range-low = prevfiscperYr2.
      l_t_range-high = prevfiscperYr1.
    *  modify l_t_range index l_idx from l_t_range.
    l_t_range-sign   = 'I'.
    l_t_range-option = 'BT'.
    modify l_t_range index l_idx.

  • How to use Oracle objects in java code

    Hi all!
    I'm reading an xls and i need to fill me oracle objects with java code:
    OBJECT_NAME OBJECT_TYPE
    LETTURA_OBJ TYPE
    LETTURA_OBJ TYPE BODY
    In the past weeks i've been using both java code into oracle and oracle objects, but new i need to write those objects with data i read with java, anybody can help me?
    I know that the easiest work around would be to put the data i read from the excel file into a table and then fill the oracle objects, but now i want to learn how to write directly those objects with a command like the following one:
    a sample of the code i'm tryng to write:
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED REPORT."Manage_Excel_ASMBS" AS
    import java.io.*;
    import java.io.IOException;
    import jxl.*;
    public cass ....
    #sql{  variabili_globali.var_ER_F3.Tipo_Lettura := 5}
    thanks,
    Massimo
    Edited by: LinoPisto on 16-mag-2011 16.38

    mmmh i'm not understanding so much....
    well... as i told before i'm working in oracle database environment and i'm developing a java procedure.
    now, i have this object
    CREATE OR REPLACE
    TYPE REPORT.FATTURA_OBJ AS OBJECT (
    POD VARCHAR2(1000),
    ID_FATTURA NUMBER,
    ID_FILE NUMBER,
    COERENZA_EA_F VARCHAR2(1000),
    COERENZA_ER_F VARCHAR2(1000),
    COERENZA_EA_M VARCHAR2(1000),
    COERENZA_EF_M VARCHAR2(1000),
    ANOMALIA VARCHAR2(1000),
    MOTIVO_INVALIDAZIONE VARCHAR2(1000),
    MATRICOLA_CONTATORE VARCHAR2(1000),
    POTENZA_DISPONIBILE VARCHAR2(1000),
    MEMBER PROCEDURE pulisci
    /and i need to work with it inside this procedure:
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED REPORT."Manage_Excel_ASMBS" AS
    import java.io.*;
    import java.io.IOException;
    import java.io.StringWriter;
    public class Manage_Excel_ASMBS
    public static void read_Excel(String inputFile,int var_Id_Caricamento, int var_Id_Distributore, String var_Distributore) throws SQLException, IOException
              **here i need to put what i'm reading inside the excel file into oracle objects**
    /can you please give me a sample ?
    thanks

  • Using getProperty in my Java code.

    I am reading the attached XML file into my Java classes.
    <Config>
    <Properties>
         <entry key="rmi.remotecontrol.port">30</entry>
    </Properties>
    <AListener>
              <Subscriber></Subscriber>
              <Database>
                   <URL>jdbc:oracle:thin:@0.0.0:1521:dev</URL>
              </Database>
    </AListener>
    </Config>
    My Java code displays the correct output when I say:
    System.out.println("The RMI Port name property: " +  prop.getProperty("rmi.remotecontrol.port"));
    Output : 30Now,if I want to get the URL address of the database,and when I use
    System.out.println("The RMI Port name property: " +  prop.getProperty("Database.URL"));
    Output is null.How do I get the value of the URL using getProperty?
    Thanks,

    you're a complete idiot. seriously. three separate threads, days apart, each with the same mistake in, pointed out by me several times each thread, links to exactly the documentation you need, code actually pasted into the thread from the documentation, several patient explainations, and you still haven't bothered actually listening to me
    other posters beware: check this fools posting history for an insight into how they repeatedly ignore advice on this problem before deciding whether it's worth your effort replying - it isn't. this clown simply ignores being told directly what is wrong here, and even ignores being given the exact fix. no point replying
    http://forum.java.sun.com/thread.jspa?threadID=5155898&messageID=9589500#9589500
    http://forum.java.sun.com/thread.jspa?threadID=5153393&messageID=9577681#9577681
    http://forum.java.sun.com/thread.jspa?threadID=5152929&messageID=9575638#9575638
    and still you don't get it. give up programming, you're not cut out for it. it involves an attention span and the ability to listen to advice

  • I want to use £ in euro in java code

    Hi,
    I want to use &pound; as euro symbol in java code please help me as soon as possible.

    It's not 100% clear what you are asking:
    I want to use &pound; as euro symbol in java codeDo you mean you want to display a Euro symbol? If so, you use &euro; (if your font supports it) but I suspect that is too easy you must mean something else. Can you ask the question again but rephrase to make it clearer what you want to do. Do you want to use the symbol in a particular Java component?

  • 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 %>"/>

  • How to: Transform Activity: Read global/local variable, execute java code

    Could anyone please show me how to do that???

    could you please elaborate your usecase? yes you can read global variable using getVariableData( ) xpath function and pass them as an argument to the processXSLT ( ) xpath function.
    You can read the global or local variables inside java exec using, please refer samples/references/javaexec sample.

Maybe you are looking for

  • Moving iTunes files from PC to Mac

    I have most of my iTunes files on my iMac and want to copy them into iTunes on my PC. I thought about moving them from the iMac onto a thumb drive and them importing them into iTunes on the PC, but don't know if the thumb drive can be used on both Ma

  • Preview and safari do not display images in a pdf, where as chrome will. How do I fix this?

    I'm on the newest OS X Yosemite and I have an issue with viewing pdfs in both preview and safari. The figures show up fine from Chrome. This also leads to the issue of when I try to print off the pdf. The images do not appear in the printed version.

  • I have an older 30 gb classic ipod.Can the 3.5mm"jack" be replaced inside?

    I have an older 30gb classic ipod. Can the "jack" sleeve inside be replaced or fixed? the prong connection inside has broke off and you need to push the jack to one side to get both sides of the earbuds to work. Thanks

  • Re: SHOCKINGLY bad service

    There really should be a get out clause that extends past 10 ten days, by the time you realise BT are getting it wrong your locked in. We signed up for Broadband, Vision, infinity, extra channels, the whole works. Subcontractors for Openreach called

  • Renaming Imported Files

    I recently had a number of old transparencies scanned at a local service bureau and delivered as jpegs on disc. The images import just fine into Lightroom from the disc, but when I try to rename them, I get a dialogue box telling me I can't rename th