configuring annotations in Springmvc - java

I am having below error when running my springmvc application. In my controller file I have used annotation to map viewAll.view to displagy inventory/ListAll.jsp but this doesn't seem to be working.
I can see message "In ViewDVDController.viewAll()" in the console using sysout in the controller file.
Please can you advise if i am missing some mappings?
Error:
HTTP Status 404 - /SpringMVC/views/inventory/viewAll.jsp
--------------------------------------------------------------------------------
type Status report
message /SpringMVC/views/inventory/viewAll.jsp
description The requested resource (/SpringMVC/views/inventory/viewAll.jsp) is not available.
--------------------------------------------------------------------------------
Apache Tomcat/7.0.29
index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Highview DVD Management</title>
</head>
<body>
<p> This DVD Management Model contains the following modules</p>
<ul>
<li>View All DVDs </li>
<li>Add a DVD </li>
</ul>
</body>
</html>
ViewDVDController.java
#Controller
public class ViewDVDController extends MultiActionController {
public ViewDVDController(){
System.out.println("In ViewDVDController()");
}
#Autowired
private InventoryManager manager;
public InventoryManager getManager(){
return manager;
}
public void setManager(InventoryManager manager){
this.manager=manager;
}
#RequestMapping(value="viewAll.view", method=RequestMethod.GET)
public ModelAndView viewAll() throws Exception {
System.out.println("In ViewDVDController.viewAll()");
Collection<DVDInfo> all = manager.getAll();
return new ModelAndView("ListAll","catalog",all);
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Spring MVCDemo</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/inventory/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cotext="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven/>
<cotext:component-scan base-package="springmvc"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/views/inventory/"/>
<property name="suffix" value=".jsp" />
</bean>
</beans>
log4j Log:
22:31:38,370 DEBUG ctory.support.DefaultListableBeanFactory: 430 - Creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
22:31:38,372 DEBUG ctory.support.DefaultListableBeanFactory: 458 - Finished creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
22:31:38,372 DEBUG gframework.web.servlet.DispatcherServlet: 647 - Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator#1a0b94d]
22:31:38,372 DEBUG ctory.support.DefaultListableBeanFactory: 245 - Returning cached instance of singleton bean 'viewResolver'
22:31:38,373 DEBUG ctory.support.DefaultListableBeanFactory: 430 - Creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
22:31:38,376 DEBUG ctory.support.DefaultListableBeanFactory: 458 - Finished creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
22:31:38,377 DEBUG gframework.web.servlet.DispatcherServlet: 709 - Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager#16c14c0]
22:31:38,377 DEBUG gframework.web.servlet.DispatcherServlet: 523 - Published WebApplicationContext of servlet 'spring' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.spring]
22:31:38,377 INFO gframework.web.servlet.DispatcherServlet: 463 - FrameworkServlet 'spring': initialization completed in 804 ms
22:31:38,377 DEBUG gframework.web.servlet.DispatcherServlet: 136 - Servlet 'spring' configured successfully
22:31:38,383 DEBUG gframework.web.servlet.DispatcherServlet: 819 - DispatcherServlet with name 'spring' processing GET request for [/SpringMVC/inventory/viewAll.view]
22:31:38,385 DEBUG .annotation.RequestMappingHandlerMapping: 213 - Looking up handler method for path /viewAll.view
22:31:38,387 DEBUG .annotation.RequestMappingHandlerMapping: 220 - Returning handler method [public org.springframework.web.portlet.ModelAndView springmvc.presentation.ViewDVDController.viewAll() throws java.lang.Exception]
22:31:38,388 DEBUG ctory.support.DefaultListableBeanFactory: 245 - Returning cached instance of singleton bean 'viewDVDController'
22:31:38,390 DEBUG gframework.web.servlet.DispatcherServlet: 902 - Last-Modified value for [/SpringMVC/inventory/viewAll.view] is: -1
In ViewDVDController.viewAll()
siz of the collection is 2
22:31:38,413 DEBUG ctory.support.DefaultListableBeanFactory:1498 - Invoking afterPropertiesSet() on bean with name 'viewAll'
22:31:38,413 DEBUG gframework.web.servlet.DispatcherServlet:1178 - Rendering view [org.springframework.web.servlet.view.JstlView: name 'viewAll'; URL [/views/inventory/viewAll.jsp]] in DispatcherServlet with name 'spring'
22:31:38,413 DEBUG pringframework.web.servlet.view.JstlView: 371 - Added model object 'modelAndView' of type [org.springframework.web.portlet.ModelAndView] to request in view with name 'viewAll'
22:31:38,413 DEBUG pringframework.web.servlet.view.JstlView: 371 - Added model object 'org.springframework.validation.BindingResult.modelAndView' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'viewAll'
22:31:38,417 DEBUG pringframework.web.servlet.view.JstlView: 236 - Forwarding to resource [/views/inventory/viewAll.jsp] in InternalResourceView 'viewAll'
22:31:38,420 DEBUG gframework.web.servlet.DispatcherServlet: 913 - Successfully completed request

Finally, I got my answer.
I was importing wrong ModelAndView Class
(org.springframework.web*.portlet.*ModelAndView) instead of org.springframework.web.*servlet.*ModelAndView in the controller file.

In what package is ViewDVDController in? Beware that the value of base-package (in cotext:component-scan) must match your package name.

Related

How to troubleshoot HTTP 404 The origin server did not find a current representation for the target resource

Following a software demo on Skillsoft, I built a simple Spring MVC Demo app in Eclipse. The app loads fine and I can hit the home page ("Hello World"). But when I try to hit my controller, I get the following error message
HTTP Status 404 - Not Found
Type Status Report
Message /springMVCDemo/WEB-INF/jsp/quote.jsp
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
I've studied the following links that describe the same error, but I could not make my code work:
Tomcat 404 error: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists
Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists
web.xml
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>MyDemoApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/myDemoApp-servletConfig.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyDemoApp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
myDemoApp-servletConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.demo.controllers"</context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
MyDemoController.java
package com.demo.controllers;
import java.util.Random;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class MyDemoController {
private String[] quotes = {"To be or not to be -Shakespeare",
"Stay hungry you're alone -Dee Snider",
"Might as well jump! -David Lee Roth"};
//http://localhost:8080/springMVCDemo/getQuote.html
#RequestMapping(value="/getQuote")
public String getRandomQuote(Model model) {
int rand = new Random().nextInt(quotes.length);
String randomQuote = quotes[rand];
model.addAttribute("randomQuote", randomQuote);
return "quote";
}
}
Quote.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>My Demo App</title>
</head>
<body>
<h1>The quote is:</h1>
<p>${randomQuote}</p>
</body>
</html>
index.jsp
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
Directory Structure
springMVCDemo
|
-->main
-->java
-->com
-->demo
-->controllers
-->MyDemoController.java
-->webapp
-->WEB-INF
myDemoApp-servletConfig.xml
web.xml
index.jsp
-->jsp
-->Quote.jsp
What I've tried and the results
Experiment #1:
http://localhost:8080/springMVCDemo
Result: Browser displays "Hello World!" as expected
Experiment #2:
http://localhost:8080/springMVCDemo/getQuote.html
Expected behaviour: One of three quotes gets displayed
Actual result: HTTP 404 + Eclipse console messages:
Dec 29, 2018 5:59:40 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'MyDemoApp'
Dec 29, 2018 5:59:40 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'MyDemoApp': initialization started
Dec 29, 2018 5:59:40 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'MyDemoApp-servlet': startup date [Sat Dec 29 17:59:40 EST 2018]; root of context hierarchy
Dec 29, 2018 5:59:40 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/myDemoApp-servletConfig.xml]
Dec 29, 2018 5:59:42 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/getQuote],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.demo.controllers.MyDemoController.getRandomQuote(org.springframework.ui.Model)
Dec 29, 2018 5:59:42 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'MyDemoApp': initialization completed in 1751 ms
Experiment #3:
http://localhost:8080/springMVCDemo/getQuote2.html
Result: As expected here, I got HTTP 404 since no such mapping exists. Also the following Eclipse console message was displayed:
Dec 29, 2018 6:03:21 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/springMVCDemo/getQuote2.html] in DispatcherServlet with name 'MyDemoApp'
In summary, I believe my controller is getting mapped correctly, but for some reason the page won't get displayed :(
Software versions I am using
Eclipse 2018-09 (4.9.0);
Tomcat v9.0
If anyone can provide some troubleshooting advice, it would be greatly appreciated. I've spent nearly 8 hours trying to tailor my servlet config file, but so far no luck.
I noticed a few things along your code:
The mapping of your controller is getQuote, and it seems to be configured and running based on this log of your server:
INFO: Mapped
"{[/getQuote],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}"
onto public java.lang.String
com.demo.controllers.MyDemoController.getRandomQuote(org.springframework.ui.Model)
Your jsp name is Quote, instead of quote (case sensitive matters):
-->jsp
-->Quote.jsp
So first, you should do a request to your mapped URL, in the case getQuote as the following:
http://localhost:8080/springMVCDemo/getQuote
Put a breakpoint in your controller and check if you can actually reach it by requesting this URL.
Also fix the return page of your Controller, since your page is named Quote, you are returning the quote page instead (remember the case sensitive):
#RequestMapping(value="/getQuote")
public String getRandomQuote(Model model) {
...
return "quote";
}

Receiving a Spring RequestMappingHandlerMapping error in Google App Engine

I have built a simple Spring MVC application that works flawlessly on my local machine. Having uploaded it to the Google App Engine, however, I receive a HTTP 500 error.
Looking into the logs I recieve this INFO message:
org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions: Loading XML bean definitions from ServletContext resource [/WEB-INF/enterprise-servlet.xml]
Which is normal, as I receive this INFO message when running the app locally. Spring would then go onto map urls onto methods, for example a log message from my local machine:
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.register Mapped "{[/listStaff],methods=[GET],produces=[application/json || application/xml]}" onto public java.util.List<org.andrewvincent.model.Staff> org.andrewvincent.controller.Controller.listStaffXML()
However when looking at the logs from the app engine, I receive the following error:
org.springframework.web.context.support.XmlWebApplicationContext refresh: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.sun.reflect.annotation")
I assume this is why I am receiving the 500 error code, as the urls are not being mapped onto the methods, but I cannot work out why I receive this error when I don't locally.
The following is my enterprise-servlet.xml:
<beans xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven/>
<bean id="controllerBean" class="org.andrewvincent.controller.Controller"></bean>
<bean id="plainControllerBean"
class="org.andrewvincent.controller.PlainTextController"></bean>
<mvc:resources mapping="/resources/**" location="/resources/"/>
<mvc:default-servlet-handler/>
</beans>
If anyone could help me out it would be much appreciated.
This is a known bug.
Are you using 4.2.4? If so you should downgrade to 4.2.3.

java.lang.IllegalStateException: start tag has already been written wso2 as

I created a JAX-WS project wso2 developer studio.
In this project I inherited from interface DocumentRegistryPortType we can find in the lib developed by Rahul(http://repo1.maven.org/maven2/com/github/rahulsom/ihe-iti/0.7/ihe-iti-0.7.jar)!.
When I try to access the wsdl in the WSO2 AS shows me the following error.
[2014-05-19 01:15:46,943] INFO {org.apache.cxf.service.factory.ReflectionServiceFactoryBean} - Creating Service {urn:ihe:iti:xds-b:2007}DocumentRegistry_Service from class ihe.iti.xds_b._2007.DocumentRegistryPortType
[2014-05-19 01:15:51,080] INFO {org.springframework.beans.factory.support.DefaultSingletonBeanRegistry} - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#6bc684d1: defining beans [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,DocumentRegistry]; root of factory hierarchy
[2014-05-19 01:15:51,081] ERROR {org.apache.catalina.core.ApplicationContext} - StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DocumentRegistry': Invocation of init method failed; nested exception is java.lang.IllegalStateException: start tag has already been written
Any idea what could be this error?
This is my cxf-servlet.xml file. The name of the package is jax and the class is DocumentRegistry. This class implement of DocumetRegistryPortType.
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:server id="DocumentRegistry" address="/servicio">
<jaxws:serviceBean>
<bean class="jax.DocumentRegistry"/>
</jaxws:serviceBean>
</jaxws:server>
</beans>

Trouble getting mapping to work

I'm using Spring 3.0.5. None of my annotated controllers are getting recognized. I have XML for my application …
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<mvc:resources mapping="/static/**" location="/static/"/>
<mvc:annotation-driven/>
<context:component-scan base-package="com.myco.systems.leadsmonitor"/>
My static assets are getting picked up fine. But I'm getting a 404 when I try and reach an annotated controller …
package com.myco.systems.leadsmonitor.web.controller;
#Controller
public class HomeController {
…
#RequestMapping("/")
public void index(Model model) {
model.addAttribute("latestLeadTime", MonitorStatistics.getInstance().getLatestLeadCreationTime());
model.addAttribute("lastDBCheck", MonitorStatistics.getInstance().getLastDBCheck());
}
What else do I need to do to get my controllers picked up by Spring? Thanks, - Dave
I think the reason you are getting a 404 is because the view is not being resolved in the contoller method. By default a void return type is mapped using to a view name based on the URI, in your case since the path is "/", it probably gets resolved to "", which does not get mapped to any logical view.
Can you try a couple of things:
Start in a debug mode and see if your request is actually coming to the RequestMapping method
If it is, can you explicitly return a view name from your method and see if this view name is getting resolved to a correct view(assuming that you have a view resolver registered)
You should check both URL mappings in web.xml and view resolution configuration in your spring configuration.
One good resource is Spring By Example.org
see: http://www.springbyexample.org/examples/simple-spring-mvc-form-annotation-config-webapp.html
Another one are the tutorials available in SpringSource ToolSuite (STS), where they walk you through creating a Spring MVC web application. Those tutorials usually include the UrlRewriteFilter from tuckey.org
e.g. servlet maps to /app, then add this servlet filter
<!-- Enables clean URLs with JSP views e.g. /welcome instead of /app/welcome -->
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<!-- <init-param>-->
<!-- <param-name>logLevel</param-name>-->
<!-- <param-value>DEBUG</param-value>-->
<!-- </init-param>-->
</filter>

Spring MVC - jsp not rendering

I'm just starting with Spring MVC trying to create a new project, and came accross an issue for which no manual or tutorial seems to help...
I have set up a simple application with no logic, just trying to get Spring configured properly. The controller just returns the name of a view to be displayed, but the view resolver is not rendering the jsp, and returning a 404 error....
Any help is greatly appreciated.
My web.xml is:
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>openstats</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>openstats</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<display-name>OpenStats API Server</display-name>
</web-app>
An my openstats-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<context:component-scan base-package="org.openstats.api.controller"/>
<!-- Enable to request mappings PER METHOD -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<!-- Enable annotated POJO #Controller -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<!-- Define the view resolver to use jsp files within the jsp folder -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
<property name="prefix"><value>/jsp/</value></property>
<property name="suffix"><value>.jsp</value></property>
</bean>
</beans>
The controller itself has no logic whatsoever, it's simply:
#Controller
public class ProductController {
#RequestMapping(value = "/products.do", method = RequestMethod.GET)
public ModelAndView listProducts(HttpServletRequest request) {
ModelAndView model = new ModelAndView("index");
return model;
}
}
The controller is reached, the issue is when attempting to render...
I set up log4j in debug, and this is part of what I get:
02:08:19,702 DEBUG
DispatcherServlet:1094 - Testing handler adapter
[org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#397b6074]
02:08:19,803 DEBUG
HandlerMethodInvoker:134 - Invoking
request handler method: public org.springframework.web.servlet.ModelAndView
org.openstats.api.controller.ProductController.listProducts(javax.servlet.http.HttpServletRequest)
02:08:19,833 DEBUG
DefaultListableBeanFactory:1367 -
Invoking afterPropertiesSet() on bean
with name 'index' 02:08:19,876 DEBUG
InternalResourceViewResolver:81 -
Cached view [index] 02:08:19,877 DEBUG
DispatcherServlet:1181 - Rendering
view
[org.springframework.web.servlet.view.JstlView:
name 'index'; URL [/jsp/index.jsp]] in
DispatcherServlet with name
'openstats' 02:08:19,877 DEBUG
JstlView:240 - Rendering view with
name 'index' with model {} and static
attributes {} 02:08:19,923 DEBUG
JstlView:234 - Forwarding to resource
[/jsp/index.jsp] in
InternalResourceView 'index'
02:08:19,926 DEBUG
DispatcherServlet:955 -
DispatcherServlet with name
'openstats' determining Last-Modified
value for [/api-server/jsp/index.jsp]
02:08:19,927 DEBUG
DispatcherServlet:1054 - Testing
handler map
[org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#440c4cee]
in DispatcherServlet with name
'openstats' 02:08:19,928 DEBUG
DefaultAnnotationHandlerMapping:179 -
No handler mapping found for
[/jsp/index.jsp] 02:08:19,929 DEBUG
DispatcherServlet:962 - No handler
found in getLastModified 02:08:19,937
DEBUG DispatcherServlet:781 -
DispatcherServlet with name
'openstats' processing request for
[/api-server/jsp/index.jsp]
02:08:19,938 DEBUG
DispatcherServlet:843 - Bound request
context to thread: GET
/api-server/products.do HTTP/1.1
My jsp folder is right within "webapp" and the index.jsp file exists.
Thanks in advance.
I do have the same problem with Spring 3.x.
Any progress so far?
EDIT:
I figured it out myself :-) I used the following servletmapping:
<servlet-mapping>
<servlet-name>spring-frontcontroller</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Editing the url-pattern to e.g. *.do fixes the problem of not rendering the JSP.
But this leaves the question how this is possible with your url-pattern.
Does your web.xml define index.jsp in the welcome-file-list, if so it may be getting overridden. Try changing the jsp name to products.jsp.
e.g.
#Controller
public class ProductController {
#RequestMapping(value = "/products.do", method = RequestMethod.GET)
public String handleRequest() {
return "products";
}
}
doesn't your .jsp and your .do conflict? since a file cannot end with both .jsp and .do .. therefore it will never resolve... so you should get rid of .jsp or change your url pattern to /*
Changing
import org.springframework.web.servlet.ModelAndView;
by
import org.springframework.web.portlet.ModelAndView;
Works in my case.

Categories