Announcement Announcement Module
Collapse
No announcement yet.
@Path variable problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Path variable problem

    Hi, i want to use PathVariable but met some problems. My controller is:

    Code:
    @Controller
    public class ExportReportController implements InitializingBean{
    
    @RequestMapping(value="/report/{portfolioName}")
    	public ModelAndView export(@PathVariable("portfolioName")String portfolioName, @RequestParam("reportType")String reportType, ModelAndView modelAndView, WebRequest request, HttpServletResponse response,ModelMap map, HttpServletRequest servletRequest){
    		try{
    my spring context is:
    Code:
    <?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:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="
    	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-2.5.xsd
    	">
    
    	<context:annotation-config />
    
    	<context:component-scan base-package="com.meritservus.web" />
    	<context:component-scan base-package="com.meritservus.service" />
    	<context:component-scan base-package="com.meritservus.service.dwr" />
    
    
    	<bean
    		class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    		<property name="order" value="1" />
    		<property name="interceptors" ref="localeChangeInterceptor" />
    	</bean>
    	
    
    
    
    	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="order" value="10" />
    		<property name="viewClass"
    			value="org.springframework.web.servlet.view.JstlView" />
    		<property name="requestContextAttribute"><value>rc</value></property>
    		<property name="prefix" value="/WEB-INF/jsp/" />
    		<property name="suffix" value=".jsp" />
    	</bean>
    	
    	<bean class="com.meritservus.web.SimpleMappingExceptionResolverImpl">
    		<property name="mailSenderService" ref="mailSenderService" />
    		<property name="defaultErrorView" value="error" />
    	</bean>
    
    	<bean id="beanResolver"
    		class="org.springframework.web.servlet.view.BeanNameViewResolver">
    		<property name="order" value="3" />
    	</bean>
    	
    	<bean class="org.springframework.web.servlet.view.XmlViewResolver">
    			<property name="location" value="/WEB-INF/jasper-views.xml"/>
    			<property name="order" value="2"/>
    	</bean>
    	
    
    	<bean id="requestTradeFormValidator" class="com.meritservus.web.validator.RequestTradeFormValidator">
    		<property name="tradeService" ref="tradeService" />
    	</bean>
    	<bean id="registrationUserFormValidator"
    		class="com.meritservus.web.validator.RegistrationUserFormValidator">
    		<property name="userService" ref="userService" />
    	</bean>
    	
    	<bean id="changeUserPasswordFormValidator" class="com.meritservus.web.validator.ChangeUserPasswordFormValidator" />
    
    	<bean class="com.meritservus.web.LastLoggedInListener">
    		<property name="userService" ref="userService" />
    	</bean>
    
    
    	<!-- Internationalization -->
    	<bean id="localeChangeInterceptor"
    		class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
    	<bean id="localeResolver"
    		class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    		<property name="defaultLocale" value="en" />
    	</bean>
    
    </beans>
    and when i run my application i see:
    Code:
    00:10:16.828  INFO [main] org.springframework.web.servlet.handler.AbstractUrlHandlerMapping:411 - Mapped URL path [/report/{portfolioName}] onto handler 'exportReportController'
    00:10:16.828  INFO [main] org.springframework.web.servlet.handler.AbstractUrlHandlerMapping:411 - Mapped URL path [/report/{portfolioName}.*] onto handler 'exportReportController'
    00:10:16.828  INFO [main] org.springframework.web.servlet.handler.AbstractUrlHandlerMapping:411 - Mapped URL path [/report/{portfolioName}/] onto handler 'exportReportController'
    but when i try to call export controlle i get: No mapping found for HTTP request with URI [/bergains/report/TEST_PORTF]

    what is the problem ?

    i think the problem in my web.xml mapping, i have next:

    Code:
    	<servlet-mapping>
    		<servlet-name>meritservus</servlet-name>
    		<url-pattern>/dwr/*</url-pattern>
    	</servlet-mapping>
    	<servlet-mapping>
    		<servlet-name>meritservus</servlet-name>
    		<url-pattern>/report/</url-pattern>
    	</servlet-mapping>
    	<servlet-mapping>
    		<servlet-name>meritservus</servlet-name>
    		<url-pattern>*.mrk</url-pattern>
    	</servlet-mapping>
    	<servlet-mapping>
    		<servlet-name>meritservus</servlet-name>
    		<url-pattern>*.json</url-pattern>
    	</servlet-mapping>
    Last edited by Trollchik; Oct 29th, 2011, 06:17 PM.

  • #2
    PLEASE, HElp anybody!

    Comment


    • #3
      missing wildcard

      Originally posted by Trollchik View Post

      Code:
      	<servlet-mapping>
      		<servlet-name>meritservus</servlet-name>
      		<url-pattern>/report/</url-pattern>
      	</servlet-mapping>

      Just glancing through your code it seems that your url-pattern should have a wild card:

      Code:
      	<servlet-mapping>
      		<servlet-name>meritservus</servlet-name>
      		<url-pattern>/report/*</url-pattern>
      	</servlet-mapping>
      And I'm no java or spring expert but it seems that an excess of method parameters makes for smelly code. Maybe consider getting your ModelMap from the ModelAndView and eliminating WebRequest.

      Comment

      Working...
      X