I'm reading the book JAVA SERVER PROGRAMMING form WROX.
 
I have created my first servlet HelloWorld.java
 
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
 
public class HelloWorld extends HttpServlet
{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException   
 {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();       
       out.println("<html>");
        out.println("<body>");       
        out.println("<head>");
        out.println("<title>Hello World!</title>");
        out.println("</head>");       
          out.println("<body>");
        out.println("<h1>Hello World!</h1>");       
      out.println("</body>");
        out.println("</html>");   
 
 }
}

which works fine

Then I created a public class named HTML which is a HTML generator

package javacode.util;

public class HTML
{
 public static final int NORMAL = 0;
 public static final int HEADING = 1;
 public static final int LINE =  2;

 public StringBuffer buffer;
 public HTML (String title)
 {
 buffer=new StringBuffer(4096);
 this.buffer.append("<HTML><HEAD><TITLE>");
 this.buffer.append(title);
 this.buffer.append("</TITLE></HEAD><BODY>");
 }

 public void add(int style, String text, boolean linebreak)
 {
 switch(style)
 {
 case NORMAL:
  this.buffer.append(text);
  break;
 case HEADING:
     this.buffer.append("<H1>");
  this.buffer.append(text);
     this.buffer.append("</H1>");
 case LINE:
  this.buffer.append("<HR>");
  break;
 default:
  break;
 }
 if(linebreak)
 {
 buffer.append("<BR>");
 }
}

public String getPage()
{
 this.buffer.append("</BODY></HTML>");
 return this.buffer.toString();
}
}

How can I use this class in other servlets?

I tried to make it jar file and import it in another servlet and when I deployed it I got the following message:


java.lang.NoClassDefFoundError: javacode/util/HTML

 

 

Reply via email to