Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A "Hello World" servlet question

Status
Not open for further replies.

Kruzer

Programmer
Jun 16, 2000
117
US
here's the code - having problems running the file

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.PrintWriter;
import java.io.IOException;

public class SampleServlet extends HttpServlet {

static int numRequests = 0;

public void init(ServletConfig config) throws ServletException {
super.init(config);
}

public void services(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");

PrintWriter out = response.getWriter();
out.println(&quot;<HTML>&quot;);
out.println(&quot;<HEAD><TITLE>Sample Sevlet</TITLE>

<script LANGUAGE=JAVASCRIPT>

<!--

function _CF_checkgetquestion(_CF_this)

{

return true;

}

//-->
</script>


<script LANGUAGE=JAVASCRIPT>

<!--

function _CF_checkgetquestion(_CF_this)

{

return true;

}


//-->

</script>

</HEAD>&quot;);
out.println(&quot;<BODY>&quot;);
out.println(&quot;<H1>Hello world</H1>&quot;);
numRequests++;
out.println(&quot;<p>This servlet has been requested &quot; + numRequests + &quot; times.&quot;);
out.close();
}
public String getServletInfo()
{
return &quot;Sample Servlet version 1.0&quot;;
}
public void destroy()
{
}
}

The problems I'm having are - I have the servlet class installed and I can see the class in my class viewing tree???

SampleServlet.java:10: Class ServletConfig not found.

public void init(ServletConfig config) throws ServletException {


error: File D:\jdk1.2.2\src\javax\servlet\ServletException.class does not contain type ServletException as expected, but class javax.servlet.ServletException. Please remove the file, or make sure it appears in the correct subdirectory of the class path.

SampleServlet.java:10: Class ServletException not found in throws.

public void init(ServletConfig config) throws ServletException {

SampleServlet.java:11: Class ServletConfig not found in void init(ServletConfig).

super.init(config);

SampleServlet.java:14: Class ServletException not found in throws.

public void services(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException [sig]<p>Dano<br><a href=mailto:dskryzer@hotmail.com>dskryzer@hotmail.com</a><br><a href= </a><br>What's your major malfunction[/sig]
 
>The problems I'm having are - I have the servlet class installed and I can see the class in my class viewing tree???



Do you have any kind of servlet-engine running? It seems like you are trying to run the servlet 'stand-alone', which is not possible. You'll need some kind of container for your servlet, like Tomcat ( or LiteWebserver (
</MrJ>
 
Usually you install it and from there you assign a browsing alias to the servlet. Java web servers usually require that you browse on a particular port and a bunch of other stuff. See the docs.

You can also try JRun3 from allaire. I've been using it lately and have found it easier to work with at least than javawebserver2.0 though I've never tried LiteWebServer. [sig]<p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br> [/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top