전체 글
- re 2022.10.01
- 깃에러 2022.08.16
- 톰캣구조 2022.08.16
- 이클립스 에러 - java.lang.Error: Unresolved compilation problem 2022.08.16
- Apache commons Fileupload 사용법과 한글깨짐 에러 2022.08.03
re
깃에러
톰캣구조
https://itwarehouses.tistory.com/8
Apache Tomcat(아파치 톰캣) 디렉토리 구조
개요 이번 글에서는 Apache Tomcat의 디렉토리 구조와 각 디렉토리 안의 파일들이 어떤 기능을 수행하는지 알아보고자 한다. 본 글은 Apache Tomcat 9 버전을 기준으로 작성되었다. Tomcat 디렉토리 구조 /
itwarehouses.tistory.com
공부하고 다시 정리할것
'Tools > Eclipse' 카테고리의 다른 글
이클립스 에러 - java.lang.Error: Unresolved compilation problem (0) | 2022.08.16 |
---|
이클립스 에러 - java.lang.Error: Unresolved compilation problem
SEVERE: 경로 [/test]의 컨텍스트 내의 서블릿 [com.project.item.control.ItemFrontCtl]을(를) 위한 Servlet.service() 호출이, 근본 원인(root cause)과 함께, 예외 [서블릿 실행이 예외를 발생시켰습니다.]을(를) 발생시켰습니다.
java.lang.Error: Unresolved compilation problem:
the type javax.servlet.http.httpservletrequest cannot be resolved. it is indirectly referenced from required .class file
The method parseRequest(HttpServletRequest) from the type ServletFileUpload refers to the missing type HttpServletRequest
git에서 프로젝트를 불어왔으나 뭔가 안 맞아서 에러발생
이거저거 만지다가 프로젝트 새로 생성해서 내용물만 복사
된는가 싶더니 서버를 통해 디비와 데이터 교환을 시도하면 위와 같은 에러 발생
프로젝트 clean부터해서 이거저거 다 찾아봤다..
환경변수부터시작해서 다 뒤져봤지만 안 되다가
처음에 프로젝트 불어왔을때 commons 라이브러리를 포함 외부라이브러리 인식이 안되는 줄 알고
모듈패스에 추가를 해줬었었는데 이걸 잊고 있었다....
난 모듈패스가 프로젝트에 국한되서 적용된다는 건줄 알았는데
찾아보니 전혀 다름
기본에 충실해야하는데,,학원에서 내어준 프로젝트하기에 급급해서리
어서 마무리하고 세팅 값들이 의미하는 것부터 하나씩 다시 공부를 해야겠다
쨋든 JRE빼고 모듈패스에 추가된거 모두 삭제했더니 정상 ~
이렇게 지식이 하나 추가돼었음
https://whitekeyboard.tistory.com/849
[Eclipse] Modulepath vs Classpath
ModulePath, ClassPath 이 둘의 차이는 뭔지 궁금하게 된 계기가 이클립스 버전을 높이면서 BuildPath를 설정중이었는데 Eclipse 구버전에는 그냥 두 개 구분없이 일렬로 나왔었는데, 최신 버전을 받으니
whitekeyboard.tistory.com
Apache commons Fileupload 사용법과 한글깨짐 에러
https://commons.apache.org/proper/commons-fileupload/download_fileupload.cgi
FileUpload – Download Apache Commons FileUpload
Download Apache Commons FileUpload Using a Mirror We recommend you use a mirror to download our release builds, but you must verify the integrity of the downloaded files using signatures downloaded from our main distribution directories. Recent releases (4
commons.apache.org
https://commons.apache.org/proper/commons-io/download_io.cgi
Commons IO – Download Apache Commons IO
Download Apache Commons IO Using a Mirror We recommend you use a mirror to download our release builds, but you must verify the integrity of the downloaded files using signatures downloaded from our main distribution directories. Recent releases (48 hours)
commons.apache.org
필요한 jar파일 압축풀고 java build path 에 추가
//fileUploadTest.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>
</head>
<body>
<form action="upload.fi" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>이름</td>
<td><input type='text' name="name"></td>
</tr>
<tr>
<td>파일</td>
<td><input type='file' name="imgFile" multiple accept="image/*"></td>
</tr>
<tr>
<td colspan="2"> <button>전송</button> </td>
</tr>
</table>
</form>
</body>
</html>
@WebServlet("*.fi")
public class FileUploadTest extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public FileUploadTest() {
super();
// TODO Auto-generated constructor stub
}
protected void doAction(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String path = req.getServletPath();
if(path.equals("/upload.fi")) {
try {
Multipart mp = new Multipart(req);
Map<String,String> map = mp.saveFiles();
System.out.println(map.get("name"));
System.out.println(map.get("fullFileName"));
}catch(Exception e) {
System.out.println("파일업로드 실패 : "+e);
}
RequestDispatcher rd = req.getRequestDispatcher("fileUploadTest.jsp");
rd.forward(req, resp);
}
}
위에서 트라이문에 들어간 모든것들은 서블릿을 하나 더 만들고 거기서 작성을 해야 위 서블릿이 깔끔합니다만,,
예시이니 넘어감
public class Multipart {
private static final String CONPATH = "D:\\temp";
private static final int LIMIE_SIZE = 1024*1024*5; //5mb
List items;
Multipart(HttpServletRequest req) throws FileUploadException{
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
items = upload.parseRequest(req);
}
public Map<String,String> saveFiles() throws Exception{
Map<String, String> map = new HashMap<>();
Iterator itr = items.iterator();
String fullFileName = "";
while(itr.hasNext()) {
FileItem item = (FileItem) itr.next();
if(item.isFormField()) {
map.put(item.getFieldName(), item.getString("utf-8"));
}else {
fullFileName+="\\img"+item.getName()+",";
item.write(new File(CONPATH+"\\"+item.getName()));
}
}
map.put("fullFileName", fullFileName);
return map;
}
}
파일 경로와 이름들을 한 문자열에 담아 DB에 저장하려는 목적으로 설계
해당 클래스를 호출한곳에서 DB와 연결하여 저장할 것이기때문에 맵으로 넘겨줌
(Multipart클래스에 I/O를 다 할지는 프로젝트 짜면서 고민을 조금 더 해봐야할 듯)
isFormField() 메서드는 파일이아닌 텍스트가 들어오면 true를 반환
텍스트는 getString()메서드로 밸류를 얻을 수 있고 파일은 getName()
다 짜고 구현해보니 한글깨짐때문에 제대로 작동 을 안 하네,,?
톰캣의 언어셋이 아니라 텍스트파라미터의 밸류만 깨짐..!
파워 구글링 !!
req.setCharacterEncoding("utf-8"); 이나 //나는 서블릿에서 이미 변환을 한 상태
upload.getHeaderEncoding("utf-8"); 을 작성한다거나
server.xml > connector 에 URIEncoding="utf-8" 설정을 한다거나,, 등등이 있었습니다만
다 안 먹혔습니다.
그러다가 getString() 메서드에 인자로 언어셋을 주니 정상작동ㅜㅜ
디테일한 이유는 조금 더 공부를 해봐야겠음