JSP function

Hi,
I want to create a function in a jsp page and after I want to call this functin from another page.
How can I do that?
Thank you!
Caroline

I don't think there is a way to do that. If you want to re-use functions in JSP pages, I would do this:
1. Write the function in a separate file:
<%! private String myFunction() {
         return "Hello";
%>Save this code in a file "myFunction.inc" or whatever you want to call it.
2. Include this file in the JSPs you want to use the function. The contents of the included file will be
appended where you place the include statement.
<%@ include file="myFunction.inc" %>
That way you can re-use functions as needed.
Michael Bishop

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 ...

  • How to use sswa jsp function in personalization?

    I have a question. When I add a custom item of type link in a region using personalization, how can i access the click of the link as an event in that region';s controller.
    Also if I want to use the "destination function" field of the new Link created with an existing seeded SSWA JSP function, how do i pass url parameter values to this function.
    The function name is IMC_NG_PER_SOURCE_VIEW and the HTML call is OA.jsp?page=/oracle/apps/imc/ocong/mosr/webui/ImcPerMosrViewPage&ImcPartyId={@ImcPartyId}&ImcPartyName={@ImcPartyName}&ImcMainPartyId={@ImcMainPartyId}
    Now when I click the link on the Page the HTML call is made as is, i.e. the target Page ImcPerMosrViewPage gets the value for ImcPartyId = "{@ImcPartyId}" instead of the real Party ID.
    Whereas on the same Page there is a side bar Menu, and one of the Menu item makes a call to the same sswa jsp function and when we click the menu item the target page is rendered successfully.
    So my question is how do I make the link on the region to work the same way as the Menu item.
    It would be great of you could share some tips to resolve this issue of mine.
    Many Thanks!
    Jay

    Just set the fire Action property of that link and capture that in controller PFR.
    Thanks
    --Anil                                                                                                                                                                                                           

  • Calling out.println in a jsp function

    Hi, i want to call out.println in a jsp function. That is i am using function like this
    <%!
    void MyFunction()
    out.println("this is good");
    %>
    This code fails with error message: "out cannot be resolved"
    Also i don't want to return value from the function, since i will later call this function recursive and display value at each instant.
    Please suggest any solution.

    <%!
    void MyFunction(JSPWriter out)
    out.println("this is good");
    %>and then execute it with:
    <% MyFunction(out): %>

  • How to call JSP function from onClick Action

    Hi
    I am trying to call a jsp function, onclick of a checkbox. This jsp function will in turn connect to the database and gets related information. I dont want to submit the data inorder to avoid posting and getting of huge data. Is there a simple way to call a jsp function from the users onClick action.
    Appreciate anyones help!!!
    Thanks alot
    Joe

    So, i have to submit the form to call the jsp function. Basically yes.
    Sorry for the shortness of the answer, but I am pretty sure we have had this conversation (or one very much like it) before.
    Java/JSP runs on the server, generates an html page, and stops running.
    Javascript runs on the client in the web browser, once the page is loaded.
    You cannot call java code from javascript.
    The only way you can run java code again is to make a request - either by submitting a form, or clicking a link.
    If you don't want to refresh the current page, you CAN get tricky with javascript and multiple frames. You submit to another frame, and when it loads, it uses javascript onload event to call back and modify the main frame. Its tricky to get going, and very easy to break, so I don't normally recommend it.
    Good luck,
    evnafets

  • Hi @include in a JSP function

    Hi,
    I wanted to use the @include directive in a jsp function. But when I compile it I get errors.
    Is this allowed ?
    <%!
    private boolean isDisplayAllowed () {
    %>
    <%@include file="foo.inc"%>
    <%@include file="bar.inc"%>
    <%
    %>
    Thanks
    RT

    Thanks
    I have a code that is needed to be shared between multiple jsp files. So I moved them to an inc, file so as to share between multiple files.
    Now I need to use this in jsp functions, so I am not sure how to do this.
    If instead of using include approach if there is any other way to share the code, please let me know.
    Thanks
    RT

  • Call jsp function in javascript without using Applet

    anyone knows how to call jsp function in javascript .
    just as follows:
    <%!
    public string jspcall()
    return new String("just a example");
    %>
    <script language="javascript">
    <!--
    temp = jspcall();
    //->
    </script>
    it's desn't work.
    any suggestion will help!

    it's was not able to call a jsp function in javascript.
    jsp function was on server site while javascript normally on the client site.

  • How to refresh a "SSWA jsp function" ?

    Dear all:
    I change sth in a package "HR_LOA_SS" (the package is "SSWA jsp function" ). What steps should I do to relink the package than make it available?
    Regards
    Edited by: Terry Chen on 2009/12/14 下午 11:06

    Hi,
    Submit "Compile Security" concurrent program from System Administrator responsibility and check then. Bouncing Apache is not required, but you may need to do so in case you cannot see the updated code.
    Regards,
    Hussein

  • How to call a jsp function on a java script event 'onchange'

    hi all,
    i m in trouble, iwant to call a jsp function on occurance
    of a javascript event onchange
    actully i want to refresh my one text field at every change
    in a select option of a form
    plz tel me any othr method if i m wrong.
    thnx in adv.

    as the form submition is a POST operation u can use some
    if{} else{} construct to handle this. u can check the value of some POST variable to identify whether its the first loading or refresh. got it
    regards
    aleens

  • How to pass javascript variable to jsp function

    i want to check which table header (that is <th> in html )is clicked and based on that a jsp funtion do a query in database and should show records in sorted way according to which column head is clicked.
    Table is created in html.
    My function is
    Vector varray = workcaseid.getWorkcaseId(Long.parseLong(MasterAccountNumber),SelectedColumn);
    <table border="1">
              <th ><label onClick="<%SelectedColumn="workcase_id";%>">Workcase Id</label></th>
              <th><label onClick="<%SelectedColumn="status_id";%>">Status</label></th>
    <tr><td>etc</td></tr>
    </table>

    im using bean for business login, following mvc model,and i think mvc is one of good design practice to use.
    <jsp:useBean id="workcaseid" scope="session"class="beanFiles.SearchWorkcaseId" />
    varray = workcaseid.getWorkcaseId(Long.parseLong(MasterAccountNumber),SelectedColumn);
    just tell me whether it is possible to pass javascript variable to jsp variable or not.i can do it by using hidden input type,using form and submit button.

  • Help on JSP Function

    Hi,
    I am writing follow. java function inside my JSP
    <jsp:useBean
         id="inquiryBean" class = "com.bbh.actionworld.pagingcontrol.inquiry.Inquiry" scope = "session">
    </jsp:useBean>
    <%
         int sIndex = inquiryBean.getStartIndex();
         int eIndex = inquiryBean.getEndIndex();
         int pSize = inquiryBean.getPageSize();
         out.println("sIndex= " + sIndex + "eIndex = " + eIndex + "pSize = " + pSize);
    %>
    <%!
    void getNextRecords() {
    if (sIndex == 0)
    if ((sIndex > 0) && (sIndex < dataArray.length))
    sIndex = eIndex;
    eIndex = sIndex + pSize;
    out.println("after next sIndex = " + sIndex + "eIndex = " + eIndex + "pSize = " + pSize);
    inquiryBean.setStartIndex(sIndex);
    inquiryBean.setEndIndex(eIndex);
    %>
    I'm getting errors like sIndex, eIndex , pSize ,out , inquiryBean are undefined variables in function.
    Can anybody help me ?
    Thanx in advance.
    -Priya

    do the three variables have local scope.
    i.e have you declared them within a block and are trying
    to use outside that block , if so they no longer exist in
    memory.
    just a guess.

  • Out.print() in a jsp function

    Hi
    I have a jsp page. I have defined a function in it which requests the farm parameters through request.getParameter() and then print it using out.print() but it displays errors on request and out objects.
    How can I use these objects in functions declared in a jsp page.
    Thanks in advance
    Sajid

    Try Like this
    <%!
    public String aFunction(HttpServletRequest request,JspWriter out){
    String sName = request.getParameter("Name");
    out.println("Hai "+sName+" i think you got it now!!!!!!!!!!");
    %>

  • JTF JSP functions interoperable with OA Functions

    Hi Gurus,
    I have a Custom Responsibility have a few OAF functions and few JTF ( like Calender , Task etc ). In order to create the Tab and Sub Tab like Structure I have created different Menus , submenus of ( HTML , SUB HTML types) and have also included the OAHF and OASF parameters in the Functions URL.
    Now the Home Page Renders File. When one click on the OAF Function it renders the Tabs correctly. Once I am there one click on any of the links (JTF or OAF ) everything works as desired.
    But when from HOME Page one click on JTF Function the Page do not render properly.
    Is there some technique / process which needs to be taken care of ..the developer guide is good for OAF related pages I believe.
    Do JSP pages understand the OAHF and OASF parameters or there is some other settings?
    Any poinetes doc is helpful
    Thanks,
    Sunit

    You get the same error even when the class which includes the method is missing. Can you check whether the class is available in WEB-INF/classes or WEB-INF/lib or at the ear level?
              I just tried this locally and it works as expected w/ the class in web-inf/classes
              We'll add a better error message in this case.
              -- Nagesh

  • Accessing values of components in a form in a JSP function

    Hi,
    I have a peculiar problem. I want to access the value of a textbox in my JSP method. Please let me know how to do that.
    The code is
    <%!     
         public boolean checkFile(String filepath)
         System.out.println("************ " + filepath);
         File f = new File(filepath);
         return (f.exists());
    %>
    the variable filepath should be the value taken from a text field.
    When the user enters a file name i need to check if the file exists or not. Is there a better way to do this. Please suggets me a way to solve this.. Very urgent.
    Thanks
    pops

    Well JSP is server side code and TextBoxes are html which is client side script. To get the value of an html Textbox you either can use Javascript and do it all client side or you can post your form to a JSP or servlet and use request.getParameter("field_name"); to get the value of the form field.
    make sense?
    -S-

  • How to make a "SSWA JSP Function"  as query Only in Oracle 11i or R12

    Please someone help me in making a SSWA JSP Page as read only..
    For "forms" we use a parameter QUERY_ONLY="YES",what is the procedure for making a JSP as read only?

    All the enterable fields of an OA Framework Page can be made Read Only via personalization. Also you can disable/hide the transaction buttons. This way the page would become query only.

Maybe you are looking for