2016-10-21 5 views
0

Я пытаюсь отправить «fromdate» и «todate», чтобы получать сообщения. Когда я запускаю код ниже, он говорит «noHandlerFound». Все методы get работают отлично, но не методы Post. Пожалуйста, помогите мне с этим.Как мы можем вызвать метод requestmethod = POST в Spring MVC?

html-код.

<form name="filtersForm" action="/SpringApp/getmessages" method="post"> 
    From Date: <input name="fromDate" type="date" value="01-01-2015" /> 
    To Date: <input name="toDate" type="date" value="01-03-2015" /> 
    <input name="submit" type="submit" value="submit" /> 
</form> 

код Spring:

@RequestMapping(value = "/getmessages", method = RequestMethod.POST) 
public String getMessages(@RequestParam("fromDate") String start_dt, @RequestParam("toDate") String end_dt, 
     ModelMap model) { 

    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"); 
    Date fromDate, toDate; 
    try { 
     fromDate = sdf.parse(start_dt); 
     toDate = sdf.parse(end_dt); 
     model.put("messagesList", appservice.getMessages(fromDate, toDate)); 
    } catch (ParseException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    return "home"; 

} 

Когда я запускаю этот код я получаю ниже ошибки:

org.springframework.web.servlet.PageNotFound noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/SpringApp/403] in DispatcherServlet with name 'mvc-dispatcher' 

Вот файл web.xml.

<?xml version="1.0" encoding="UTF-8"?> 

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd» ID = "WebApp_ID" версия = "3.0"> MonitorApp

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     /WEB-INF/spring-security.xml, 
     /WEB-INF/applicationContext.xml, 
    </param-value> 
</context-param> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<servlet> 
    <servlet-name>mvc-dispatcher</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>mvc-dispatcher</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

<!-- Spring Security --> 
<filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

Spring Security:

<beans:beans xmlns="http://www.springframework.org/schema/security" 
xmlns:beans="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-4.3.xsd 
http://www.springframework.org/schema/security 
http://www.springframework.org/schema/security/spring-security-4.1.xsd"> 

<http auto-config="true" use-expressions="true"> 
    <intercept-url pattern="/**" requires-channel="http" /> 
    <intercept-url pattern="/" 
     access="hasAnyRole('ROLE_ADMIN','ROLE_USER')" /> 
    <intercept-url pattern='/login' access='isAnonymous()' /> 
    <!-- access denied page --> 
    <access-denied-handler error-page="/403" /> 

    <form-login login-page="/login" default-target-url="/home" 
     authentication-failure-url="/login?error" login-processing-url="/j_spring_security_check" 
     username-parameter="username" password-parameter="password" /> 

    <logout logout-success-url="/login?logout" logout-url="/j_spring_security_logout" /> 
    <!-- enable csrf protection --> 
    <csrf /> 
</http> 


<authentication-manager> 
    <authentication-provider> 
     <user-service> 
      <user name="admin" password="admin" authorities="ROLE_ADMIN" /> 
      <user name="user" password="user" authorities="ROLE_USER" /> 
     </user-service> 
    </authentication-provider> 
</authentication-manager> 

ApplicationContext:

<?xml version="1.0" encoding="UTF-8"?> 

http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-4.3.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-4.3.xsd «>

<context:annotation-config /> 
<context:component-scan base-package="com.someapp" /> 
<tx:annotation-driven /> 
<bean 
    class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> 

<bean id="dataSource" 
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 

    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> 
    <property name="url" value="jdbc:oracle:thin:@172.28.12.31:1521:fsdev" /> 
    <property name="username" value="cybercodesqat" /> 
    <property name="password" value="welcome123" /> 
</bean> 

<bean id="entityManagerFactory" 
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" 
    p:dataSource-ref="dataSource" p:persistenceUnitName="MonitorJpaPersistenceUnit" /> 

<bean 
    class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> 

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" 
    p:entityManagerFactory-ref="entityManagerFactory" /> 

<tx:annotation-driven transaction-manager="transactionManager" /> 

+0

Просьба указать [MCVE]. Откуда идет путь 403? –

+0

Можете ли вы показать свой web.xml? –

+0

403 отправляется с весны безопасности xml – U9000521

ответ

1

Попробуйте это решение, предложенное here.

@Configuration 
public class CreateYourSecurityConfig extends WebSecurityConfigurerAdapter { 
    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
    http.csrf().disable(); 
    } 
} 
0

Мой вопрос был решен путем изменения контекста путь к GetMessages? _csrf = a0008ebb-bed2-4245-89da-b012db364e99 может быть это из-за безопасности.

Смежные вопросы