On Thu, Jun 4, 2009 at 11:41 AM, chihi asma <[email protected]> wrote:
>
> hi,
> i am trying to implement 2 servlets in a bundle using the httpservice. there
> is the code :
> the first servlet:
> [...]
>
> the second servlet:
....
Hi,
the problem **might** be in the
req.getRequestDispatcher("/servlet2")
The javax.servlet specification supported by Apache Felix HTTP service
is 2.1. It's a quite old spec, and apparently there is no
ServletRequest.getRequestDispatcher method, as you can see comparing
http://java.sun.com/products/servlet/2.1/api/javax.servlet.ServletRequest.html#_top_
with
http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html
To confirm that it is the problem, can you check if the following
example is working?
(The FirstServlet is slightly different from your:)
----------------------------
public class FirstServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse
res)
throws ServletException, IOException {
req.setAttribute("name", "sana ");
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/servlet2");
dispatcher.forward(req,res);
}
}
----------------------------
public class SecondServlet extends HttpServlet
{
protected void doGet(HttpServletRequest req, HttpServletResponse
res) throws ServletException, IOException
{
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
out.println(req.getAttribute("name"));
}
}
----------------------------
public class Activator implements BundleActivator{
public void start(BundleContext context) throws Exception {
ServiceReference sr =
context.getServiceReference(HttpService.class.getName());
if(sr != null) {
HttpService http = (HttpService)context.getService(sr);
if(http != null) {
http.registerServlet("/servlet1", new FirstServlet(),
null, null);
http.registerServlet("/servlet2", new SecondServlet(),
null, null);
}
}
}
public void stop(BundleContext context) throws Exception {
}
}
--
Filippo Diotalevi
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]