인코딩은 jsp, 서버, spring 단계마다 각각 인코딩 설정해준대로 돌아간다.

2가지 인코딩 문제를 겪음.

1.Spring에서 수정하고, 수정사항을 보여주는데 인코딩이 깨짐.

이 때 javascript와 spring 상에서 잘 뿌려주는지 확인했는데 response 단에 문제가 있었음. 

 

해결방법은

@RequestMapping(value = "/addpresident", method = RequestMethod.POST, produces = "text/html; charset=utf-8")

 

mapping에다가 produces를 붙임.

 

2. 1번과 반대로 controller에 들어갈 때부터 인코딩 깨짐. DB에 이상한 글자가 들어가있길래 확인해 봄.

form태그로 보냈는데....

web.xml에 encoding Filter 추가

 
    https://gmlwjd9405.github.io/2019/01/01/spring-utf8.html

프로젝트를 하는데 시간 계산이 필요한 순간이 왔다.

처음에는 dto에서 String으로 받아서 DB에 String으로 넣고 있었는데 이러면 시간 계산이 안된다.

나의 경우 시간만 DB에 넣고 싶었는데 찾아본 결과 oracle에 시간만 넣을 수는 없다. 

oracle에서 시간을 원하는 형식으로 넣고 빼는 sql은 to_date와 to_char가 있는데 date는 dto에서도 date로 받을 수 있어서 시간 계산이 가능하다. to_char는 String으로 불러오기 때문에 계산이 불가능하다.

 

그리고 DB에 시간만 넣고 싶었는데 이건 불가능했다. 무조건 날짜가 들어가야했다. 그래서 그냥 String으로 넣고 쓰고싶을 때 불러와서 parsing후에 비교하는 방식으로 바꿨다.

 

그리고 시간 입력할 때는 dto에서 date형식으로 불러오고 넣는것 보다 String으로 입력해서 넣는게 훨씬 편하고 에러도 적은 것 같다.

'Spring' 카테고리의 다른 글

인코딩 문제 해결  (0) 2019.11.11
Numberformatexception 오류 해결  (0) 2019.10.21
File upload + MultipartFile 과 File 정리  (0) 2019.09.24
web.xml,root-context.xml,servlet-context.xml  (0) 2019.06.11

1. jstl 상의 오타

dto와 db상의 컬럼명 다름

c태그의 컬럼명 오타 등 

 

2.  jdbctypefornull에 null을 넣어준 경우 

select 쿼리문 날려서 list로 받아오면 String 형태로 null이 옴.

이 경우 list.size()로 사이즈 확인해보고 0이 아닐 경우 null이 아님.

필자는 jstl empty list 써서 list안에 있는 프로퍼티를 가리키며 numberformat 에러가 떴고,

list size가 3이었음. 즉 null 3개가 들어있음.

 

controller 단에서 null일 경우 result값에 listnull 을 넣어주고 jstl 상에서 listnull일 경우와 아닌 경우로 로직처리함.

File 클래스 정리

https://hyeonstorage.tistory.com/233

 

[JAVA] File 클래스 정리 (파일정보, 파일목록, 하드디스크 정보 출력)

File 클래스 정리 java.io 패키지는 기존의 파일이나 폴더에 대한 제어를 하는 데 사용하는 File 클래스를 제공한다. 이 클래스를 이용해서 파일과 폴더에 대한 다양한 기능을 제공한다. 파일을 나타내는 객체를..

hyeonstorage.tistory.com

 

File명 또는 디렉토리 변경

https://pandorica.tistory.com/38

 

java, 파일 rename, move 하는법

JAVA로 파일명을 변경하거나, 파일을 다른디렉토리로 이동하는 방법입니다. 첫번째 방법입니다. File file = new File( "c:/text.txt" ); File fileToMove = new File( "c:/TEMP/text2.txt" ); boolean isMoved =..

pandorica.tistory.com

MultipartFile.transferTo 

https://okky.kr/article/512140

 

OKKY | MultipartFile.transferTo 에 대해서 잘아시는분 계신가요?

웹에서 폼형태로 파일데이터를 컨트롤러에서 받을 경우 이 데이터는 어디에 저장 되어있나요? 임시파일형태로 저장되어 있나요? transferTo 메서드에서  isInMemory() 일 경우에는 FileOutputStream.write 하고 아닐경우는 FileUtils . moveFile()을 하던데.. transferTo을 이용하

okky.kr

 

 

파일업로드 샘플 1

https://passionha.tistory.com/214

 

파일업로드 처리(MultipartResolver, MultipartFile)

인코딩 타입이 Multipart인 경우 파라미터나 업로드한 파일을 구하려면 전송 데이터를 알맞게 처리해 주어야 한다. 스프링은 Multipart 지원 기능을 제공하고 있기 때문에, 이 기능을 이용하면 추가적인 처리없이..

passionha.tistory.com

 

파일업로드 샘플 2

https://loco-motive.tistory.com/72

 

스프링프레임워크 간단한 파일업로드 샘플

스프링프레임워크 간단한 파일업로드 샘플 1. 환경설정 pom.xml commons-fileupload commons-fileupload 1.2.1

loco-motive.tistory.com

 

파일업로드 샘플 3

https://jdkblog.tistory.com/132

 

Spring FileUpload 하기

안녕하세요. 퍼온글 : https://mkil.tistory.com/273 pom.xml 1 2 3 4 5 commons-fileuploadcommons-fileupload1.3.2

jdkblog.tistory.com

파일업로드 샘플 4

https://advenoh.tistory.com/26

 

스프링 파일 업로드 처리

1. 들어가며 이번 포스팅에서는 스프링에서 파일 업로드를 어떻게 구현할 수 있는지에 대해서 알아보도록 하겠습니다. 스프링에서는 단일 파일 업로드뿐만이 아니라 아래와 같은 여러 방법으로 파일 업로드 기능을..

advenoh.tistory.com

파일업로드 샘플 5

https://parkwonhui.github.io/spring/2019/03/20/java-spring-fileupload.html

 

file upload

web, server, java, spring 등.. 공부한 것을 기록하는 장소 입니다. 공부하면서 정리하였기 때문에 틀린 내용이 있을 수 있습니다. 이야기 해주시면 수정하겠습니다. HOME /About /algorithmus /db /front /git /java /ml /search /server /spring 파일업로드 방식 form 태그 사용 방식 : 브라우저 제한이 없어야 하는 경우 사용. 일반적으로 페이지 이동과 동시에 첨부파일을 업로드하는 방

parkwonhui.github.io

 

'Spring' 카테고리의 다른 글

인코딩 문제 해결  (0) 2019.11.11
oracle-Spring 시간 계산은 서버에서 처리  (0) 2019.10.29
Numberformatexception 오류 해결  (0) 2019.10.21
web.xml,root-context.xml,servlet-context.xml  (0) 2019.06.11

1) web.xml

설정을 위한 설정파일이다. 배포 기술자로써 영어로는 DD(Deployment Descriptor) 이다.

이 파일은 WAS(Web Application Server)가 최초 구동될 때 즉 톰켓이 최초 구동될 때 web.xml을 읽고 그에 해당하는 설정을 구성한다. 즉 각종 설정을 위한 설정파일이라고 할 수 있다.

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
      <context-param>  - 루트 컨텍스트로 모든 서블릿과 필터들이 공유함. root-context.xml을 정의
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/root-context.xml</param-value>
      </context-param>
      
      
      <!-- Creates the Spring Container shared by all Servlets and Filters -->
      <listener> - 리스너로써 루트 컨텍스트에 정의 되어있는 것들을 모든 서블릿과 필터가 공유할 수 있게 해준다고 함.
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      
      
      
      <!-- Processes application requests -->
      <servlet> - 서블릿 설정
            <servlet-name>appServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> - DispatcherServlet으로 앞단에서 요청정보를 핸들링 해줌.
            <init-param>
                  <param-name>contextConfigLocation</param-name> 
                  <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> -servlet-context.xml을 가르키고 있음.
            </init-param>
            <load-on-startup>1</load-on-startup>
      </servlet>
            
            
            
      <servlet-mapping> - appServlet에 대한 url-pattern을 정의
            <servlet-name>appServlet</servlet-name>
            <url-pattern>/</url-pattern>
      </servlet-mapping>
</web-app>

2) servlet-context.xml

주석을 보면  <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> 이라고 나와있다.

해석해보면 DispatcherServlet Context : 이 서블릿의 요청처리 인프라를 정의한다. 이다. Dispatcher 서블릿과 관련된 설정을 하는것 같다.

정답은 아니지만 주로 View 지원 bean을 설정한다고 한다. ex) Controller

그래서 그런지 어노테이션, 리소스 디렉토리, ViewResolver에 관한 설정들이 있다.



<?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 http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://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/" /> - HTML 리소스 디렉토리 정의
      <!-- 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"> - ViewResolver로 jsp와 name 을 매핑
            <beans:property name="prefix" value="/WEB-INF/views/" />
            <beans:property name="suffix" value=".jsp" />
      </beans:bean>
      
      <context:component-scan base-package="com.hee.heechart" /> - 베이스 패키지 하위 모든 어노테이션을 스캔해서 빈으로 등록하겠다는 것.
     
</beans:beans>

3) root-context.xml 

처음에 프로젝트 생성시에는 아무 내용도 없다. 이곳은 공통빈을 설정하는 곳으로 주로 View 지원을 제외한 bean을 설정한다고 한다. 

ex) Service / Repository(DAO) / DB/ log 등등

mybatis를 root-context에 만들어 보도록 하자.

<?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:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
		http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
	
	<!-- Root Context: defines shared resources visible to all other web components -->
	
    <!--먼저 오라클 드라이버 연결 spring에서는 객체를 bean으로 생성한다. xml에서 bean으로 생성하는 방법이있고, annotation으로 생성하는 방법이 있고, config로 생성하는 방법이 있다.-->
    <bean name="driver"
    
    
</beans>




출처: https://debugdaldal.tistory.com/127 [달달한 디버깅]

 

[SPRING] web.xml , root-context.xml , servlet-context.xml 에 관하여...

1) web.xml 설정을 위한 설정파일이다. 배포 기술자로써 영어로는 DD(Deployment Descriptor) 이다. 이 파일은 WAS(Web Application Server)가 최초 구동될 때 즉 톰켓이 최초 구동될 때 web.xml을 읽고 그에 해당..

debugdaldal.tistory.com

 

'Spring' 카테고리의 다른 글

인코딩 문제 해결  (0) 2019.11.11
oracle-Spring 시간 계산은 서버에서 처리  (0) 2019.10.29
Numberformatexception 오류 해결  (0) 2019.10.21
File upload + MultipartFile 과 File 정리  (0) 2019.09.24

+ Recent posts