I'm taking a class at DeAnza College, and the
instructor doens't have enough time to answer questions
and he knows virtually nothing about how to get
anything working on Linux, the only system where I have
regular access to J2EE to do my homework assignments.
I'm stuck, unable to invoke my sub-class of HttpServlet
by any reasonable means. Please see details here:
http://www.rawbw.com/~rem/ServletQuestion/question.html
By the way, Google Groups shows not a single message matching keywords
J2EE HttpServlet Linux in the past several months, and only about ten
or so messages ever. Am I the only person trying to use J2EE on Linux
currently/recently?
John Bailo - 11 May 2005 23:41 GMT
> I'm taking a class at DeAnza College, and the
> instructor doens't have enough time to answer questions
[quoted text clipped - 9 lines]
> or so messages ever. Am I the only person trying to use J2EE on Linux
> currently/recently?
OS shouldn't and doesn't matter with a java application server. For
example, I set up an AJAX client that connects to a simple J2EE servlet
on a Weblogic 8.1 server. There is a reference to a website from which
it came. You can install Tomcat and do the same thing. I'm surprised
you didn't look at the Tomcat documentation.
The code is at the bottom.
To make it run:
(1) Put it in the classes directory in \WEB-INF
(2) Edit the web.xml and add.
</servlet>
<servlet>
<servlet-name>HelloWWW</servlet-name>
<servlet-class>HelloWWW</servlet-class>
</servlet>
and
<servlet-mapping>
<servlet-name>HelloWWW</servlet-name>
<url-pattern>/www/HelloWWW</url-pattern>
</servlet-mapping>
I can then call this servlet with the url:
http://www.mywebserver.com/www/HelloWWW
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Simple servlet that generates HTML.
* Part of tutorial on servlets and JSP that appears at
* http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/
* 1999 Marty Hall; may be freely used or adapted.
*/
public class HelloWWW extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n" +
"<HTML>\n" +
"<HEAD><TITLE>Hello WWW</TITLE></HEAD>\n" +
"<BODY>\n" +
"<H1>Hello WWW</H1>\n" +
"</BODY></HTML>");
}
}
John Bailo - 12 May 2005 00:40 GMT
Oh, ps... I didn't realize my example is externally accessible ( i used
"myserver.com" as a pseudo-url ).
The real URL demostrating the result is:
http://training.vcrm2.com/broadbaseema/www/HelloWWW
>> I'm taking a class at DeAnza College, and the
>> instructor doens't have enough time to answer questions
[quoted text clipped - 66 lines]
> }
> }

Signature
Texeme Construct
http://texeme.com
Wendy Smoak - 12 May 2005 00:08 GMT
Robert Maas wrote:
> I'm stuck, unable to invoke my sub-class of HttpServlet
> by any reasonable means. Please see details here:
> http://www.rawbw.com/~rem/ServletQuestion/question.html
The reasonable means to invoke a Servlet is to visit (or forward or redirect
to) a URL that matches the pattern you have mapped to it in the deployment
descriptor (web.xml).
A URL including WEB-INF will never work-- the container is specifically
forbidden to serve things under WEB-INF (and anyway that isn't how you "run"
a Servlet.) Neither will forwarding to the Servlet .class file.
See if this helps:
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets9.html#70064
The fact that you're using Linux is irrelevant. The Servlet Specification
sets out 'the rules' that Servlet containers and developers must follow, no
matter what operating system they're working on.

Signature
Wendy S