Javascript inside jsp

Hi,
is it possible to call a javascript function or can i add events like onClick, onLoad inside the body tag when the response content type is set to "response.setContentType("application/vnd.ms-excel")" ??
Currently the issue is none of the events or javascript function calls are getting executed as soon as i set the contenttype as above. so what should i do to call the script function or call some event. Since i am novice in this particular field please explain the solution in a simple way.
Advance thanks,
Yours sincerely
Raghu

This is the setting i am making to open the file as an excel sheet.
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "filename=" + "abc.xls");
response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader("Expires",0);
response.addHeader("Cache-control", "no-store");
response.addHeader("Cache-control", "max-age=0");
Is this all right?? And after this i write the contents to the excel sheet and then i need to call a javascript function to close the child window.
Thanx

Similar Messages

  • Using javascript inside jsp

    hello
    My front end is jsp.so in jsp i want to write a javascript function for validating the form fields given by the client. so give me any simple javasript sample program....thank you.

    See: www.google.com for more information

  • Putting javascript inside WEB-INF

    I could not call a javascript function test() from JSP. my function is defined in .js file places inside WEB-INF/javascript/script.js
    and my JSP is inside WEB-INF/jsp/report.jsp. Its says object expected. I have tried all ways but could not access that function from JSP. Both javascript and jsp are inside WEB-INF folder. This is required.
    Following is the code...
    <html><head><title>Main Menu</title>
    <script type="text/javascript" src="../javascript/tabpane.js"></script>
    <link type="text/css" rel="StyleSheet" href="../css/tabpane.css" />
    </head>
    <body><h1>Report types</h1>
    <div class="tab-pane" id="tab-pane-1">
    <script language="javascript">
    test();
    </script>

    I could not call a javascript function test() from
    JSP. my function is defined in .js file places inside
    WEB-INF/javascript/script.js
    and my JSP is inside WEB-INF/jsp/report.jsp. Its says
    object expected. I have tried all ways but could not
    access that function from JSP. Both javascript and
    jsp are inside WEB-INF folder. This is required.
    Following is the code...
    <html><head><title>Main Menu</title>
    <script type="text/javascript"
    src="../javascript/tabpane.js"></script>
    <link type="text/css" rel="StyleSheet"
    href="../css/tabpane.css" />
    </head>
    <body><h1>Report types</h1>
    <div class="tab-pane" id="tab-pane-1">
    <script language="javascript">
    test();
    </script>The script element includes a client-side script into the document. Client-side script is executed by web browser in this case, while WEB-INF is an "protected" area and is not accessible to web browser. So you can not put javascripts, images and css files into WEB-INF directory.

  • Associating two events with submit button using  javascript in jsp

    Hi
    How can i Associate two events with submit button using javascript in jsp. Firstly it should insert the data to database and secondly it should close the same pop-up window

    Have something like :
    <input type="submit" name="submitbtn" value="Click me" onClick="function1(); function2(); " />
    You just call both functions sequentially, it's that simple. Although using javascript to work with a database, that seems a bit tricky.

  • Help me!! How to use JavaScript with JSP ??

    I am using JDeveloper and I created a screen in JSP which uses a bean for database connectivity and retriving info onto the page.
    The page has a ListBox where list items are populated from the database.My requirement is
    whenever the list is changed the page shuold be refreshed with the selected item info.
    I tried to use 'JavaScript' for triggering the event with 'onChange' event of the ListBox.But the event is not getting invoked. I think JavaScript is not working with JSP.
    Please help me with how to Use javaScript with JSP or any other alternative where I can meet my requirement.
    I have one more question...I have gone through the JSP samples in OTN and I am trying do download the sample 'Travel servlet' which show list of countries...etc
    I have also gone through the 'readme' but I don't know how to extract .jar file.
    I would be great if you could help me in this.
    Thanks!!
    Geeta
    null

    We have a similar need. We have used Cold Fusion to display data from Our Oracle Database. We have a simple SElect Box in HTML populated with the oracle data. When someone selects say the State of Pennsylvania. then we have an On change event that runs a Javascript to go get all the cities in Pennsylvania.
    Proble we are having is that inorder for the Javascript to work , we currently have to send all the valid data.
    Do you know of any way to dynamically query the the Oracle database in Javascript

  • Servlet with no dynamic code inside jsp pages

    Hello,
              I saw that a servlet is created even if there is no dynamic code inside jsp pages (scriplets & tags). Is it possible to avoid it on bea side ? (I am using portal 8).
              By the way, do you know if is it possible to define apache in order to avoid to send to bea the jsp which have no dynamic code inside ?
              thank you !

    JSP's always generate a servlet on all web containers. Apache/Tomcat is no
              different. If you have static content, make it an HTML page.
              Bill
              "hournon jc" <[email protected]> wrote in message
              news:22255787.1103297053148.JavaMail.root@jserv5...
              > Hello,
              >
              > I saw that a servlet is created even if there is no dynamic code inside
              jsp pages (scriplets & tags). Is it possible to avoid it on bea side ? (I am
              using portal 8).
              >
              > By the way, do you know if is it possible to define apache in order to
              avoid to send to bea the jsp which have no dynamic code inside ?
              >
              > thank you !
              

  • Handling ActiveX events with Javascript inside BSPs

    Hi,
    Has anyone any experience with handling events from ActiveX objects (using the <object> tag) with Javascript, inside BSPs?
    I'm developing solely for the IE browser. Reading other threads, I know that the usual way this is done is via the below code excerpt:
    <i><script type="text/javascript" for="MyObject" event="Object_Event">
         js_function();
    </script></i>
    I create a HTML page, with the <object>, <script..for..event> tags, etc. Everything works fine when the page is run from my local system. However, when the code is run from WebAS (Activate then Test (F8)), the ActiveX object loads fine. But the javascript does not respond to events thrown by the ActiveX object.
    I wonder if anyone can share their experiences on this issue.
    Thank you.
    Amos

    It's the Skype4COM (v1.0.0.17) wrapper for the SkypeAPI, available at https://developer.skype.com/Download
    (Note: NOT the v1.0.0.16, which comes with the Skype ActiveX Tools package).
    I'm trying to use javascript to handle the event "CallStatus", thrown by Skype4COM, as shown in the code excerpt below.
    <i><script language="javascript" type="text/javascript" for="Skype" event="CallStatus(Call, Status)">
                 handleCallStatus (Call, Status);
    </script></i>
    It works locally, but not when in a BSP.
    It's rather interesting to mess with Skype calls from a webpage. Do let us know how your experience goes
    Amos

  • Embed javascript in JSP

    hi
    i want to store the query string of an URL in a flat file. but i want to append the name of the person who's passing the query string by prompting him to enter his/her name. i have a code something like this
    FileWriter outputFile = new FileWriter("Libset1.txt", true);
    BufferedWriter outputBuffer= new BufferedWriter(outputFile);
    final PrintWriter outputWriter = new PrintWriter(outputBuffer);
    //writes all data to the output file
    for (int i=0; i<Selected_set1.length; i++)
    outputWriter.println("some javascript to prompt the user goes here..." + Selected_set1);
    outputWriter.close(); //closes output file
    i want to embed some javascript in place "some javascript to prompt the user goes here..." prompting the user to enter his name..
    is it possible to do that. if yes, how.?
    sorry i'm just a beginner, it might look silly for you...please help...
    thanks in advance..

    First of all, you need to understand how Javascript and JSP work together....they don't. Javascript is a client side scripting language, which means that it executes and runs in the client browser after the page has been loaded. JSP is purely server side, it only runs while the request is being serviced, or while it's generating the HTML to send back to the client browser.
    To do what you're asking for should be pretty easy using javascript. You should be able to use the Javascript onClick() event for the link the user is clicking on to execute a Javascript method that prompts the user for their name.
    You might try something like this...
    <script language="JavaScript">
    function promptUser(newPage)
      var username = prompt("Please enter your username");
      if(username)
        document.location = newPage + "&username=" + username;
    }</script>
    Click Here Please!
    This will result in a query string that looks something like mypage.jsp?id=23&view=whatever&username=john
    Make sense?

  • Parameters b/w javascript and JSp

    how i can pass values between javascript and jsp .
    ( java script varaible in the JSP part & jsp object in the javascript code )

    Since Java script is on the client side , to get the value of a java script variable into jsp, u have to set some form field variable and submit it to the server again. So, it can be something like:
    <script>
    function submit()
         var scriptVar = 12;
         document.form1.formVariable.value=scriptVar;
         document.form1.submit();
    </script>
    <%
    System.out.println("Script variable value = " +request.getParameter("formVariable"));
    %>
    <form name="form1" method="post">
    <input type="hidden" name="formVariable" value=""/>
    <input type="button" name="bSubmit" value="Submit" onclick="javascript:submit()" />
    </form>
    The first time this jsp is called, the value of formVariable will be null.
    The next time, when u click on submit button, the value will be 12.
    I have not tested this. There might be some syntax errors. Just try it out. Also, make sure that u don't end up submitting the form in an infinite loop by using the submit() generally in the script. Hope this helps.

  • Mix JavaScript and JSP

    Hi.
    I have jsp and javascript mixed when I click a check call a function javascript for example:
    //JavaScript
    function Hola(numerop) {
              idRol = Number(numerop)
              <%nombreRol = roles.get(numerop)%> }
    //Form
    <input type="checkbox" name="<%=roles.get(sum)%>" value="<%=roles.get(sum)%>" onClick="Hola('<%=roles.get(sum)%>')">
    In the function numerop is a number but in the jsp code numerop is undefined.
    How I can mixed javaScript and jsp??
    Please I need help you.

    Remember that the JSP runs on the server and generates the HTML, including Javascript. The Javascript runs on the browser after the JSP is finished. So you cannot do whatever it is you expected that to do.

  • How to genarate javascript from jsp?

    how to genarate javascript from jsp?
    Edited by: coolsayan.2009 on May 12, 2009 6:21 AM

    coolsayan.2009 wrote:
    [got an example|http://www.ibm.com/developerworks/web/library/wa-aj-simplejava1/index.html] but can you say all this specifically because i am not familier with AJAX.and i want to generate a javascript random number and by jsp i want to send it to user email.once user got the number it will be checked wheather he got it or not in next page say check.jsp if it this entry is right he will be grant to access the his account....
    What does AJAX have to do with the rest of this question? And why do you want to generate a number in JavaScript at all? If you are trying to confirm a working email address, which is what I think you are trying to do then leave that all on the server side. Generate the number in the servlet, mail it, etc. Neither JavaScript nor AJAX are any part of that.

  • Java inside jsp???

    i've written ODBC connection with java standalone code. Can i use that java code inside jsp? Instead of re-writting the whole program in jsp, is there anyother way???

    certainly you can.
    However doing database access from a JSP is considered bad style.
    Better would be to bundle the database connection code into a bean, and use it from both your application and your JSP.
    Also, be aware of the differences in classpath to locate your JDBC driver. For a JSP the classpath is basically the web-inf/lib directory. So as long as you put your JDBC driver there, you should be fine.

  • Can JavaScript access JSP variable?

    Could we do this? Or, how could we have JavaScript access JSP variable?
    <%
    String fooBar = request.getParameter(......
    %>
    <script language="JavaScript">
    <!--
    if (fooBar  == ...) {
    -->
    </script>

    To access the variable in Javascript you'll have to
    write it out from the JSP. You'll need to do something
    like:
    <%
    String fooBar = request.getParameter(......
    %>
    <script language="JavaScript">
    <!--
    var fooBar = '<%=encodeQuotes(fooBar)%>';
    if (fooBar  == ...) {
    -->
    </script>You'll need to either make sure fooBar doesn't contain
    any quotes or write a function to replace each ' with
    \'.Thanks!
    That works perfectly, without encodeQuote() method in my current case.
    Thanks again. You ar a saviour.

  • How to get the status of Javascript inside a java class

    Hi,
    Can anybody let me know the way by which I can get the status of Javascript (enabled/disabled) in browser inside a Java Class.
    I do have a trick -
    <input type="hidden" name="jstatus" value="disabled">
    <input type="submit" name="submit" onClick="doChecking()">
    <script language= javascript>
    function doChecking()
    document.form.jstatus.value = "enabled";
    submit();
    Now inside our java class we can check the value of "jstatus" if it is disabled then it is disabled else it is enabled.
    Ha ha wat a stupid trick...... ;-)
    Plz let me know a real approach to determine the Javascript status.
    Cheers !!!
    Irshad

    Actually, I don't think that trick is stupid at all. Javascript and Java are normally in no way related (javascript is just plain text content to your servlets / jsp's). So a good way of getting such information to your server is submitting it, like you do.
    Another possibility would be to do it with Ajax in the background, but that all depends on what you do with the information.

  • JavaScript within JSP

    Hi all !!
    I'm stuck up.
    Is there any way by which i can actually embed JavaScript within a JSP file that contains no JSP code. Actually it is file with .jsp extention but from within it holds only java script inside <script> tags.
    The prerequisite is there should be no performance implications... as this would be just a plain js file anyways.
    I need this coz i want to pick-up messages for alert from Resource bundle. For this i'am using <bean-el:message ...> tag. but using this in a plane .js file is not possible.
    How should i go about it.
    or
    Is there any better way to do this.

    You could put how much ever js that you need inside a jsp file. Theres no restrictions and given that you have to pick up messages using a tag, there's no other way out too.
    Other than the compilation time (which can be overcome by precompiling jsps), there's not much of a difference in the load time for a static html or html streamed from a jsp process. Ofcourse if you use the 'src' tag to load you js, each 'src' results in a round trip. However that's true of even static html pages.
    cheers,
    ram.

Maybe you are looking for