status 500 error to call a servlet from a JSP page


General J2EE: status 500 error to call a servlet from a JSP page

  1. I tried to call servlet from a JSP page, but it has the following status 500 runtime error:

    '.' expected
    [javac] import GenerateHTML ;

    <%@page import = "GenerateHTML " %>

    GenerateHTML obj = new GenerateHTML ();
    obj.service(request, response);


    public class GenerateHTML extends HttpServlet
    public void service(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException

    any ideas??
  2. The import might expect a . in the import statement, since you usually put your java classes in packages. Of course, you can put it in the default package as well and this should be supported, but it obviously isn't.

    Anyway, I think you're violating the servlet's lifecycle by instantiating it yourself. You should let the servlet container do that. Just define your servlet in web.xml, map it to a request URI, say /GenerateHTML and then use

    <jsp:include page="/GenerateHTML" flush="true"/>

    to call the servlet.

  3. ...which is criticized correctly by the javac compiler.