친애하는 친구,액션 URL이 Spring MVC에서 메소드 액션 이름을 호출하지 않음
Spring MVC 양식 예제 웹 프로젝트를 실행하려고했습니다.
동작 이름이 해당 URL에 도달하려고 시도 할 때 해당보기가 을 호출하지 않지만 뷰 이름 (/viewname.html)을 사용하여 URL을 호출하려고 시도하면 해당 페이지가 표시됩니다.
많은 예제를 보았고 내 코드가 액션 이름을 기반으로 호출하지 않는 이유가 궁금합니다.
내 샘플 코드 :
컨트롤러 :
@Controller
@RequestMapping("/test")
public class TestController {
@RequestMapping(value="/login",method = RequestMethod.GET)
public String login(ModelMap model){
model.addAttribute("message","Welcome Jagan");
return "login";
}
}
봄-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:p="http://www.springframework.org/schema/p"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="controller"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
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>SpringMVCWithJSP</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
의 login.jsp처럼 내 웹 XML 보인다 : 나는 다음과 같은 URL을
http://localhost:8082/SpringMVCWithJSP/test/login => not invoking login page.
ttp://localhost:8082/SpringMVCWithJSP/test/login.html => successfully invoking login page .
을 공격하려고하면 일부 환영의 콘텐츠
을 가진 내 질문은 login.jsp를 직접 호출하지 않고 대신 .../test/login.html
으로 만 호출하고 .../test/login
으로는 호출하지 않는 로그인 작업 이름입니다. 이 친구를 해결하는 데 도움이되는 아이디어가 있습니까? 당신에
서블릿은'* .html' 패턴을 가진 요청에만 응답합니다. 서블릿이 URL에 '.html'을 추가하지 않으면 (패턴과 일치하지 않기 때문에) 서블릿은 패턴을 찾지 못합니다. – ochi