여러 예제 또는 프로젝트 및 개인공부를 하다보면
수도없이 많은 URL을 요청해야 한다
그러다보면 폴더도 너무 다양하고 일일이 하나하나 입력하는게 여간 귀찮지 않을 수 없다
그럴때 간단한 설정을 통해서 조금이라도 길이를 줄여서 타이핑을 할 수 있는데
아주 간단한 예시를 통해 알아보자
내가 이번에 요청하게 될 경로는
http://localhost:8080/resources/registerForm.html
이렇게 된다
로컬호스트에서 resources라는 폴더안에서 registerForm.html을 호출했는데
그리 길지는 않지만 resources라고 매번 입력하는게 귀찮긴하다
인텔리제이로 들어가서
해당 파일을 열어보자 servlet-contxt.xml 파일에서
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.fastcampus.ch2" />
</beans:beans>
이렇게 작성되어있는데
내가 수정할 부분은 저기 mapping된 주소이다
<resources mapping="/**" location="/resources/" />
이렇게 바꿔주고 저장을 해주자
이제 기존경로를 넣으면 이렇게 에러가 나온다
바꿔줬으니 앞에 resources를 지우고 새로고침해보면
정상적으로 나오게 되고 훨씬 짧아진 코드입력이 가능해진다
'BackEnd' 카테고리의 다른 글
redirect와 forward (0) | 2022.12.22 |
---|---|
@GetMapping 과 @PostMapping (0) | 2022.12.22 |
@ModelAttribute 그리고 WebDataBinder (1) | 2022.12.21 |
@RequestParam 에 대한 정리 (0) | 2022.12.18 |
서블릿과 JSP(4) - JSTL(JSP Standard Tag Library) (0) | 2022.12.17 |