Announcement Announcement Module
No announcement yet.
How to setup Sesrvlet or Controller handling iframe request. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to setup Sesrvlet or Controller handling iframe request.


    I have written a Servlet to handle iframe request, but it shown the following error:

    HTTP Status 404 - /ForestsurfClient-web/product-photo-gallery.jsp

    type Status report

    message /ForestsurfClient-web/product-photo-gallery.jsp

    description The requested resource (/ForestsurfClient-web/product-photo-gallery.jsp) is not available.
    Here is my web.xml file:

    <servlet-class>ForestsurfClient.controller.PhotoGalleryServ let</servlet-class>
    Servlet class:

    public class PhotoGalleryServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private static final Logger logger = Logger.getLogger(PhotoGalleryServlet.class);

    ProductImageService productImageService = new ProductImageServiceImpl();
    // // Statics ------------------------------------------------------------------------------------
    // private static ImageDAO imageDAO = DAOFactory.getImageDAO();

    // Actions ------------------------------------------------------------------------------------

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    logger.debug("===============PhotoGalleryServlet<= ===========");
    // Get ID from request.
    String productId = request.getParameter("productId");

    logger.debug("==============PhotoGalleryServlet, productId:"+productId);
    // Check if ID is supplied to the request.
    if (productId == null) {
    // Do your thing if the ID is not supplied to the request.
    // Throw an exception, or send 404, or show default/warning image, or just ignore it.
    response.sendError(HttpServletResponse.SC_NOT_FOUN D); // 404.

    if (StringUtils.isEmpty(productId) || !StringUtils.isNumeric(productId) ) {
    response.sendError(HttpServletResponse.SC_EXPECTAT ION_FAILED); //417
    Collection<ProductImages> productImages = productImageService.findByProductId(Integer.valueO f(productId),0,productImageService.count());

    request.setAttribute("productImages", productImages);
    RequestDispatcher rd = request.getRequestDispatcher("/product-photo-gallery.jsp");
    rd.forward(request, response);

    Here is the file path of the "missing" jsp file:

    Caller jsp file:
    <iframe src="<%=request.getContextPath()%>/product-photo-gallery.phdo?productId=${product.productId}"
    onload="this.height=iFrame1.document.body.scrollHe ight"
    frameborder="0" width="800" height="600" scrolling="no"> </iframe>
    Any suggestion is very much appreciated.


  • #2
    I feel that 404 error occuring, has nothing to do with iframe.

    As per the javadoc the call request.getRequestDispatcher("/product-photo-gallery.jsp") will search for product-photo-gallery.jsp relative to web content but its present at different location as mentioned by you. So its better to use a view resolver or try having the jsp file directly under your web content folder.