Announcement Announcement Module
Collapse
No announcement yet.
Could not resolve view with name in servlet with name 'Spring MVC Dispatcher Servlet' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Could not resolve view with name in servlet with name 'Spring MVC Dispatcher Servlet'

    Hello,

    With Spring MVC 3 and JBoss 7, in my jsp, I am trying to inject a spring url tags with its value into a controller, but it run into the following error:

    javax.servlet.ServletException: Could not resolve view with name 'category/image/5955' in servlet with name 'Spring MVC Dispatcher Servlet'
    My jsp code:
    <img alt="" src="<spring:url value="/category/image/${category.categoryId}" htmlEscape="true"/>" />
    Controller with relevant Annotation:
    @RequestMapping(value="/category/image/{processDefinitionKey}", method = RequestMethod.GET)
    public ResponseEntity<byte[]> downloadReportTemplateContent(

    I am wondering what I have done wrong.

  • #2
    The path "category/image/5955" looks different to the RequestMapping path "/category/image/xxx".
    Is this the problem? if so, why Spring strip off the leading "/" character?

    Very appreciate for any suggestion.
    Thanks
    Sam

    Comment


    • #3
      I suggest you take a look at the logging output and also take notice of the request processing lifecycle. I suspect that your mapping is wrong and thus the method isn't getting called. Which will lead to spring invoking the RequestToViewNameTranslator to get a viewname (which is basically the incoming URL without the leading / and extension).

      You only posted a snippet of your code/configuration. But I suspect you want /category/image to be at the root of your site whereas you use the spring:url tags which makes t he passed in URL relative (including the current path).

      Comment


      • #4
        The /login is tagged by <c:url , where c is defined as <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
        what is the difference if I use <spring:url for passing value to @RequestMapping(value="/category/image/{processDefinitionKey}" controller.

        What if I remove the leading "/" character in the controller?

        Thanks a lot
        Sam

        Comment


        • #5
          Please read my post and read the reference guide.

          Originally posted by Marten Deinum
          I suspect that your mapping is wrong and thus the method isn't getting called. Which will lead to spring invoking the RequestToViewNameTranslator to get a viewname (which is basically the incoming URL without the leading / and extension).
          The behavior you describe is inline with my conclusion. Now take a look at the logging output (you might want to enable debug logging for org.springframework.web) and see which URLs are mapped and which URL comes in for the link you posted earlier.

          The behavior of the UrlTag is desribed here.

          Comment


          • #6
            Thanks for the quick reply.
            Here I found the url from log file:


            [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-12) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/category/image/4302] is: -1

            Thanks
            Sam

            Comment


            • #7
              or it looks like this:
              [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.mvc.annotation.Def aultAnnotationHandlerMapping - Mapping [/category/image/
              9975] to HandlerExecutionChain with handler [ix.houseware.category.web.controller.CategoryImage Controller@93e06df] and 3 interceptors
              08:44:29,972 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/category
              /image/9975] is: -1

              Comment


              • #8
                At startup of your container (and when debug is on) you should see a list of URLs mapped to which controllers. When the request comes in you should see some logging of which controller executes the request. Which is the latter, the first is the actual result and indicating that caching of the result is disabled (the -1).

                Not sure if you are at liberty to upgrade to Spring 3.1 but I would recommend it as the RequestMapping stuff in there is better then < 3.1. At least imho that is.

                Comment


                • #9
                  Hi, I still can't get it right.
                  In my jsp file, I have the following line of code to deal with the display of the image:

                  <td><img alt="" src="<spring:url value="/category/image/${category.categoryId}" htmlEscape="true"/>" /></td>
                  where categoryId is 5499 which is expected to be used to retrieve corresponding image bytes from the database.
                  I have also attached a server.log file for reference. Please search "5499" in the log file for more details.

                  Very appreciate for any help and suggestion.
                  Thanks
                  Sam

                  Comment


                  • #10
                    I also suspect my the method in my controller is wrong:

                    @RequestMapping(value="/category/image/{processDefinitionKey}", method = RequestMethod.GET)
                    public ResponseEntity<byte[]> downloadReportTemplateContent(
                    @PathVariable final String processDefinitionKey)
                    throws IOException {
                    String categoryId = processDefinitionKey;
                    System.out.println("categoryId: "+categoryId);
                    List<CategoryImages> ciList = (List<CategoryImages>) categoryImageService.findImagesByCategoryId(Intege r.parseInt(categoryId), 0, categoryImageService.count()) ;
                    if (ciList.isEmpty()) {
                    System.out.print("cList is Empty.............");
                    return null;
                    }
                    System.out.println(" .......... before ciList.get(0)..............");
                    CategoryImages ci = ciList.get(0);
                    int imageLength = ci.getImageData().length;
                    try {
                    System.out.println(" ..........in Try Block......... ");
                    InputStream image = new ByteArrayInputStream(ci.getImageData());
                    byte[] imageBytes = IOUtils.toByteArray(image);
                    System.out.println(" ..........imageBytes length: "+imageBytes.length);

                    HttpHeaders headers = new HttpHeaders();
                    headers.setContentType(MediaType.IMAGE_JPEG);
                    headers.setContentLength(imageBytes.length);
                    System.out.println(" ..........headers: "+headers.toString());

                    return new ResponseEntity<byte[]>(imageBytes, headers, HttpStatus.OK);
                    } catch (Exception e) {
                    throw new RuntimeException(e);
                    }
                    }
                    as it thrown the following errors:

                    02:31:24,210 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Spring MVC Dispatcher Servlet' processing GET request for [/CategoryClient6-web/category/image/5499]
                    02:31:24,211 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Looking up handler method for path /category/image/5499
                    02:31:24,211 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Returning handler method [public org.springframework.http.ResponseEntity<byte[]> ix.houseware.category.web.controller.CategoryImage Controller.downloadReportTemplateContent(java.lang .String) throws java.io.IOException]
                    02:31:24,212 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Did not find handler method for [/resources/images/th.bg.gif]
                    02:31:24,212 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Matching patterns for request [/resources/images/th.bg.gif] are [/resources/**]
                    02:31:24,212 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - URI Template variables for request [/resources/images/th.bg.gif] are {}
                    02:31:24,212 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Did not find handler method for [/resources/images/diplomat.jpg]
                    02:31:24,212 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Mapping [/resources/images/th.bg.gif] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceH ttpRequestHandler@3ce724f5] and 1 interceptor
                    02:31:24,213 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Returning handler method [public org.springframework.http.ResponseEntity<byte[]> ix.houseware.category.web.controller.CategoryImage Controller.downloadReportTemplateContent(java.lang .String) throws java.io.IOException]
                    02:31:24,213 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-7) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Did not find handler method for [/resources/images/springone2gx.jpeg]
                    02:31:24,213 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/resources/images/th.bg.gif] is: -1
                    02:31:24,213 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Matching patterns for request [/resources/images/diplomat.jpg] are [/resources/**]
                    02:31:24,213 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.resource.ResourceH ttpRequestHandler - Trying relative path [images/th.bg.gif] against base location: ServletContext resource [/]
                    02:31:24,213 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/category/image/4958] is: -1
                    02:31:24,213 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/category/image/5499] is: -1

                    Comment

                    Working...
                    X