Hello All,
I am fairly new to servlet programming, and am
having problems sharing data between servlets. The setAttribute() and
getAttribute() methods in the API 2.1seem to be the best way to do this but I
can not make the setAttribute() method work at all...
The following simple servlet code demonstrates my
problem. It will not work for me using using the JavaWebServer1.1.3.
unless the setAttribte() line is removed. Can some one enlighten me as to
why...?
Dan.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class TestServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException{
ServletContext context = config.getServletContext();
// The following line of code does not seem to work.
context.setAttribute("text", (Object) "hello" );
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
res.setHeader("pragma", "no-cache");
PrintWriter out = res.getWriter();
out.print("<html><body><h2>Report From Test Servlet</h2>");
out.print("<p>Servlet Loaded Ok</p></body></html>");
out.close();
}
}
