• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help in compiling Servlet program

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody
I am using tomcat3.1 in windows98 machine
it works fine
But i was not able to compile these program
ServletUtil.java
package test ;
public class ServletUtil {
public static final String DOCTYPE = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
public static String headWithTitle(String title){
return (DOCTYPE + "\n" +
"<HTML>\n" +
"<HEAD><TITLE>" + title + "</TITLE></HEAD>");
}

};
Hello.java
package test;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Hello extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException , IOException {

res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println(ServletUtil.headWithTitle(" Hello WWW ") + "\n" +
"<BODY>\n" +
"<H1> Hello WWW -- BY Siva </H1>\n" +
"</BODY></HTML>");
}
};
These two file are present in the c:\tomcat\source\test
I am generating the class files in
c:\tomcat\webapps...\classes\test
when i compiled ServletUtil it did well , but when i compiled Hello.java the compiler was sayin that it can't undestand
ServletUtil.headWithTitle(" Hello wwww");
can u pls help me in this
Thank you
rgds
Siva
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see a couple of typos and I dont know if that is the problem but the Hello class has a ; after the last }
could that be it?
paul
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi! SivaKumar,
I do not believe that the compiler will complain about the ";" at the end.
It generally shouldn't matter but you could try doing this:

String title = ServletUtil.headWithTitle(" Hello WWW ");
out.println(title+........whatever your code );
Preethi

Originally posted by Sivakumar Jagadeesan:
Hi everybody
I am using tomcat3.1 in windows98 machine
it works fine
But i was not able to compile these program
ServletUtil.java
package test ;
public class ServletUtil {
public static final String DOCTYPE = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
public static String headWithTitle(String title){
return (DOCTYPE + "\n" +
"<HTML>\n" +
"<HEAD><TITLE>" + title + "</TITLE></HEAD>");
}

};
Hello.java
package test;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Hello extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException , IOException {

res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println(ServletUtil.headWithTitle(" Hello WWW ") + "\n" +
"<BODY>\n" +
"<H1> Hello WWW -- BY Siva </H1>\n" +
"</BODY></HTML>");
}
};
These two file are present in the c:\tomcat\source\test
I am generating the class files in
c:\tomcat\webapps...\classes\test
when i compiled ServletUtil it did well , but when i compiled Hello.java the compiler was sayin that it can't undestand
ServletUtil.headWithTitle(" Hello wwww");
can u pls help me in this
Thank you
rgds
Siva


 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I using jdk1.3 & tomcat 3.1.
I can start and stop the tomcat server using port 127.0.0.1
I can compile and runing the follong simple program with the enclosed setting. Hope this helps...
Do you have the follow env var...
PATH=c:\jdk1.3\bin;c:\tomcat\bin
JAVA_HOME=c:\jdk1.3
TOMCAT_HOME=c:\tomcat
CLASSPATH=,;c:\tomcat\lib\servlet.jar
...................
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Very simplistic servlet that generates plain text.
* <P>
* Taken from Core Servlets and JavaServer Pages
* from Prentice Hall and Sun Microsystems Press,
* http://www.coreservlets.com/.
* � 2000 Marty Hall; may be freely used or adapted.
*/
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
}
}

[This message has been edited by Monty Ireland (edited November 16, 2000).]
 
Siva Jagadeesan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody :
I finally made my programs work . I made some mistake in setting up my classpath
Thank you Preethi Chaloori and Monty Ireland
rgds
Siva
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic