How to write a function in JSP

I have a few lines of code I would like to store in an external file and then call it from a web page.
Here is the code
     String isCE = "No";
     String ismobile = "No";
     String accept = request.getHeader("accept");
     String user_agent = request.getHeader("user-agent");
     String accept_charset = request.getHeader("accept-charset");
     String accept_language = request.getHeader("accept-language");
     String profile = request.getHeader("profile");
     String x_wap_profile = request.getHeader("x-wap-profile");
     if (user_agent.contains("CE")) {
          isCE = "Yes";
     if (x_wap_profile == null && isCE == "No") {
          response.setStatus(301);
          response.sendRedirect("someurl.com");
          response.setHeader( "Connection", "close" );
Now I would like to include this code and then call it with a single function and then pass the url like:
snif("www.someurl.com");
Please help

Thai,
You can use the "channel" functions for this. I'm far from an expert on channel programming but I've read files line-by-line successfully by going one character at a time, looking for a carriage return.
You can open up the file channel with something like:
  ChannelT chan;
  FilePathT *path;
  UCharT ptr[1];
  IntT numRead;
  path = F_PathNameToFilePath("C:\\temp\\mydoc.txt", NULL, FDefaultPath);
  if((chan = F_ChannelOpen(path,"r")) == NULL)
      return;
  //read the first character
  numRead = F_ChannelRead(ptr, sizeof(UCharT), 1, chan);
...then you can call F_ChannelRead iteratively to build the string in a buffer, looking for a carriage return (ASCII 13) and stopping there. (that is, ptr[0] == 13).
There might be a better way. This is just the way I've gotten it to work. It probably is not a good method for unicode files.
Russ

Similar Messages

  • How to write printing function using JSP?

    dear all,
    i want to add a printing function in my project but i do not know how to do it? could anyone teach me how to do it?
    thanks
    eric

    salut eric,
    you can do it this way :
    1 - create a html link in your code to this javascript
    function : (I am using Struts, but you can write it in
    pure html
    <html:link href="#bodyStart"
    onclick="openWindowForPrinting()"
    titleKey="msg.status.print">      <bean:message
    key='app.print' />
    <script language="JavaScript">
    <!--
    window.open = SymRealWinOpen;
    //-->
    </script>
    </html:link>
    >
    >
    2 - here is the javascript function : it open a window
    with the "print.jsp" page.
    function openWindowForPrinting(){
    window.open('/your_project/pages/common/print.jsp','',
    'left=150, top=150 , status=no, directories=no,
    toolbar=no, menubar=yes, location=no, scrollbars=yes,
    resizable=yes, dependant=yes');
    3 : here is the print.jsp page : You have only to
    create a session variable called
    "currentBodyRelativeLocation", which content the
    relative URL to the page you want to print (for
    example, the boby of the current page).
    <%@ taglib uri='/WEB-INF/tlds/perso.tld'
    prefix='perso' %>
    <html>
    <head>
    <perso:csslink page='${cssRelativeLocation}' />
    </head>
    <body onload="var SymTmpWinOpen = window.open; window.open = SymWinOpen; printPage();; window.open = SymTmpWinOpen;">
    <body>
    <jsp:include page="${currentBodyRelativeLocation}"/>
    </body>
    <script language="JavaScript">
    <!--
    window.open = SymRealWinOpen;
    //-->
    </script>
    </html>
    <script language='javascript'>
    function printPage(){
    window.print();
    window.close();
    </script>
    hai,
    i'm not very understand how is your code work. when i write html code, do i need to mind about this code: "msg.status.print" ? what is this code mean?
    i have too much question on this thing. would you mind to be further explain to me? or is it any reference for me to refer? i'm really new to write printing function on JSP.
    i never write this function before. i'm feel so lost.....:(
    thanks again
    eric

  • How to realize print function in JSP

    How to realize print function in JSP? I know use Javascript:window.print() can print,but it will print whole page,it don't fit me;Another method is to write JSP into Excel and then print it in Excel,but it don't fit me too,because it don't print directly. Anybody know how to print it directly?

    Many websites offer a "printer friendly" version of a certain page. That IMO is the only way to solve your problem, next to using CSS to use a different style for printer output. Here is a tutorial that covers this:
    http://www.alistapart.com/stories/goingtoprint/

  • How to write a function block?

    Hi There,
    Does anybody know how to write a function block with LabVIEW?  Something like those in Real-Time VIs>>Function Blocks>>.
    Thank you very much in advance?
    Solved!
    Go to Solution.

    I don't want to overwelm you but there is tons of free training material online.  One of these is the one already mentioned.
    NI Learning Center
    NI Getting Started
    -Hardware Basics
    -LabVEW Basics
    -DAQ Application Tutorials
    3 Hour LabVIEW Introduction
    6 Hour LabVIEW Introduction
    Self Paced training for students
    Self Paced training beginner to advanced, SSP Required
    LabVIEW Wiki on Training
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • How to write a function generator

    How to write a function generator from labview and using PCI-MIO-16

    Hallo, [email protected],
    Du (x) meintest am 27.07.01 zum Thema How to write a function generator:
    > How to write a function generator from labview and using PCI-MIO-16
    Look to the examples - there are many VIs with that function.
    Viele Gruesse!
    Helmut

  • How to write Boolean function (If Then Else)?

    Hi all,
    I have a logic to write in the query. It is:
    If (A = 0 and B = 0)
    Then 0
    Else
            If (A = 0 and B > 0)
            Then 100
            Else
                   A/B  (we want to show %)
    How to use boolean function to write this Netted If Else statement? Thank you in advance!

    Hi
    If (A = 0 and B = 0)
    Then 0
    Else
    If (A = 0 and B > 0)
    Then 100
    Else
    A/B (we want to show %)
    1. create a formula in the query designer. and use this formula for if - else
    ( ( (A==0) AND (B==0) ) * 0) +  ( ( a==0 ) AND (B >0 ) * 100 + (A/B*100) )
    : denotes THEN
    + : denotes ELSE
    See if this works.
    Assign points if helpfull
    From
    ManesH

  • How to write a function read line from a file in FDK?

    Hello,
    I want to write a function that can read a file in line by line in FDK. How do I write it. If FDK could not. Is there any the way? Please help.
    Thank you,
    Thai Nguyen

    Thai,
    You can use the "channel" functions for this. I'm far from an expert on channel programming but I've read files line-by-line successfully by going one character at a time, looking for a carriage return.
    You can open up the file channel with something like:
      ChannelT chan;
      FilePathT *path;
      UCharT ptr[1];
      IntT numRead;
      path = F_PathNameToFilePath("C:\\temp\\mydoc.txt", NULL, FDefaultPath);
      if((chan = F_ChannelOpen(path,"r")) == NULL)
          return;
      //read the first character
      numRead = F_ChannelRead(ptr, sizeof(UCharT), 1, chan);
    ...then you can call F_ChannelRead iteratively to build the string in a buffer, looking for a carriage return (ASCII 13) and stopping there. (that is, ptr[0] == 13).
    There might be a better way. This is just the way I've gotten it to work. It probably is not a good method for unicode files.
    Russ

  • How to write a function module?

    How can i write a function module that does the same thing as BAPI_FLIGHT_GETLIST in the SAP system?

    Hi
    Hope it will help you.
    Reward if help.
    Function Modules;
    Check this matter.
    Function Modules are Global ABAP programs created by SAP for reusable purpose.they have IMPORT,EXPORT and TABLE parameters, and EXCEPTIONS to through when error occurs.
    You can create them from TCode SE37.
    Go through the following doc:
    Function modules are cross-program, reusable procedures that are organized into function groups, and whose functions are implemented between the statements FUNCTION and ENDFUNCTION. Function modules and their interfaces are created in the Function Builder.
    Function Module Interfaces
    The parameter interface of a function module is defined in the Function Builder. It includes the definition of interface parameters and the specification of exceptions that can be triggered by a function module. The Function Builder automatically generates comment lines below the FUNCTION statement in the source code of the function module, which represent the interface of the function module with the following syntax:
    Syntax
    ... [IMPORTING parameters]
    [EXPORTING parameters]
    [CHANGING parameters]
    [TABLES table_parameters]
    [{RAISING|EXCEPTIONS} exc1 exc2 ...]
    The syntax and semantics of IMPORTING, EXPORTING, CHANGING, RAISING, and EXCEPTIONS mainly correspond to the definition of method interfaces with [CLASS-]METHODS. The additional option of defining table parameters using TABLES is obsolete.
    Interface parameters
    The interface parameters are defined on the relevant tab pages in the Function Builder.
    IMPORTING parameters are input parameters. When the function module is called, a suitable actual parameter must be specified for every non-optional input parameter. The content of the actual parameter is passed to the input parameter when the call is made. The content of an input parameter for which 'pass by reference' is defined cannot be changed in the function module.
    EXPORTING parameters are output parameters. When the function module is called, a suitable actual parameter can be specified for every output parameter. The content of an output parameter that is defined for 'pass by value' is transferred to the actual parameter if the function module is completed without errors. An output parameter that is defined for pass by reference is not initialized when the function module is called.
    CHANGING parameters are input and output parameters. When the function module is called, a suitable actual parameter must be specified for every non-optional input or output parameter. When the function module is called, the content of the actual parameter is passed to the input/output parameter, and when the function module is completed, the content of the input/output parameter is passed to the actual parameter.
    TABLES parameters are table parameters. Table parameters are obsolete CHANGING parameters that are typed as standard tables with a header line. If an internal table without a header line or a table body is passed as an actual parameter to a formal parameter of this type, an empty local header line is generated in the function module. If an internal table with a header line is used as an actual parameter, both the table body and the header line are passed to the function module. Pass by value is not possible in formal parameters defined using TABLES. Formal parameters defined with TABLES can be replaced by formal parameters defined with CHANGING. A local work area can be created for the internal table in the function module by using the addition LIKE LINE OF itab of the DATA statement.
    Exceptions
    The exception of a function module are defined on the Exceptions tab page in the Function Builder. Here you can select exception classes to define whether class-based exceptions are declared or non-class-based exception are defined. Class-based exceptions are represented in the above syntax by RAISING, and non-class-based exceptions are represented by EXCEPTIONS.
    The addition RAISING is used to declare class-based exceptions that can be propagated from the function module to the caller. Exceptions in the categories CX_STATIC_CHECK and CX_DYNAMIC_CHECK must be explicitly declared, otherwise a propagation can lead to an interface violation. A violation of the interface leads to the treatable exception CX_SY_NO_HANDLER. Exceptions of the category CX_NO_CHECK are implicitly always declared. The declaration of exceptions of the category CX_STATIC_CHECK is statically checked in the syntax check. For exceptions of the category CX_DYNAMIC_CHECK, the check is not performed until runtime. In a function module in which class-based exceptions are declared with the RAISING addition, the statement CATCH SYSTEM-EXCEPTIONS cannot be used. Instead, the relevant treatable exceptions should be handled in a TRY control structure.
    The addition EXCEPTIONS is used to define a list of non-class-based exceptions that can be triggered in the function module using the statements RAISE or MESSAGE RAISING. Exceptions defined in this way - as with formal parameters - are bound to the function module and cannot be propagated. If an exception of this type is triggered in a function module, and no return value has been assigned to it with the homonymous addition EXCEPTIONS of the CALL FUNCTION statement when the call was made, this leads to a runtime error.
    Note
    For new developments after release 6.10, SAP recommends that you work with class-based exceptions that are independent of the function module.
    RFC is a technology which is used to access a functions (Modules) from
    the remote systems.
    If a function module is set as remote enabled which can be access from
    the remote system via RFC.Eg: U can access the Remote enabled function modules in ur VB,Webdynpro,Java,Visual composer program.
    A function module can be set as remote enabled by SE37->Go to ur FM->click the option Button "remote enabled".
    But Normal function modules can not accessd from the remote system.
    Good Example for RFC enabled function module is : BAPI(Business Application Programming Interface)
    Note: All BAPIs are Remote enabled but not all remote enabled function modules are BAPI.
    CALLING A FUNCTION MODULE:
    1)In U ABAP Editor --> Click "Patter" ---> Selection Option Button "Call Function"
    --> Write the Corresponding FM name --> Hit Enter
    2)The appropriate import ,export Parameters will be displayed in ur editor
    3)Pass the Values Here.
    Also check these links.
    http://www.geocities.com/victorav15/sapr3/abapfun.html
    Check this link:
    http://help.sap.com/saphelp_erp2004/helpdata/en/9f/db988735c111d1829f0000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/ef/d94b78ebf811d295b100a0c94260a5/frameset.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/43/41341147041806e10000000a1553f6/frameset.htm
    Check this link:
    http://help.sap.com/saphelp_erp2004/helpdata/en/9f/db988735c111d1829f0000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/ef/d94b78ebf811d295b100a0c94260a5/frameset.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/43/41341147041806e10000000a1553f6/frameset.htm
    See the following links:
    http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/26/64f623fa8911d386e70000e82011b8/content.htm

  • Please help; how to write XML document with JSP?

    I try to write XML document with JSP...
    But I got wrong results everytime.
    The result is not XML file displayed in the browser,
    but HTML file.
    I even tried to use HTML special code for <, >, "
    but still display as HTML file not XML file.
    How to do this?
    Thanks in advance. I put my codes below.
    Sincerely,
    Ted.
    ================
    Here is code for the JSP (called stk.jsp):
    <%@ page contentType="text/xml" %>
    <%@ page import="bean.Stock" %>
    <jsp:useBean id="portfolio" class="bean.Portfolio" />
    <% java.util.Iterator pfolio = portfolio.getPortfolio();
    Stock stock = null; %>
    <?xml version="1.0" encoding="UTF-8"?>
    <portfolio>
    <% while (pfolio.hasNext())
    stock = (Stock) pfolio.next(); %>
    <stock>
    <symbol>
    <%=stock.getSymbol() %>
    </symbol>
    <name><%=stock.getName() %> </name>
    <price><%=stock.getPrice() %> </price>
    </stock>
    <% } %>
    </portfolio>
    =================
    Here is the code for bean.Stock:
    package bean;
    public class Stock implements java.io.Serializable
    String symbol, name;
    float price;
    public Stock(String symbol, String name, float price)
    this.symbol = symbol;
    this.name = name;
    this.price = price;
    public String getSymbol()
    return symbol;
    public String getName()
    return name;
    public float getPrice()
    return price;
    ===============
    And here is bean.Portfolio:
    package bean;
    import java.util.Iterator;
    import java.util.Vector;
    public class Portfolio implements java.io.Serializable
    private Vector portfolio = new Vector();
    public Portfolio()
    portfolio.addElement(new Stock("SUNW", "Sun Microsystem", 34.5f));
    portfolio.addElement(new Stock("HWP", "Hewlett Packard", 15.15f));
    portfolio.addElement(new Stock("AMCC", "Applied Micro Circuit Corp.", 101.35f));
    public Iterator getPortfolio()
    return portfolio.iterator();
    }

    Hi
    I'm not sure whta your query is but I tested your code as it is has been pasted and it seems to work fine. There is an XML output that I'm getting.
    Keep me posted.
    Good Luck!
    Eshwar Rao
    Developer Technical Support
    Sun microsystems
    http://www.sun.com/developers/support

  • How to create download function in JSP?

    Can I know how to make a download function in JSP? Any sample?. Thank You very much!

    http://forum.java.sun.com/thread.jspa?threadID=5312541&tstart=0
    Sorry but whining about it in duplicate threads doesn't help.
    HELP DENIED!

  • How to write exit functions

    Hi
    i have to write exit functions in bps.can any body tell me how these are to be written.please explain the structure and flow of exit functions.please explain me in detail if posiible give me some links for exit functions.
    thanks and regards,
    sekhar reddy

    Hi Sekhar,
    Go through the below links
    Re: user exit
    https://websmp104.sap-ag.de/~sapidb/011000358700005475091999
    https://websmp104.sap-ag.de/~sapidb/011000358700005475101999
    Hope it helps
    Regards

  • How to write a function

    Is there a way to write a function
    function f(c sys_refcursor) return number;
    which is called from sql (for example like this)
    select f( cursor(...) ) from dual
    and returns the number of columns specified in the cursor expression;
    One suggestion could be to use the dbms_sql package, but it is impossible to invoke the dbms_sql.to_cursor_number function as it wants IN OUT parameter, and SQL doesn't allow in out parameters. so what to do.
    thanks in advance

    DimaK wrote:
    Is there a way to write a function
    function f(c sys_refcursor) return number;
    which is called from sql (for example like this)Yes. If this is truly needed - yes, you can create a cursor handle in SQL and pass that to a PL function to process. Example:
    SQL> create or replace function FunkyFoo( c sys_refcursor ) return varchar2 is
      2          type TStrings is table of varchar2(4000);
      3          buffer          TStrings;
      4          csvLine         varchar2(4000);
      5  begin
      6          fetch c bulk collect into buffer limit 10;
      7          close c;
      8
      9          for i in 1..buffer.Count
    10          loop
    11                  csvLine := csvLine || buffer(i);
    12                  if i != buffer.Count then
    13                          csvLine := csvLine || ',';
    14                  end if;
    15          end loop;
    16
    17          return( csvLine );
    18  end;
    19  /
    Function created.
    SQL> show errors
    No errors.
    SQL>
    SQL> col LINE format a50
    SQL> select
      2          FunkyFoo( cursor(select object_name from user_objects order by 1) ) as LINE
      3  from dual
      4  /
    LINE
    FUNKYFOO,TOKENISE,TSTRINGS,WEBURL
    SQL>
    and returns the number of columns specified in the cursor expression;No. Reason - a ref cursor does not have a describe interface. Thus you cannot determine the SQL projection of the cursor and number of columns, column labels and column data types and precision in the projection.
    But the question is.. why on earth do you want to have such a function? What purpose is it suppose to fulfill? What is the underlying requirement that needs to be met? As from what you've stated here, it seems to be pursuing a very incorrect solution for the unknown problem at hand.

  • How to implement this function in JSP/Servlet env?

    Hi all,
    I working on a project, it provides functionality to upload file using JSP/Servlet. In the first JSP page, there is file location and submit button. After user select a file to upload and click submit button, a message, like "sending file to XXXX", will be shown on the screen. Once uploading and validation are done on the server-side, a successful/error msg will be shown to user.
    Here I have a question for the "sending..." msg and the successful/error msg. They should be put in one jsp page or in two separate page? how to implement them?
    Thanks for any help!
    Tranquil

    For the sending message... Well, the thing is, when you click submit, it's sending the file to the server and the server is processing it, and this is all done before the "complete" page is sent to the server. So one would need to use some Javascript on the page before the actual submit happens to show some message. This is done on Ebay when you put something for sale, you can upload an image, and there is a little popup message telling you that it's uploading, and it is removed when the process is done. Now, I'm not sure the exact details of how this works, but my educated guess is this:
    1) The onsubmit function of the form checks that the file upload fields have a value (no need to popup a message if no file upload, since that's what usually takes the time, although it could just be assumed there is a file). If a file is to be uploaded, or just want to show the message anyway, a new popup window is opened with the window.open method and the "sending" message is shown (either written via Javascript or just load a small web page to the window).
    2) The popup window, since you can't transfer the window object from the form page to the next page, has to check window.opener for some value that the success/error page would have to set. The success/error page could use it's body onload function to set a variable in it's own window object to denote that the page is loaded. The popup window can use a looping check using setTimeout or setInterval in Javascript to check for window.opener.isLoadedVariable to be present, and if so, close itself.
    I've never done that, but I see no reason why it wouldn't work.

  • How to define recursive functions in JSP

    Hi,
    If anybody knows, how to to define recursive functions pls help. I am using an XML file for the creation of a tree menu. In order to display the menu, i have to use recursive functions...Also out.println throwing error in the function..
    Thanks,
    Philips

    I do not have my Java book at work with me today so you'll have to bear with me. The following routine assumes that you can get some sort of branch object from your tree menu object (also assuming you have something like this). Furthermore, it assumes that the branch object can return some sort of collection of all leaves and branches on a particular branch through a made-up getLeaves() method call.
    <%!
              public void displayLeaves(Branch branch)
                   Iterator branches = null;
                   branches = branch.getLeaves().getIterator();
                   Object leaf = null;
                   while( branches.hasMoreItems() )
                        leaf = branches.nextItem();
                        if(leaf instanceof branch)
                             displayLeaves((Branch) leaf);
                        else
                             out.println( ((Leaf)leaf).getValue() );
    %>This code fragment should be just the logic you need to expand a tree as JSP output. To invoke this method all you have to do is pass the root branch element to the method from within your JSP. Please let me know if you need additional info.

  • How to write a function with table name as parameter

    I created a function like this:
    create or replace function "GETNAME"
    (did in NUMBER, dtable in VARCHAR2)
    return VARCHAR2
    is
    dname varchar2(200);
    begin
    select lastname || ' ' || firstname
    into dname from dtable
    where id = did;
    return dname;
    end;
    i got an error: table or view does not exist.
    Could somebody tell me how to fix it?
    Thanks,
    Jen

    or by using a reference cursor:  create or replace function dynamic_cursor (pTab varchar2)
        return sys_refcursor as
        c sys_refcursor;
      begin
        open c for 'select * from '|| pTab;
        return c;
      end;
    SQL> exec :c := dnamic_cursor('emp');
    SQL> exec :c := dynamic_cursor('emp');
    PL/SQL procedure successfully completed.
    SQL> print c;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7566 JONES      MANAGER         7839 02-APR-81       2975       1000         20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    10
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7788 SCOTT      ANALYST         7566 09-DEC-82       3000                    20
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
          7945 CINDY      SALESMAN        7698 16-JAN-83       1800                    30
          7950 TINA       SALESMAN        7698 18-JAN-83       1850                    30
    16 rows selected.
    SQL>

Maybe you are looking for