Javascript In A Servlet??

S

Steve Burrus

Can anyone please tell me if some JavaScript is allowed in the html
content of a Java Servlet or not???!! I have tried to get an alert
dialogue box to pop up when the servlet is first loaded into my browser,
but have failed to do so!!
 
C

Christophe Vanfleteren

Steve said:
Can anyone please tell me if some JavaScript is allowed in the html
content of a Java Servlet or not???!! I have tried to get an alert
dialogue box to pop up when the servlet is first loaded into my browser,
but have failed to do so!!

Show us your code. You can generate any kind of content with a Servlet, be
it an image, HTML,XML, HTML with javascript, ...

If it doesn't work, the problem is probably your content, not the servlet
itself.
 
S

Sudsy

Steve said:
Can anyone please tell me if some JavaScript is allowed in the html
content of a Java Servlet or not???!! I have tried to get an alert
dialogue box to pop up when the servlet is first loaded into my browser,
but have failed to do so!!

Just for clarification, a servlet is NEVER loaded into your browser.
Think about it: a servlet runs on the server side!
Perhaps you could explain what you're trying to do, what you've
already attempted, and what you expect to happen?
 
A

Andrew Thompson

...I have tried to get an alert
dialogue box to pop up when the servlet is first loaded into my browser,
but have failed to do so!!

Does the JS work from HTML, Steve?

Often the problem is the JS, beyond anything else.

Of course, the best way to investigate that
is to take it up with the Gurus of JavaScript.
You can get a good link from here..
<http://www.physci.org/codes/javafaq.jsp#js>
 
L

Liz

Steve Burrus said:
Can anyone please tell me if some JavaScript is allowed in the html
content of a Java Servlet or not???!! I have tried to get an alert
dialogue box to pop up when the servlet is first loaded into my browser,
but have failed to do so!!

The output of the servlet is just text sent to the browser
so you can spit out anything. The browser would have to
have javascript enabled for it to work.
 
S

Steve Burrus

"Sudsy", I am just simply trying/attempting to write a simple
"HelloServlet.java" or maybe a "WelcomeServlet.java"-if you know what
that is!

I am using a series of "out.println()" methods within the
"<html><body>" tags of the servlet! I would like to be able to see a
JavaScript "alert" dialog box pop up when the html page is first loaded
into my personal web browser!! (Wait a minute, just now I thought of a
possible solution for my problem, and that is to put the javascript that
I wanna work with into the <html> file that is supposed to work with the
servlet.) Am I am on the right track with this kind of thinking or
not??? And finally, how much experience do you have with working with
servlets anyway? And the "companion" question to that, what are the
app.servers that you have worked with??

****************************************************************************
 
S

Steve Burrus

Okay Christophe, here is my servlet code, and I must tell you it just
now compiled for me successfully! :

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class WelcomeServlet extends HttpServlet {

// process "get" requests from clients
protected void doGet( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException
{
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();

// send XHTML page to client

// start XHTML document
out.println( "<?xml version = \"1.0\"?>" );

out.println( "<!DOCTYPE html PUBLIC \"-//W3C//DTD " +
"XHTML 1.0 Strict//EN\" \"http://www.w3.org" +
"/TR/xhtml1/DTD/xhtml1-strict.dtd\">" );

out.println(
"<html xmlns = \"http://www.w3.org/1999/xhtml\">" );

// head section of document
out.println( "<head><JavaScript version='1.3'>" );
out.println( "<title>A Simple Servlet Example</title>" );
out.println( "</head></javascript>" );

// body section of document
out.println( "<body onLoad=alert('I am FLYING HIGH with this Servlet')>" *
out.println( "<h1>Welcome to Servlets!</h1>" );
out.println( "</body>" );

// end XHTML document
out.println( "</html>" );
out.close(); // close stream to complete the page
}
}

* Just to note that I have all of the content of that alert box on ONE
line in my code, "text wrap" doesn't work too well in my email
composition window.
 
A

Andrew Thompson

// head section of document

This is a badly malformed head
out.println( "<head><JavaScript version='1.3'>" );

out.println( "<head>" );
out.println( "<script language='javascript' type='text/javascript'>" );
out.println( "<!-- //JavaScript goes here! -->" );
out.println( "<!-- //important to end the script -->" );
out.println( said:
out.println( "<title>A Simple Servlet Example</title>" );
out.println( "</head></javascript>" );

out.println( "</head>" );

HTH
 
S

Steve Burrus

Okay Andrew, I tried out your code which u supplied me with, but alas, I
still didn't get my desired alert dialogue box to pop up at all!!! Here
is the code which I had (which again compiled okay!) :


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class WelcomeServlet extends HttpServlet {

// process "get" requests from clients
protected void doGet( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException
{
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();

// send XHTML page to client

// start XHTML document
out.println( "<?xml version = \"1.0\"?>" );

out.println( "<!DOCTYPE html PUBLIC \"-//W3C//DTD " +
"XHTML 1.0 Strict//EN\" \"http://www.w3.org" +
"/TR/xhtml1/DTD/xhtml1-strict.dtd\">" );

out.println(
"<html xmlns = \"http://www.w3.org/1999/xhtml\">" );

// head section of document

out.println( "<head>" );
out.println( "<script language='javascript' type='text/javascript'>" );
out.println("alert('I am FLYING HIGH\n\n with this Servlet!!')");
out.println( "</script>" );
out.println( "</head>" );
// body section of document
out.println( "<body>");
out.println( "<h1>Welcome to Servlets!</h1>" );
out.println( "</body>" );

// end XHTML document
out.println( "</html>" );
out.close(); // close stream to complete the page
}
}
 
S

Sudsy

Steve said:
"Sudsy", I am just simply trying/attempting to write a simple
"HelloServlet.java" or maybe a "WelcomeServlet.java"-if you know what
that is!

I am using a series of "out.println()" methods within the
"<html><body>" tags of the servlet! I would like to be able to see a
JavaScript "alert" dialog box pop up when the html page is first loaded
into my personal web browser!! (Wait a minute, just now I thought of a
possible solution for my problem, and that is to put the javascript that
I wanna work with into the <html> file that is supposed to work with the
servlet.) Am I am on the right track with this kind of thinking or
not??? And finally, how much experience do you have with working with
servlets anyway? And the "companion" question to that, what are the
app.servers that you have worked with??

Okay, so I don't usually reply to flame-bait but I'll make an
exception this time. App Servers: Oracle 9i, BEA WebLogic and
IBM WebSphere. Servlet experience: more than 5 years, developing
on various platforms, deploying to others. Check out some of my
articles here:
<http://www.sudsy.net>
Click on the "Technology" button and take away from it what
you will...
And if you'll read and consider what other helpful people have
posted, you might comprehend why I posted as I did. Content
type is crucial to interpretation of the body and any embedded
content (such as images et al).
Fair enough?
 
S

Steve Burrus

"sudsy", I am just a little bit curious about what you mean by
"flame-bait" from me!! Anyway, you say that u have worked with the
"Websphere" and the "WebLogic" servers respectively. I have recently
gotten/obtained both of those application servers again, since I have
had them in the past, but alas, I haven't really ever gotten a "handle"
on just how exactly one goes about starting to use them for J2EE
development!!

Can you please, please tell me FINALLY how you go about using them for
deploying such components of the j2ee as servlets, jsp's, and even ejb's???!

************************************************************************************************
 
C

Christophe Vanfleteren

Steve said:
"sudsy", I am just a little bit curious about what you mean by
"flame-bait" from me!! Anyway, you say that u have worked with the
"Websphere" and the "WebLogic" servers respectively. I have recently
gotten/obtained both of those application servers again, since I have
had them in the past, but alas, I haven't really ever gotten a "handle"
on just how exactly one goes about starting to use them for J2EE
development!!

Can you please, please tell me FINALLY how you go about using them for
deploying such components of the j2ee as servlets, jsp's, and even
ejb's???!

How about you read the docs of your specific server, and then ask a question
when you have a specific problem. One can't just answer your question here,
since the deployment process is partly different for all the appservers.
 
A

Andrew Thompson

On Fri, 07 May 2004 23:06:12 GMT, Steve Burrus wrote:

[ Comments all the way to bottom ]
Okay Andrew,

(sighs) OK Steve.. I will give you one last chance.

Please stop top-posting.
...I tried out your code which u supplied me with, but alas, I
still didn't get my desired alert dialogue box to pop up at all!!! Here
is the code which I had (which again compiled okay!) :

It is important realise this Steve.

Java code that compiles does *not* produce
valid HTML/XHTML/JavaScript..

Whether the latter is 'valid and well formed'
an entirely separate matter.

The stuff you produced, was not valid if it
had been typed in notepad. So writing it
using Java is not going to fix it.

[[ If you want a JS alert, it is best to
do it all in HTML first. ]]

This is something that a lot of Java
programmers get wrong.

That is how I develop my sites - I work out
the HTML/JS/applet calls in a web page ..THEN,
once it is working and valid, I write more
advanced page(s) generated by the server.

If I mess with 3 technologies at once
(e.g. Java/HTML/JS) I stuff it up.
import javax.servlet.*;
import javax.servlet.http.*;

So I shouldn't have to be looking at this crap.

This should have _nothing_ to do with servlets yet.

Which ultimately means you should be
asking THIS question on...
<http://google.com/groups?group=comp.lang.javascript>

As it happens I need to pop in there myself
to get some help with a URL/parameters problem,
so I might be seeing you there.

Now, I considered sitting down and writing
a simple HTML/JS pop-up example for youm
but neither do I have time, nor is it fair to
the other members if this Java group.

What I recommend is. Mosey on over to c.l.js
and you will have working HTML/JS in 20 minutes.
Then write that back into your servlet.

HTH
 
R

Roedy Green

Please stop top-posting.
It does not matter for God's sake. You have no right to impose how
people speak any more that what they speak.

If you want to natter about something, what does matter is twits who
quote pages of text irrelevant to their posts.
 
A

Andrew Thompson

It does not matter for God's sake.

It does to me. (People are different)
..You have no right to impose how
people speak any more that what they speak.

Which is why I said 'please'.

The implication was 'stop top-posting or
_I_ will no longer respond to your posts'.
No more, no less.
If you want to natter about something, what does matter is twits who
quote pages of text irrelevant to their posts.

I agree with you. I also comment on poor trimming.
 
S

Sudsy

Steve said:
"sudsy", I am just a little bit curious about what you mean by
"flame-bait" from me!! Anyway, you say that u have worked with the
"Websphere" and the "WebLogic" servers respectively. I have recently
gotten/obtained both of those application servers again, since I have
had them in the past, but alas, I haven't really ever gotten a "handle"
on just how exactly one goes about starting to use them for J2EE
development!!

Can you please, please tell me FINALLY how you go about using them for
deploying such components of the j2ee as servlets, jsp's, and even
ejb's???!

Unfortunately, there's not a single definitive source. I've purchased
numerous books on the separate elements (EJBs, JSPs, etc.) and worked
through the provided examples. When it comes to deployment, that's
very much a detail of the particular implementation. WebSphere, for
example, uses a script called assembly.sh. Once I learned the format
of the deployment files (ibm-ejb-jar-bnd.xmi and ibm-ejb-jar-ext.xmi)
then I was able to generate them automatically in my build script. I
also generate weblogic-ejb-jar.xml for deployment to WebLogic.
But then you have to know the format of ears and wars as well so that
you can put the files in the appropriate locations...
There's a heck of a lot to learn and I don't know of any shortcuts.
 
S

Steve Burrus

Please forgive my dumb ignorance, but what the hell is "Top Posting"
anyway??!! Is it something that I shouldn't do??!

************************************************************************************************
 
A

Andrew Thompson

Please forgive my dumb ignorance, but what the hell is "Top Posting"
anyway??!!

Steve, do you understand th concept of links?

They are those long blue things in
your newsreader. They turn a much warmer
purply red once you click on them, but I
expect all yours are still that cold blue,
'cos you do not seem to follow the links
I give you.

They are wonderful things, these links,
they attach to information. I have for
example, given you the link to the
information on top-posting before..

Here it is again.
..Is it something that I shouldn't do??!

What you should or shouldn't do is up to
you Steve, and whether other people in the
forum care any which way is up to them.

You can choose to continue acting as you please,
and the others in the forum can choose to help you,
_or_ they can choose to ignore you ..or 'plonk' you,
which is far worse.
 
S

Sudsy

Steve said:
Please forgive my dumb ignorance, but what the hell is "Top Posting"
anyway??!! Is it something that I shouldn't do??!

Top posting is what you've been doing. It's where you reply to a post
and put new content at the top. Note that I'm doing the opposite,
namely leaving the essence of your post at the top of the reply and
adding my comments at the bottom. (I'm also trimming extraneous
content.)
It's just the standard way things are done on usenet groups. You want
to leave just enough content so that people can follow the thread of
conversation. If you go back and read Andrew's post you'll notice
that he included a link (most newsreaders will make it "clickable")
to a document describing what is called "netiquette".
Andrew has some other good ideas as well, providing links to help
you create a "short, self-contained, compilable example". Having one
can considerably improve your chances of receiving helpful responses.
If one can "cut" the code from the post and "paste" into a local file
then it's easier to compile and test.
You'll get used to it in time. People are actually trying to help you
out here.
 
R

Roedy Green

Please forgive my dumb ignorance, but what the hell is "Top Posting"
anyway??!! Is it something that I shouldn't do??!

It just means putting your response at the top and the stuff the
other guy said that everyone has already read already underneath.

It irritates some people. They like reading the same old stuff over
and over and paging down 10 pages to get to where you say,
"I agree".

I consider it preferable. However, most people don't. I have
proposed technology to deal with the problem but no one is interested.

See http://mindprod.com/projmailreadernewsreader.html

In the meantime, to keep Andrew happy, put your comment under the text
it refers to, and to keep me happy, don't quote anything unless is
very relevant. If the user wants to refer back, let him hit up arrow.
You need just enough recall the gist of the other's argument.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top