Results 1 to 6 of 6

Thread: Javascript code in servlet

  1. #1
    Join Date
    Dec 2009
    Posts
    213

    Javascript code in servlet

    Hi,
    I want to include javascript code in my servlet. I have tried to use
    response.setContentType (Text \ html);
    then PrintWriter = response.getWriter ();
    then println ()
    I post the result I get is the javascript code as it should be that is a simple html page (. Html). How do I interpret the file.
    Last edited by Aaliya Seth; 14-01-2010 at 07:10 PM.

  2. #2
    Join Date
    Dec 2009
    Posts
    211

    Re: Javascript code in servlet

    Hello,
    Even i have a similar kind of problem. In addition to that, I'm about to call a function included in a script java script that I put in WEB-INF/lib. Is that fair? Otherwise what could be the cause? do you have any suggestion for this. What I have to do to include the code in servlet. Thank you for helping me

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Javascript code in servlet

    Hello,
    Javascript is usually interpreted web browser (client). You should put your javascript in your jsp. I think this is not a good idea to apply. One question I would like to ask you, what do you want to achieve by integrating the jsp code in the servlet, that is what is the use of that. Any special reason for that?

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Javascript code in servlet

    Hello
    Normally, your first method should work (println ()), simply because it is a client side code interpreter as he told my college. Make sure what did not half or double odds odds over who makes your code non-interpretable. A little tip: put your javascript functions in the Head is better. If you have any more queries regarding this then do post back.

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    Re: Javascript code in servlet

    Hello,
    If javascript is not interpreted by the browser, I advise you this:
    response.setContentType("text / javascript");
    or
    response.setHeader("Content-Type", "text / javascript")
    Otherwise the browser will not interpret the stream sent by the servlet in the same way.

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: Javascript code in servlet

    Hello,
    In fact, whether you generate an HTML page complete with all the tags (like any HTML page). In this case, text / html enough. I presume that if you only give the javascript code (no html tag ... so it's not an html page) Well yes, you may need to use text / javascript. Right now, a web browser, can retrieves web pages HTML tags can be asking for more specific plugins (eg javascript). I advise you to generate a real HTML page, and to place the code between <HEAD> and </ HEAD>. Well, I too have a question, what difference does it make to put the javascript code in HEAD or not ? Because I have tested to put it somewhere else, and everything works fine.

Similar Threads

  1. Need JavaScript Code to open URL
    By AM-Anthony in forum Software Development
    Replies: 2
    Last Post: 12-04-2012, 06:50 PM
  2. How to invoke JavaScript Code from an Applet?
    By Soumen in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 01:02 AM
  3. How to convert Javascript code to Html code
    By Bosch in forum Software Development
    Replies: 3
    Last Post: 21-09-2009, 01:20 PM
  4. Code to scroll to javascript element.
    By sizzla in forum Software Development
    Replies: 2
    Last Post: 04-07-2009, 10:13 PM
  5. JavaScript code outside html page
    By Gefry in forum Software Development
    Replies: 3
    Last Post: 30-04-2009, 03:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,627,895.37478 seconds with 17 queries