web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>springsecuritydemo</display-name>
<!-- <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list> -->
<servlet>
<description></description>
<display-name>offers</display-name>
<servlet-name>offers</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>offers</servlet-name>
<url-pattern>/DispatcherServlet</url-pattern>
</servlet-mapping>
</web-app>
offers-sevlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns = "http://www.springframework.org/schema/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"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.spring.security.web"></context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
<bean name="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsps/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
여기에 무엇이 잘못 되었습니까? home.jsp에 액세스 할 수 없습니다. 실제로 스프링 3.0의 튜토리얼을보고 있는데 비디오에 표시된대로 정확하게 수행했습니다. 누구든지 여기서 내 실수를 지적 할 수 있습니까?
서블릿 매핑의 URL 패턴에 문제가 있습니다.
<url-pattern>/DispatcherServlet</url-pattern>
컨트롤러가
@Controller
public class HomeController {
@RequestMapping("/home")
public String home(){
return "home";
}
}
라고 가정해 보겠습니다. 디스패처 서브렛은 이 URL을 매핑하려고 시도합니다.
현재 우리 서블릿의 URL 패턴은 /Dispatcher
이며, 이는 리소스가 {컨텍스트 경로}/Dispatcher
에서 제공된다는 것을 의미합니다.
하지만 http://localhost:8080/home
을 요청하면 실제로는 사용할 수 없는 /
에서 리소스를 요청하고 있습니다.
따라서 디스패처 서블릿이 /
에서 리소스를 제공하도록 하려면
<url-pattern>/</url-pattern>
를 수행하여 //에서 제공하도록 하거나, /Dispatcher/*
를 수행하여 //에서 제공하도록 해야 합니다.
예
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID"
version="3.1">
<display-name>springsecuritydemo</display-name>
<servlet>
<description></description>
<display-name>offers</display-name>
<servlet-name>offers</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>offers</servlet-name>
<url-pattern>/Dispatcher/*</url-pattern>
</servlet-mapping>
</web-app>
를 입력하고 http://localhost:8080/Dispatcher/home
로 요청하거나
또는 /
만 넣어 다음과 같이 요청합니다.
http://localhost:8080/home
노란색으로 강조 표시된 패키지를 추가했고 이제 내보기 페이지에 액세스 할 수 있습니다. 이클립스에서는 전쟁을 배치 할 때 배치 평가에 언급 된 항목 만 배치합니다.
프로젝트 오른쪽 클릭 --> 속성 --> 적용 및 닫기....에서 배포 평가를 설정합니다.