Question about invoking HttpServlet on Linux, by URL or via JSP

  • Thread starter Robert Maas, see http://tinyurl.com/uh3t
  • Start date
R

Robert Maas, see http://tinyurl.com/uh3t

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?
 
J

John Bailo

Robert said:
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?

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>");
}
}
 
W

Wendy Smoak

Robert said:
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.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top