Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Running Servlet

Reply
Thread Tools

Running Servlet

 
 
agapitolw@yahoo.es
Guest
Posts: n/a
 
      08-27-2007
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

 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      08-27-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Could you kindly explain how it is possible to run a servlet from
> javascript code ? For example , I have:
>
> <script language="JavaScript">


<script type="text/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
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
 
Reply With Quote
 
 
 
 
josh
Guest
Posts: n/a
 
      08-28-2007

> 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
on the Sun site:
>> A servlet can almost be thought of as an applet that runs on the server side--without a face.


but they are not, technically, the same.



 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening new child window - Running servlet (JSP and Servlet) agapitolw@yahoo.es Java 4 08-27-2007 12:57 PM
Offending class: javax/servlet/Servlet.class chamikara Java 1 06-19-2004 05:42 AM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM
Tomcat: POST from one servlet or internal class to another servlet Sean Clarke Java 1 01-07-2004 02:22 PM
how to get my servlet configuration before the servlet is initialised Andy Fish Java 4 12-17-2003 09:47 PM



Advertisments