How to setup Sesrvlet or Controller handling iframe request.
samwun9988 Apr 27, 2013 9:24 PMHi,
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.
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>
<servlet-name>photoGalleryServlet</servlet-name>
<servlet-class>ForestsurfClient.controller.PhotoGalleryServ let</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>photoGalleryServlet</servlet-name>
<url-pattern>*.phdo</url-pattern>
</servlet-mapping>
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.
return;
}
if (StringUtils.isEmpty(productId) || !StringUtils.isNumeric(productId) ) {
response.sendError(HttpServletResponse.SC_EXPECTAT ION_FAILED); //417
return;
}
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:
WEB-INF/views/prouct-photo-gallery.jsp
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.
Thanks
Samuel