Servlet.?

A friend is using some code and has imported javax.servlet.http. The code has many errors:

- javac -

SaveAsFilter.java:8: cannot find symbol

symbol: class Filter

class SaveAsFilter implements Filter{

^

SaveAsFilter.java:9: cannot find symbol

symbol : class FilterConfig

location: class javax.servlet.http.SaveAsFilter

FilterConfig fc;

^

SaveAsFilter.java:10: cannot find symbol

symbol : class ServletRequest

location: class javax.servlet.http.SaveAsFilter

public void doFilter(final ServletRequest request,

^

SaveAsFilter.java:11: cannot find symbol

symbol : class ServletResponse

location: class javax.servlet.http.SaveAsFilter

final ServletResponse

^

SaveAsFilter.java:13: cannot find symbol

symbol : class FilterChain

location: class javax.servlet.http.SaveAsFilter

FilterChain chain)

^

SaveAsFilter.java:14: cannot find symbol

symbol : class ServletException

location: package javax.servlet

throws java.io.IOException, javax.servlet.ServletException {

^

SaveAsFilter.java:28: cannot find symbol

symbol : class FilterConfig

location: class javax.servlet.http.SaveAsFilter

public void init(FilterConfig fc) throws ServletException {

^

SaveAsFilter.java:28: cannot find symbol

symbol : class ServletException

location: class javax.servlet.http.SaveAsFilter

public void init(FilterConfig fc) throws ServletException {

^

SaveAsFilter.java:18: cannot find symbol

symbol : class HttpServletResponse

location: class javax.servlet.http.SaveAsFilter

HttpServletResponse httpResponse = (HttpServletResponse) response;

^

SaveAsFilter.java:18: cannot find symbol

symbol : class HttpServletResponse

location: class javax.servlet.http.SaveAsFilter

HttpServletResponse httpResponse = (HttpServletResponse) response;

^

10 errors

Output completed (1 sec consumed) - Normal Termination

Can anyone help with these errors.

here is the code.

package javax.servlet.http;

import java.util.*;

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public

class SaveAsFilter implements Filter{

FilterConfig fc;

public void doFilter(final ServletRequest request,

final ServletResponse

response,

FilterChain chain)

throws java.io.IOException, javax.servlet.ServletException {

//Beginning PreProcessing

if (request.getParameter("saveas")!=null)

{

HttpServletResponse httpResponse = (HttpServletResponse) response;

httpResponse.setHeader("Content-disposition" , "attachment; filename="

+ request.getParameter("saveas")

);

}

//End PreProcessing

chain.doFilter(request,response);

//Beginning PostProcessing

//End PostProcessing

}

public void init(FilterConfig fc) throws ServletException {

this.fc = fc;

}

public void destroy() {

fc = null;

}

}

[3162 byte] By [Mr_Mojo_Risina] at [2007-11-27 5:07:52]
# 1
this can't be right:package javax.servlet.http;
corlettka at 2007-7-12 10:27:08 > top of Java-index,Java Essentials,Java Programming...
# 2

the classes used are part of the java enterprise edition. There are two options to fix these errors:

- if you have J2EE installed (or are using an application server like JBoss), you need to add j2ee.jar to your classpath

- if you are using Tomcat, you need to add common/lib/servlet-api.jar to your classpath

gimbal2a at 2007-7-12 10:27:09 > top of Java-index,Java Essentials,Java Programming...
# 3
> There are two options to fix these errors:You can copy the package containing the servlet API to your build environment (whether you are developping for JBoss or Tomcat or whatever) and include in the compilation class path.
BIJ001a at 2007-7-12 10:27:09 > top of Java-index,Java Essentials,Java Programming...