How to refer javascript in servlets

Hi friends,
I have a doubt.In jsp we can use<%@ include file="sample.js"%>.How do you do the same operation in Servlets

hey,
first of all i would think about getRequestDispatcher().include(request,response), but at least at tomcat it works with .jsp files only (even html files can't be included...).
so i guess the only way out you have is the annoying
out.print(all_your_js_code_here)...

Similar Messages

  • How to write JAVASCRIPT in SERVLET

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.print("<HTML><HEAD><TITLE> DATA NET</TITLE></HEAD>");
    I have to write the following javascript code ......how to do??
    -------------------------javascript code--------------------------------
    <BODY onLoad=pageload();
    <SCRIPT>
    function pageload()
    var time;
    time=200;
    URL=Default.jsp;
    self.setTimeout(top.location.href =URL;,time);
    </SCRIPT>
    </BODY>

    Wow! You've revived a 4 year old thread!
    Well, putting your scripts into a separate JS file makes your page less messy and more importantly, allows reuse of your code. You simply need to link to the JS file instead of copying the same functions in every page. This also makes maintenance easy.
    Also, "text/html" in the post above because the OP was sending HTML. Check this: http://krijnhoetmer.nl/stuff/javascript/mime-types/. It lists the MIME type for JavaScript and which browsers support which ones.

  • 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

  • How to mention encoding in servlet.

    Hi
    How to mention encoding in servlet.
    Regards
    Arghya Banerjee

    I suppose your question may refer to the setContentType method discussed here:
    http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletResponse.html
    If not, ask a more specific question.

  • How to use JavaScript in Web bean generated JSP

    I want to do some simple JavaScript validations (for example, checking if a particular field is empty) in the JSP page rendered by the data web bean. Because the HTML is rendered by the bean, I'm not able to refer to the HTML controls in the JSP page. I'm not even able to refer to the form with the following standard piece of JavaScript code - "document.forms[0].control_name".
    Is anybody aware of how to use JavaScript with these rendered JSP pages?

    You just have to add it like and applet , including this line in your JSP or JSF
    <script src="http://dl.javafx.com/dtfx.js"></script>Then add the applet
    <script>
        javafx(
                  archive: "./resources/jar/Draw.jar",
                  width: 400,
                  height: 200,
                  code: "Draw",
                  name: "Draw"
    </script>./resources/jar/Draw.jar - is the path and the name of the jar

  • How to use Javascript in OBIEE?

    Hi all,
    can any one tell how to use javascript in OBIEE. i.e steps to follow to insert the javascript in OBIEE 11g or 10g

    If you are trying to display total number of pages in a report, Add the below formula in the column of the report and hide that column in the report.
    FX = sum(count(1))/25
    You can then reference the column in the narrative view like this: "Total pages in the report are @5" and out put may be "Total Pages in the report are 30".
    Or
    You can also use something like the below:
    To calculate them use fi:
    CEILING(CAST(RCOUNT("FactColumn In the Report (Sum All)") as DOUBLE)/ 25) for the page number
    CEILING(CAST(COUNT("FactColumn In the Report (Sum All)") as DOUBLE)/ 25) for the total pages
    Put the above formula in the column and reference it in the narrative view like I mentioned in the previous example.
    If you are report view is pivot, then please refer to this link: http://oraclebizint.wordpress.com/2008/01/17/oracle-bi-101332-pagination-in-pivot-tables/
    Hope this helps.
    Thanks,
    -Amith.

  • Passing variable from javascript to servlet!!!

    Hi all,
    I have one doubt,
    can we pass a variable from javascript to servlet???
    In Brief,
    i am getting some values in javascript through jsp and the same values i
    want to use in servlet.
    Yes, i know i can get these values in servlet by using request.getParameter("");
    But these values are dynamically generated so i dont know how many varaible are they!. so i am trying to put some array list so that i can forward this values to servlet.
    But i can't get this array which is declared in javascript!! :( so any buddy can help me how to get this dynamically generated values in servlet!!!
    Thanks in Advance!! :)

    can you post a sample of your code?
    remember to put it between tags                                                                                                                                                                                       

  • Javascript in servlets help???

    Hi everyone just have a look at the folloeing code..
    //function next
         out.println("function next(){");
         rs.next();
         out.println("window.document.frm1.qno.value="+rs.getString(1));
              out.println("window.document.frm1.ques.value=\""+rs.getString(2)+"\"");
         out.println("}");
    out.println("<input type=\"button\" value=\"Next\" onclick=next()>");whenever I press next button I am only able to get second row
    How can I move my resultset to next row each time I press "next" button

    java.venkat wrote:
    I am very sorry I didnt get back to this thread because I didnt add this to my watchlist
    I started my project in servlets , Now I can't convert to JSPs.
    Including javascript in servlets is becoming very headache for me...Why can't you convert to JSPs? Trust me, you don't want to be doing this in servlets, it's madness. Begin with JSPs immediately, you'll save more time and effort and frustration than you can imagine.
    >
    I got a new problem
    out.println("<form name=frm1 action=Cone>");
    out.println("<input type=\"submit\" value=\"Submit\" onClick=\"validate()\" >");
    out.println("function validate()");
    out.println("{");
    out.println("if(document.main.name.value==\"\"||document.main.address.value==\"\")");
    out.println("alert(\"Please Enter Your Username and Password\"\n)");
    out.println("}");Now whenever Submit button is clicked "validate()" is exceuted and an alert box is shown. and servlet is also executing
    How can I stop servlet to execute when validate is executed..This is a JavaScript problem, not the right place for it.
    You need to return true/ false from your JavaScript function depending on if you want to allow the action or stop it.
    And where the function is called make a change:
    <input type="submit" value="Submit" onClick="return validate();" >The return keyword will pass the value returned by validate() to the onClick() event handler and stop the propogation of the submit event if the value is false. If it's true,it'll continue.
    And please, once again, for God's sake, do yourself a favour and switch to JSPs!
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • Passing Parameter from javascript to Servlet

    hi,
    I have 2 list boxes in my Jsp page and values for these list boxes are preloaded . These things are to be carried out using javascript onload() function.
    So now i want to pass the selected parameters from both the list boxes to servlet and have to display the corresponding resulting datas in same JSP page. if i submit the form then values selelcted by the user will reset because the form has onload() function. then i thought hidden field will solve my problem. but its giving error like nullpointer exception.
    so please tell me how to achive this.

    When you right a new Option(...) line in javascript, there are three parameters you can give:
    Option("text", "value", selected);
    How you make use of this depends on how you move from the servlet back to the JSP.
    So for example, if you are doing a response.sendRedirect in the servlet, you will either have to add a parameter back to the url you are re-directing to, or add the value to the session. (I like the session method myself... hides it from the user)
    //in servlet
      public void doGet(...)... {
        String country = request.getParameter("country");
        String state = request.getParameter("state");
        //... Do Stuff ...
        HttpSession session session = request.getSession();
        session.setAttribute("country", country);
        session.setAttribute("state", state);
        String sendTo = response.encodeRedirectURL("theForm.jsp");
        response.sendRedirect(sendTo);
      //... The JSP might look like this now...
      //Get the selected values from the session:
      <%
        String countrySelected = (String)session.getAttribute("country");
        String stateSelected = (String)session.getAttribute("state");
      %>
      <html>
      <head>
      <script type="text/javascript">
      /* Use this to store the values for states in JavaScript */
      var state2DArray;
      /* Javascript function to set up values for the states  and countries */
      function initSelects() {
        <%
          /* This is JSP scriptlet code to get the country list that we need... */
          List countries = (List)application.getAttribute("countryList");
        %>
        countrySelect = document.form.country;
        <%
          /* This is JSP scriptlet code to loop through the countries and assign
           * values as needed.  We will break out of scriptlets to print out
           * the javascript needed to assign values to the countrySelect and to
           * the state2DArray
          int countryCount = countries.size();
        %>
        state2DArray=new Array(<%=countryCount+1%>);
          state2DArray[0] = new Array(1);
          state2DArray[0][0]="--Select A State--";
        <%
          for (int co = 1; co <= countryCount; co++) {
            Country country = (Country)countries.get(co-1);
            List stateList = country.getStates();
            int stateCount = stateList.size();
        %>
        //Now we add a true/false if the country should be selected...
        countrySelect.options[<%=co%>] = new Option("<%=country.getName()%>","<%=country.getId()%>",
                                                    <%= (country.getId() == countrySelected)%>);
        state2DArray[<%=co%>] = new Array(<%=stateCount+1%>);
        state2DArray[<%=co%>][0] = "--Select A State--";
        <%
            for (int st = 1; st <= stateCount; st++) {
              String stateName = (String)stateList.get(st-1);
        %>
        state2DArray[<%=co%>][<%=st%>] = "<%=stateName%>";
        //We are going to call the fillInStates now at the end of initSelects so the initial
        //values are passed on to the states...
        fillInStates(countrySelect);
        <%
        %>
      function fillInStates(countrySelect) {
        selectedCountry = countrySelect.selectedIndex;
        stateCount = state2DArray[selectedCountry].length;
        stateSelect = document.form.state;
        stateSelect.options.length = 0;
        for (state = 0; state < stateCount; state++) {
          //Again add true/false if it should be selected...
          stateSelect.options[state] = new Option(state2DArray[selectedCountry][state], state2DArray[selectedCountry][state],
                                                  <%= (stateSelected == state2DArray[selectedCountry][state]) %>);
    </script>
      </head>
      <body onload="initSelects()">
      <form name="form" id="form" action="#" method="get">
        <select name="country" id="country" onchange="fillInStates(this);">
          <option value="">--Select A Country--</option>
        </select>
        <select name="state" id="state">
          <option value="">--Select a State--</option>
        </select>
      </form>
      </body>
    </html>

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

  • How to refer report items?

    Hi,
    How to refer the report items?
    I have standard sql report region contains 3 columns.
    doc_id,doc_name and No_units.all three items are apex item.
    below is my sql query for report.
    APEX_ITEM.SELECT_LIST_FROM_QUERY(17,doc_id,'select s_id from         
    sales')"doc id",
    apex_item.text(18, doc_name) "doc name",
    apex_item.text(19,  No_units) " No units",null
    from sale_docMy intention is to fire a dynamic action when event change in doc_id. So in when tab what i have to assign in item(s) fields for doc_id. i gave *#doc_id#* in items(s) field it doesnt work.
    how to resolve this?

    any help?

  • How to call two different servlet-url in the same application

    Hi,
    I want to call, consecutively these methods in my application.
    response.sendRedirect(servlet-url1)
    reponse.sendRedirect(servlet-url2)
    but the second method dont answer,
    I think, the first method redirect s with response ,
    but how to call two different servlet ?
    thanks

    if you call the first redirect, the servlet is getting aborted, so you can redirect to the first servlet, working the stuff in it, and then in the second servlet you can redirect to the third servlet

  • How to refer one view from another view?

    Hi,
    I have 2 views in my Adobe Flash Builder mobile app. I need to refer the first view in my second view.
    How to refer one view from another view? Or how to create a reference to a view wherever needed?

    I don't need any data from my first view. In a certain flow, I need to make my first view to be invisible.
    for eg., My First view is in portrait mode. I change the device to Landscape. In the landscape mode, I want to show a completely different view (second view).
    In this case, what happens is, I see my first view in Landscape mode for a second. Then the second view appears. When I change to Landscape mode, only the second view should be seen. I need to make my first view to be completely invisible in the OnOrientationChanging event of
    StageOrientationEvent
    As stage object and StageOrientationEvent works at application level, I need to know how to refer my first view object in the application level.
    private function onOrientationChanging(soe:StageOrientationEvent):void
          MyFirstView.Visible = False; ====> don't know how to refer MyFirstView here
    Is my question clear now?

  • How to refer a column value of a single row in conditional column display?

    Hello,
    does anybody have an idea, how i can refer a column value of a single row in conditional display of a column?
    So my idea is, that a report has a column, which value is only displayed, when another column value of this row has a specific value.
    I want to solve this problem with condition type: PL/SQL Function Body returning a boolean.
    But I do not know how to refer the column value of each single row!
    Thank you,
    Tim

    Here's a solution that, to me, seems easier to implement but, that's, of course, in the eye of the implementer.
    Rather than using APEX to generate a link column for you, actually create the link as part of your SQL.
    select '<a href="f?p=102:3:491847682940364::::P3_CONTACT_ID:' || CONTACT_ID || "><img src="/i/themes/theme_1/ed-item.gif" alt="Edit"></a>' CONTACT_LINK, ...
    etc.
    Test this out. You'll see that it works just like making a column a link using the column attributes.
    Next, we'll change the SQL to use a DECODE statement to either display the link or nothing depending on what your criteria is. For example, let's assume you only want a link for active contacts.
    select Decode( CONTACT_STATUS, 'A', '<a href="f?p=102:3:491847682940364::::P3_CONTACT_ID:' || CONTACT_ID || "><img src="/i/themes/theme_1/ed-item.gif" alt="Edit"></a>', NULL ) CONTACT_LINK, ...
    etc.
    This will not display the link in any rows in which the CONTACT_STATUS is not active, i.e. "A"
    -Joe

  • How can I run a servlet with Sun Java System Application Server PE 8?

    I've created a package with a TestServlet.class inside, used the deploytool to create a WAR and deployed this using the autodeploy folder.
    The filestructure has been generated and I find the TestServlet.class in
    [installdir]\domains\domain1\applications\j2ee-modules\testProject\WEB-INF\classes\[packagefolderstructure]\TestServlet.class.
    The context root is working fine, but I have no clue how I can run the servlet directly via the URL.
    I've tried many things like
    http://localhost:8080/testProject/TestServlet
    http://localhost:8080/testProject/servlet/TestServlet
    http://localhost:8080/testProject/servlet/[packagenamewithpoints]TestServlet
    http://localhost:8080/testProject/servlet/[packagenamewithslashes]TestServlet
    etc etc
    Can somebody tell me please how to write URLs to deployed servlets? Or send me an example url and xml descriptor files?
    Thanks a lot in advance!

    in web.xml use servlet mapping
    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/doit</url-pattern>
    </servlet-mapping>then use http://localhost:8080/testProject/doit

Maybe you are looking for

  • X1 Fading/flickering to black and white and then returning to color,

    X1 Fading/flickering to black and white and then returning to color, video lags, image moves up and down I have had the X1 for almost 1 year and it is really acting up. It flickers/fades to black and white, the video lags on ocassion, and the image m

  • Problem in Creating Receiver Agreement

    Hi, I had created a namespace in IR and did a simple idoc to file scenario. In the IR, the MI and MT are not been shown while creating the receiver agreement and receiver determination. Do let me know what would have been wrong. I tried entering it m

  • N8 still on PR1.1

    I bought, original phone, over my telecom in Bosnia and Herzegovina. And I am still on PR1.1. 013.016 Phone works fine and there is no problem. But! People is is still on PR1.1. Even Sudan has PR1.2. And I speak same language as Croatia and Serbia an

  • Problem with CRW files

    I just installed Aperture, changing from Photoshop Elements 4. But I have a problem with my .CRW files from my Canon Powershot S45 (RAW format). If I click on them, I get a glimps of a low resolution picture, but that is immediately replaced by the w

  • Accessing jar inside  javascript

    Hi, Is there way to access a jar inside a javascript?