Question of the Week No. 66
Researched by Sara Louis
Question of the Week presents answers to key questions posed by the
developer community. The intent is to pass this important, but not
always easy-to-find, information on to JavaTM
Developer ConnectionSM (JDC) members. The
questions are selected from the JDC Forums
generally because: they are frequently asked, they are significant or timely, or
the answers are not easily accessible.
Topic:
Servlet Configuration Questions
Questions:
Servlet newbie looking for setup help (WinNT,JDKTM 1.1.8,JSWDKTM 1.0.1). I have
two questions:
1. How do the servlet docBase and mapping properties work with the form
ACTION tag to resolve the servlet's location?
The examples run fine, and if I create a servlet and put
it into the examples directory with the other servlets,
that runs fine, too. What I'm trying to do is something
similar to the way CGI works. I want to place my
servlets in a particular directory, and have them
accessible via an action tag like ACTION=/old?u=http%3A%2F%2Fdeveloper.java.sun.com%2Fdeveloper%2Fqow%2Farchive%2F66%2F%26quot%3B%2Fservlet%2FmyServlet%26quot&y=1999
or at the worst ACTION=/old?u=http%3A%2F%2Fdeveloper.java.sun.com%2Fdeveloper%2Fqow%2Farchive%2F66%2F%26quot%3Bhttp%3A%2FmyServer%3A8080%2Fservlet%2FmyServlet%26quot%3B.&y=1999
If it makes a difference, I'm currently only
using servlets to process form data, NOT to generate the
form HTML like the examples do.
2.
We run behind a firewall. Is there any way to have the servlets run without
opening another port (such as 8080) to the world?
Answer:
1. If I understand your question properly, when you start servletrunner, you use
the -d flag to state where the servlet lives
and the -r flag to state where the document root is (that is, where to look for
any files such as HTML templates) An example:
bin\servletrunner -d examples\ -r examples\templates\
So, in your example, servletrunner if started as above would look for file
examples\myServlet.class.
2. If using servlets for real, you would not use servletrunner. You would use
something like WebSphere or Jrun that attaches
itself to a WebServer. Requests come through on port 80 like any other HTTP
requests but the Web Server identifies these as
servlet requests and passes them to the Application Server to execute the
servlet. The servlet builds the response and sends it
to App Server which sends to Web Server and responds to Browser on port 80
again.
If you really need to use servletrunner, I know of no other way than to open
know of no other way than to open another port.
Many thanks to JDC member astorer for contributing
to this answer.
Sun Dec 05 00:27:51 PST 1999
[Member not logged in]
I get an exception NoClassDefFoundError when I try to run a java
application over the network on a Windows 98 machine. But the
same application runs perfectly over the network on a Windows NT
workstation. Classpath for both 98 and NT workstation are the same.
Any clues?
email to mehul_mehta@yahoo.com
Thanks
- Mehul Mehta
Mon Dec 06 01:42:11 PST 1999
[Member not logged in]
I have been wondering how could solve my problem before I read this anwser. I did exactly
as the answer suggested to run "servletrun -d myServer". It was fine to get file running in
myServer/myClass.class. The problem was the server could not find class files in a
sub-directory of myServer. For example, if a file is in /myServer/subDir/myClass.class
when it run http://homeHost:8080/servlet/myServer/subDir/myClass, the server indicated an
error "Can't find subDir". Am I missing something here or simple the JSDK cannot run multiple
directories under myServer?
(BTW, I run APACHE web server, but I don't think it is related)
Thank you.
Mon Dec 06 05:00:06 PST 1999
[Member not logged in]
the above comments seem applicable to the servletrunner not jswdk1.01
1) JavaTM Server Web Development Kit(JSWDK 1.01 implements web applications as defined in the servlet 2.2 API.
"A web application is a collection of resources that is mapped to a specific Uniform Resource
Identifier (URI) prefix. These resources may include JSP pages,
Servlets, HTML files, and images."
This is much more flexible, but also more complicated than the older system where all servlets
went in the servlets directory.
See the FAQ.html included with JSWDK1.01 for information on setting up web applications.
See the Java Servlet API Specification 2.2 for more info.
2) The JSWDK is configured using the file webserver.xml (in the root directory)
This file is self documenting. to change the port number change the line (near the bottom of the
file)
from
port NMTOKEN "8080"
to
port NMTOKEN "80"
In my experience the JSWDK is very robust.
Mon Dec 06 06:51:35 PST 1999
[Member not logged in]
I downloaded the JSWDK so I could write and test servlets but it doesn't contain the jsdk2.0 or
the jsdk.jar, Don't I need these thing to wwrite and test servlets? And where do I get them and
how do I configure them?
Thank you for your time
"THE INFORMATION PROVIDED IN THE JAVA DEVELOPER'S CONNECTION IS PROVIDED "AS IS" WITHOUT
WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR, AND NON-INFRINGEMENT.
THIS INFORMATION IS PROVIDED AT NO CHARGE. BY USE OF THE INFORMATION YOU AGREE THAT
NEITHER SUN MICROSYSTEMS, INC. NOR ITS LICENSORS WILL BE LIABLE FOR ANY DAMAGES
WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS
PROFITS OR SPECIAL DAMAGES, EVEN IF SUN OR ITS LICENSORS HAVE BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF
LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT
APPLY.
THIS INFORMATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS.
CHANGES ARE PERIODICALLY ADDED TO THE INFORMATION HEREIN. SUN MICROSYSTEMS, INC. MAY
MAKE IMPROVEMENTS AND OTHER CHANGES IN THE PRODUCTS AND THE PROGRAMS DESCRIBED
HEREIN AT ANY TIME WITHOUT NOTICE."