Running Servlet

A

agapitolw

Dear Newsgroup

Could you kindly explain how it is possible to run a servlet from
javascript code ? For example , I have:

<script language="JavaScript">
function open_a_window(){
childwin = window.open("showdata.jsp","dataname",
"height=300,width=100");
</script>

that opens a jsp page called showdata. However, I would like to run a
servlet that extracts data from database and forwards the results to
be displayed in showdata.jsp.

Thank you
 
T

Thomas 'PointedEars' Lahn

Could you kindly explain how it is possible to run a servlet from
javascript code ? For example , I have:

<script language="JavaScript">

function open_a_window(){
childwin = window.open("showdata.jsp","dataname",
"height=300,width=100");

For accessibility, "resizeable,scrollbars" is mandatory.
</script>

that opens a jsp page called showdata. However, I would like to run a
servlet that extracts data from database and forwards the results to
be displayed in showdata.jsp.

JSPs are *JavaServer* Pages, and Java programming is off-topic here.

ISTM your problem is that you have not understood the client-server
architecture of the Web yet. What happens is:

1. The client (here: browser) accesses foo.jsp on the server through
HTTP(S).
2. The Web server (e.g. Apache) has .jsp resources associated with the
server-side Java engine. It calls Java, passing the .jsp resource.
3. Java executes the .jsp resource, and generates a markup document
from it (e.g. HTML).
4. The server serves that document to the browser, which displays it.
5. The markup document may also contain client-side J(ava)Script code,
which the browser has associated with the client-side script engine.
The browser passes that code to the client-side script engine.
6. The client-side script engine executes that script code.
7. The script code code may (but does not have to) trigger a request
to the server (as your window.open() call does), and everything
starts all over again.

Now you want the client-side script engine to tell the server that it should
run a servlet (server-side applet). But that script engine does not even
"know" that the code it is executing was generated by the server; it merely
executed some code that the browser passed to it.

The only chance is that the script engine tells the browser to make a
request to the server, that makes the server call Java, that executes Java
code that accesses the database to generate from the retrieved data another
resource, that is then served by the server to the browser.

IOW: You have a Java problem, not a JavaScript problem. Post to
comp.lang.java.databases instead.

(That said, there is also server-side J[ava]Script, but that does not apply
here.)


HTH

PointedEars
 
J

josh

3. Java executes the .jsp resource, and generates a markup document
from it (e.g. HTML).

before generating an HTML file it makes a .java file that contains
the .jsp page
code (converts in a servlet) than that file is compiled to a .class
file and then it has
send to the client
run a servlet (server-side applet).

a servlet is not a server-side applet. They are different things! an
applet
executes in a client host while a servlet in a server host. I think
that is not
correct to say server-side applet but may be should be better to say
as described

but they are not, technically, the same.
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top