단순 코드 기록/Spring

Spring_보안폴더에서 외부파일 사용+xml주소처리

일일일코_장민기 2024. 2. 14. 12:52
728x90
Main.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<link rel="stylesheet" href="css/test.css" type="text/css" >

<script type="text/javascript" src="js/test.js">
</script>

</head>
<body>

<br>
<h1>main</h1>
<br>

<img src="image/a.jpg" width="100" height="100"><br>

JS파일을 통해 글자 로딩+콘솔 출력 / CSS파일로 인해 h1 색 변경 / IMG파일로 인해 그림 생성


</body>
</html>

 

Servlet-context.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">

	<annotation-driven />

	<!-- 1. 직접 url과 view 페이지 등록 -->	
	<view-controller path="/test" view-name="main"/>	<!-- test요청에 대해 main.jsp실행 -->

	<!-- 2. 직접 Resource 등록 -->
	<resources mapping="image/**" location="/WEB-INF/image/" />
	<resources mapping="/css/**" location="/WEB-INF/css/" />
	<resources mapping="/js/**" location="/WEB-INF/js/" />
	<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.controller" />
	
</beans:beans>

 

TestController

 

package com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class TestController {

// 일부러 아무것도 불러오지 않도록 만듦
//	@RequestMapping(value = "/test", method = RequestMethod.GET) 
//	public String main() {
//		System.out.println("main");
//		return "main";
//	}
	
	
}

 

 

 

 

 

'단순 코드 기록 > Spring' 카테고리의 다른 글

Spring_Ajax  (0) 2024.02.15
Spring_ajax&JSON(@RequestBody)  (0) 2024.02.14
Spring_Intercept_for_login  (0) 2024.02.14
Spring_Intercept  (0) 2024.02.14
Spring_Redirect_Forwarding  (0) 2024.02.14