Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
need some help regarding java and web
Old 02-18-2009, 04:57 AM need some help regarding java and web
Junior Talker

Posts: 2
Name: Mike
Location: Philippines
Trades: 0
hello everyone,

ok here is my problem. i have a java servlet wherein it has a StringBuffer that appends my html tags and a javascript. My question is that is there a way wherein i can append a javascript in the StringBuffer using response.setContentType("text/html")? oris there another way to append a javascript in java to be flushed in html?
below is a sample script i made.


StringBuffer buff = new StringBuffer();

buff.append("<p>just some text here..</p>");
buff.append("<script \"text/javascript\">callFunction();</script>");

response.setContentType("text/html");
response.getWriter().println(buff.toString());
response.getWriter().flush();

whenever i execute this program it outputs the html part but does not execute the javascript part.

thanks
Eagle-Man is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-18-2009, 07:56 AM Re: need some help regarding java and web
Banned

Posts: 923
Name: Geoff Vader
Location: In my dreams
Trades: 0
Sorry if this is incorrect, but it seems correct on the surface... you appear to have missed part of the tag out where the script begins...

<script \"text/javascript\"...

is what you put,

but surely it should say

<script language=\"text/javascript\"...

?

or "type" if not language. but basically you're missing the equals and the wotsit thingy that is either "language" or "type" in this instance... is my guess, anyway.

Probably just a careless error on your part, eh? Or maybe that makes no difference and it is permissable to write the script tag in the way you've done it - i haven't looked this up, I just made this guess from looking at your code.


this google search appears to corroborate my theory to some extent...
http://www.google.co.uk/search?hl=en...G=Search&meta=

and suggests that "type" is the (more?) correct wotsit to use for this job.

Last edited by witnesstheday; 02-18-2009 at 07:59 AM..
witnesstheday is offline
Reply With Quote
View Public Profile
 
Old 02-18-2009, 10:01 AM Re: need some help regarding java and web
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
actually, <script language="text/javascript"> would be incorrect, <script type="text/javascript"> would be correct. When the language attribute is used, it is just <script language="javascript"> The language attribute is being phased out though, in favor of type.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 02-18-2009, 03:04 PM Re: need some help regarding java and web
Banned

Posts: 923
Name: Geoff Vader
Location: In my dreams
Trades: 0
I had come to suspect this.
witnesstheday is offline
Reply With Quote
View Public Profile
 
Old 02-18-2009, 08:53 PM Re: need some help regarding java and web
Junior Talker

Posts: 2
Name: Mike
Location: Philippines
Trades: 0
hi guys thanks for the replies,

oops! sorry for the code. careless me..

well, even though i put it this way

buff.append("<script type='text/javascript'>callFunction();</script>");
buff.append("<script type=\"text/javascript\">callFunction();</script>");

or even this way

buff.append("<script>callFunction();</script>");

it still doesn't call the "callFunction" script and execute it.

so, anymore ideas guys?

thanks
Eagle-Man is offline
Reply With Quote
View Public Profile
 
Old 02-21-2009, 07:12 PM Re: need some help regarding java and web
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
javascript has to be triggered by an clientside event, your servlet pushing data onto the page that is already been processed by the browser isn't going to raise an event.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to need some help regarding java and web
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22924 seconds with 12 queries