신미성
68
2021-05-04 18:27:38 작성 2021-05-04 18:51:33 수정됨
0
54

springboot jsp: include jsp 경로를 못잡아요.


스프링부트가 리소스/static  만 경로를 잡게 되어 있네요. 


변경방법을 찾고 있는데.. 어떻게 하면될까요? 

안하고 넘길라고 했는데 header, 네비게이션 등등 공통파트에대한 해결할방법이 없어요. 


아래처럼은 했는데.. 저러면 jsp를 중간에 넣을수가 없고요. 

전에 해결한걸본적있는데.. 어떻게해야할지 모르겠네요. 

package com.today10sec.diary.config;

import org.apache.catalina.Context;
import org.apache.tomcat.util.descriptor.web.JspConfigDescriptorImpl;
import org.apache.tomcat.util.descriptor.web.JspPropertyGroup;
import org.apache.tomcat.util.descriptor.web.JspPropertyGroupDescriptorImpl;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Collections;

@Component
public class DiarySpringBootServletInitializer extends SpringBootServletInitializer {

@Bean
public ConfigurableServletWebServerFactory configurableServletWebServerFactory ( ) {
return new TomcatServletWebServerFactory(){
@Override
protected void postProcessContext(Context context) {
super.postProcessContext(context);
JspPropertyGroup jspPropertyGroup = new JspPropertyGroup();
jspPropertyGroup.addUrlPattern("*.jsp");
jspPropertyGroup.setPageEncoding("UTF-8");
jspPropertyGroup.setScriptingInvalid("true");
jspPropertyGroup.addIncludePrelude("/WEB-INF/views/common/common.jsp");
jspPropertyGroup.setTrimWhitespace("true");
jspPropertyGroup.setDefaultContentType("text/html");
JspPropertyGroupDescriptorImpl jspPropertyGroupDescriptor = new JspPropertyGroupDescriptorImpl(jspPropertyGroup);
context.setJspConfigDescriptor(new JspConfigDescriptorImpl(Collections.singletonList(jspPropertyGroupDescriptor), Collections.emptyList()));

}
};
}
}


spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
0
  • 답변 0

  • 로그인을 하시면 답변을 등록할 수 있습니다.