How to apply JSP expression %= var % in Java String

I have an unique problem. I am just trying to describe it with a simple example as follow:
A servlet passes the following string to a JSP page:
String sFromServlet = "hello my name is <%= strName %>";
The JSP code has the definition of the variable strName as:
String strName = "John Smith";
Now, in the JSP code, we want to replace strName in the variable sFromServlet so that it looks like the following:
"hello my name is John Smith".
I know this can be done with string pattern search and replacement. But did anyone know any smarter way to do it?
Thanks,
SQ

Do you mean
<%
String strName = "John Smith";
String sFromServlet = "hello my name is "+strName";
%>

Similar Messages

  • How to write regular expression to find desired string piece *duplicate*

    Hi All,
    Suppose that i have following string piece:
    name:ali#lastname:kemal#name:mehmet#lastname:cemalI need
    ali
    mehmetI use following statement
    SQL> select lst, regexp_replace(lst,'(name:)(.*)(lastname)(.*)','\2',1,1) nm from (
      2    select 'name:ali#lastname:kemal#name:mehmet#lastname:cemal' as lst from dual
      3  );
    LST                                                NM
    name:ali#lastname:kemal#name:mehmet#lastname:cemal ali#lastname:kemal#name:mehmet#
    SQL> But it does not return names correctly. When i change 5th parameter(occurence) of regexp_replace built-in function(e.g. 1,2), i may get ali and mehmet respectiveley.
    Any ideas about regexp?
    Note : I can use PL/SQL instr/substr for this manner; but i do not want to use them. I need regexp.
    Regards...
    Mennan
    Edited by: mennan on Jul 4, 2010 9:53 PM
    thread was posted twice due to chrome refresfment. Please ignore the thread and reply to How to write regular expression to find desired string piece

    The approach is to do cartesian join to a 'number' table returning number of records equal to number of names in the string.I have hardcoded 2 but you can use regexp_count to get the number of occurrences of the pattern in the string and then use level <=regexp_count(..... .
    See below for the approach
    with cte as(
    select
    'name:ali#lastname:kemal#name:mehmet#lastname:cemal' col ,level lev
    from dual connect by level <=2)
    select substr(regexp_substr('#'||col,'#name:\w+',1,lev),7)
    from cte
    /

  • How to open JSP session from a java application or an applet?

    Hi,
    My problem is a bit challenging (at least for me) and its not about JSP but it is about a web application..
    I couldnt find a better place to post this question I am sorry if this is not the right place to post it..
    I need to enable users log into my website by checking username and password and reading and checking the data from a usb device located in client computer.
    I can read from the device thorough JNI using the third party DLL file for the device... I have no problem with that..
    Since I need to make native calls I am planning to develop a java application so I let the users open the application using web start.. Once my application is running on client side after reading the device and getting login password information (assuming login information correct), How can I open a web session for the that spesific user and a web browser and let the user browse the web site on his/her own session?
    I would appreciate any guidance..
    Thanks..

    add the values in the header using...
    response.addHeader("userNmae","XXXX");use it in all ur pages like say..
    if(!request.getHeader("userName")!=null && request.getParameter("userName").equlas(""))
    String username=request.getParameter("userName");
    }

  • How to run jsp pages  from webdynpro java

    Hi experts
         I want to run the jsp pages present in a webserver like tomcat or weblogic servers from webdynpro.Is there any way to run a jsp from webdynpro environment?
    Thanks and regards
    venkat kalyan

    hi Venkat,
    Check out this threads. They might be helpful
    Re: web dynpro jsp
    Re: Opening a jsp from another server(Weblogic) from webdynpro running on WAS
    Regards,
    Gopi

  • How to write regular expression to find desired string piece

    Hi All,
    Suppose that i have following string piece:
    name:ali#lastname:kemal#name:mehmet#lastname:cemalI need
    ali
    mehmetI use following statement
    SQL> select lst, regexp_replace(lst,'(name:)(.*)(lastname)(.*)','\2',1,1) nm from (
      2    select 'name:ali#lastname:kemal#name:mehmet#lastname:cemal' as lst from dual
      3  );
    LST                                                NM
    name:ali#lastname:kemal#name:mehmet#lastname:cemal ali#lastname:kemal#name:mehmet#
    SQL> But it does not return names correctly. When i change 5th parameter(occurence) of regexp_replace built-in function(e.g. 1,2), i may get ali and mehmet respectiveley.
    Any ideas about regexp?
    Note : I can use PL/SQL instr/substr for this manner; but i do not want to use them. I need regexp.
    Regards...
    Mennan

    Hi, Mennan,
    You can nest REGEXP_SUBSTR withing REGEXP_REPLACE to get the n-th occurrence, like this:
    SELECT     lst
    ,      REGEXP_REPLACE ( REGEXP_SUBSTR ( lst
                                      , 'name:[^#]*#lastname'
                               , 1
                               , n
                     , 'name:(.*)#lastname'
                     , '\1'
                     )      AS nm If the pattern occurs fewer than n times, the expression above returns NULL.

  • How to execute logical expression in JEP?

    Hi guys,
    I have a logical expression like,
    (5>3) AND (6>8) OR (7==7)
    Now how execute the above expression using JEP(JAVA Expression Parser)?
    can anyone help me?
    --Subbu                                                                                                                                                                                                                                                                                                                                                           

    Please go through the documentation for JEP
    http://www.singularsys.com/jep/doc/html/usage.html#gettingstarted

  • Passing Var to Java from PL/SQL

    I am trying to pass a PL/SQL varchar2 var to Java String. Java is not responding..
    sendmail(v_sub,v_msg,'[email protected]','[email protected]');
    it does accept ('ddd','ddd','[email protected]','[email protected]');
    Any ideas on how to make it work so I can use PL/SQL variable.
    Thanks much!

    Try with the following example.
    This ia taken from the Oracle8i manual.
    import java.sql.*;
    import java.io.*;
    import oracle.jdbc.driver.*;
    public class GenericDrop {
    public static void dropIt (String object_type, String object_name)
    throws SQLException {
    // Connect to Oracle using JDBC driver
    Connection conn =
    DriverManager.getConnection("jdbc:default:connection:");
    // Build SQL statement
    String sql = "DROP " + object_type + " " + object_name;
    try {
    Statement stmt = conn.createStatement();
    stmt.executeUpdate(sql);
    stmt.close();
    } catch (SQLException e) {System.err.println(e.getMessage());}
    CREATE OR REPLACE PROCEDURE drop_it (
    obj_type VARCHAR2,
    obj_name VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'GenericDrop.dropIt(java.lang.String, java.lang.String)';
    Create table ee1(a number);
    declare
    i1 varchar2(20);
    i2 varchar2(20);
    begin
    i1:='TABLE';
    i2:='EE1';
    dropit(i1,i2);
    end;
    There is no problem in executing the above procedure.
    What is the exact error message you are getting?

  • How to pass value from the jsp file to a java bean

    I have huge promblem .I want to pass value of combo box to bean file to set my database contecting.The is how i call function to pass database to the bean file
    <%db.setDatabase(database);%>are coding to set my databse connection
    private String database;
        public Conn(){
         try{
                   Class.forName("org.gjt.mm.mysql.Driver");
                   DriverManager.registerDriver((Driver) Class.forName("org.gjt.mm.mysql.Driver").newInstance());
                   String data=getDatabase();
                   String url = "jdbc:mysql://localhost/"+data;
                   Connection conn = DriverManager.getConnection(url);
                   setConnection(conn);
              catch(SQLException e){
                   System.out.println(e.toString());
              catch(Exception e){
                   System.out.println(e.toString());
         public void setDatabase(String Database){
          this.database = Database;
         public String getDatabase(){
         return this.database;
         }     and Below are error produce
    Note: sun.tools.javac.Main has been deprecated.
    /mrs/system_menu.jsp:18: Method setDatabase(java.lang.String) not found
    in class bgoc.dbConn.Conn.
    db.setDatabase(database);
    ^
    1 error, 1 warning
    please help me soon. any that come to your will help
    thank you

    I have huge promblem .I want to pass value of combo box to bean file to set my database contecting.The is how i call function to pass database to the bean file
    <%db.setDatabase(database);%>are coding to set my databse connection
    private String database;
        public Conn(){
         try{
                   Class.forName("org.gjt.mm.mysql.Driver");
                   DriverManager.registerDriver((Driver) Class.forName("org.gjt.mm.mysql.Driver").newInstance());
                   String data=getDatabase();
                   String url = "jdbc:mysql://localhost/"+data;
                   Connection conn = DriverManager.getConnection(url);
                   setConnection(conn);
              catch(SQLException e){
                   System.out.println(e.toString());
              catch(Exception e){
                   System.out.println(e.toString());
         public void setDatabase(String Database){
          this.database = Database;
         public String getDatabase(){
         return this.database;
         }     and Below are error produce
    Note: sun.tools.javac.Main has been deprecated.
    /mrs/system_menu.jsp:18: Method setDatabase(java.lang.String) not found
    in class bgoc.dbConn.Conn.
    db.setDatabase(database);
    ^
    1 error, 1 warning
    please help me soon. any that come to your will help
    thank you

  • How to apply java support packages.

    hi all,
    i applied support packages for 4.7EE but i dont know how to apply java support packages.
    can anyone explain about how to apply  java support package for netweaver s??
    from scratch anyone can explain.
    regards
    vijay

    Hello Vijay ,
    Java Support packs can be installed without using SDM also if you are on NW2004.
    Process:
    Eg SP18
    Download the following DVDs
    1. WebAS 6.40 SP18(Part 1/4): SAP Installer
    2. WebAS 6.40 SP18(Part 2/4): SAPInst Control File for Oracl
    3. WebAS 6.40 SP18(Part 3/4): OS Depend. parts of Java RuntiA
    4. WebAS 6.40 SP18(Part 4/4): OS Indep. Parts of Java Runtime
    Uncar each of them in the sequence
    1,4,3,2
    Once u uncr then u will get some more uncarred files
    eg D:\sapinst\J2EE-RUNT-CD\SCS\NT\I386\SCS.SAR uncar it into run directory : DIR_CT_RUN ( D:\usr\sap\SRX\SYS\exe\runU)
    Note: The value of DIR_CT_RUN can be found In Profile SRX_SCS01_B3BPH1W)
    Run SAPINST
    Note:Give RFC user as 000 DDIC
    Java Support packs can be installed using JSPM  if you are on NW2004s
    1)Download SP Stack or SP
    2)Copy the SCA files to /usr/sap/trans/EPS/in
    3)Execute the JSPM go.bat from \sapmnt\SID\DVEBMGSXX\j2ee\JSPM
    4) Provide SDM Password
    5 ) Select the Traget SP level .
    6 ) Deploy.
    Also, you can find the current SP Level in http://localhost:5<instance numeber>00 and then system information.
    Regards ,
    Santosh Karadkar <a href="https://forums.sdn.sap.com/click.jspa?searchID=-1&messageID=3819594">Click here for further info</a>

  • How to execute a jsp instruction from a java class?

    How to execute a jsp instruction from a java class?
    Any help please.
    Thank's

    I'll detail my problem:
    Supposing that I have a jsp file called: start.jsp
    In the start.jsp I instanciated an object called global from the class Global ( for example ).
    Then, I called a custom taglib:
    <ix:mytag/>
    In the suitable tld file: the mytag is defined:
    <tag>
    <tag class>Tag1<.....
    The java file Tag1 has method:
    doStartTag(){
    // here is the problem
    global.doSomeFunctions();
    Okay, the problem is that the object gobal is not defined in the class Tag1. what to do?
    I think that I have to pass the object global as a parameter to the class Tag1. How to do that?
    Actually, the problem was to insert the follwoing in the doStartTag method:
    doStartTag(){
    pageContext.getOut().print("<%= hello world %>");
    The output is <%= hello world %> not hello world.
    Okay, the new problem is how to pass an object as a parameter to a class called from a tld file.
    Any help please.
    Thank's too much

  • How to call the method from the java bean and pass it to JSP textbox

    i'm quite new to java thats why i'm asking how to call a method in the java bean file and pass it to the JSP textbox. My projects are communicating JSP with C#. i had successfully created a C# client bean file for JSP. The whole process is to type something on the server(C# programming) and it would appear in the textbox.

    your question doesn't provide much informartion. provide some other information and coding so that we could tell exactly what you are looking for?

  • How to apply sap license for Sap Netweaver AS Java

    Hello guys,
    May i know how to apply sap license for SAP Netweaver AS Java?  Appreciate the reply, thank you
    regards,
    wei how

    Hi Lee,
    check below link:
    http://help.sap.com/saphelp_nwce10/helpdata/en/9f/5e533e5ff4d064e10000000a114084/content.htm
    Thanks
    sunny

  • How to apply ajax / XMLHttpRequest in jsp

    Hi,
    I would like to know how to apply the above in my jsp page. I did not use xml tag
    for example:
    I have 3 fields in the form. after user chosen the selected value from the listbox of the first field, the program will have to retrieve the data from the database based on the value user selected on the first field and display on the 2nd listbox and so on.
    I cannot ask user to submit each time he has chosen the value, therefore I guess ajax can perform this.
    pls help and provide me the example on how to do the above.
    TQ

    In a JSP use AjaxTags.
    Ajax may also be implemented ina JavaScript/HTML page.
    http://www.regdeveloper.co.uk/2006/06/09/ajax_web_tutorial/
    http://www.regdeveloper.co.uk/2006/06/20/ajax_web_tutorial_part2/

  • How to apply a Character Style that's already been made in a template document?

    First of all I'd like to thank everyone that helps. I'm a complete beginner at scripting and appreciate all your help.
    I'm basically using GREP expressions to find patterns in a document and apply a Character Style which has already been made. This Character style was not made using script, but just in InDesign when making and setting up the template.
    var myDoc = app.activeDocument;
    //Clear the find/change grep preferences.
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
    //Set the find options.
    app.findChangeGrepOptions.includeFootnotes = false;
    app.findChangeGrepOptions.includeHiddenLayers = false;
    app.findChangeGrepOptions.includeLockedLayersForFind = false;
    app.findChangeGrepOptions.includeLockedStoriesForFind = false;
    app.findChangeGrepOptions.includeMasterPages = false;
    //GREP Expression for finding all HEADERS
    app.findGrepPreferences.findWhat = ".+\n";
    //Applying formatting changes to put into All Caps, Bold and changing the font size to 12 pt.
    app.changeGrepPreferences.capitalization = Capitalization.allCaps;
    app.changeGrepPreferences.fontStyle = "Bold";
    app.changeGrepPreferences.pointSize = "12";
    myDoc.changeGrep();
    //Clear the find/change preferences after the search.
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
    This is how I currently have it. I will manually define the changes to the text. The problem is, each template uses a different set of fonts and not all of them use Bold e.g. Sabon can use CE Bold.
    I would like to learn how to apply a Character Style and have tried looking around but nothing seems to work.
    Any help would be much appreciated.
    Thanks.

    select the text where u went  and run below  script after change group as per ur template.
    var myDoc = app.activeDocument;
    var mySel = app.selection[0];
    //Clear the find/change grep preferences.
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
    //Set the find options.
    app.findChangeGrepOptions.includeFootnotes = false;
    app.findChangeGrepOptions.includeHiddenLayers = false;
    app.findChangeGrepOptions.includeLockedLayersForFind = false;
    app.findChangeGrepOptions.includeLockedStoriesForFind = false;
    app.findChangeGrepOptions.includeMasterPages = false;
    //GREP Expression for finding all HEADERS
    app.findGrepPreferences.findWhat = "role";
    //Applying formatting changes to put into All Caps, Bold and changing the font size to 12 pt.
    //app.changeGrepPreferences.capitalization = Capitalization.allCaps;
    //~ app.changeGrepPreferences.fontStyle = "Bold";
    //~ app.changeGrepPreferences.pointSize = "12";
    app.changeGrepPreferences.appliedCharacterStyle=myDoc.characterStyleGroups.item("Style Group 1").characterStyleGroups.item("Style Group 2").characterStyles.item("Header")// Header is name of character name
    mySel.changeGrep();
    //Clear the find/change preferences after the search.
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
    If it's help then click yes
    Mi_D

  • How to write JSP that returns current time(AJAX)

    how to make jsp returns current system time in response
    i am using the following code
    test.jsp
    <%@page pageEncoding="UTF-8" import="java.util.Date" import="java.util.*" import="java.lang.*"%>
    <%
    out = response.getWriter();
    out.println(System.currentTimeMillis());
    %>where as i am following an .ASP file working well with code
    test.asp
    <%
    response.expires=-1
    response.write(time)
    %>

    Chkeck this out
    Ajax_Time.htm
    <html>
    <body>
    <script type="text/javascript">
    function ajaxFunction()
    var xmlHttp;
    try
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    catch (e)
    // Internet Explorer
    try
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    catch (e)
    try
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    catch (e)
    alert("Your browser does not support AJAX!");
    return false;
    xmlHttp.onreadystatechange=function()
    if(xmlHttp.readyState==4)
    document.myForm.time.value=xmlHttp.responseText;
    xmlHttp.open("GET","time.jsp",true);
    xmlHttp.send(null);
    </script>
    <form name="myForm">
    Name: <input type="text"
    onkeyup="ajaxFunction();" name="username" />
    Time: <input type="text" name="time" />
    </form>
    </body>
    </html>
    time.jsp
    <%@ page import="java.text.*,java.util.*" session="false"%>
    <%!
    DateFormat fmt = new SimpleDateFormat("hh:mm:ss aa");
    String now = fmt.format(new Date());
    %>
    The time is <%= now %>

Maybe you are looking for