JAVA에서 XML 파일 생성
JAVA에서 Oracle 데이터 조회 후 XML로 생성하는 방법
1. 파일 생성 경로 설정
딱히 없으면 패스
2. Oracle 데이터 XML 생성
소스
openapiBean bean = new openapiBean();
bean.setMap(resultMap);
resultList = krXmlService.selectXmlfolderStrucheData(krWbsPrjVO);
resultMap.put("body" , resultList);
Writer writer = new StringWriter();
JAXBContext jc = JAXBContext.newInstance(openapiBean.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(bean, writer);
result = writer.toString();
writer.close();
StringBuilder jspPath = (new StringBuilder()).append( propertiesService.getString("Globals.jsp.path.window"));
StringBuilder filePath = (new StringBuilder()).append(request.getSession().getServletContext().getRealPath("WEB-INF")).append(File.separator).append("jsp");
filePath.append(File.separator).append("xml").append(File.separator).append("strucheXml.xml");
jspPath.append(File.separator).append("xml").append(File.separator).append("strucheXml.xml");
File file = new File(filePath.toString());
File jspFile = new File(jspPath.toString());
FileWriter fw = null;
if(file.exists()){
file.delete();
}
if(jspFile.exists()){
jspFile.delete();
}
file.createNewFile();
fw = new FileWriter(file, true) ;
fw.write(result.toString());
fw.flush();
fw.close();
jspFile.createNewFile();
fw = new FileWriter(jspFile, true) ;
fw.write(result.toString());
fw.flush();
fw.close();
3. openapiBean Class 생성
'IT > java' 카테고리의 다른 글
JAVA SERVER CLIENT EXE (0) | 2018.05.02 |
---|---|
JAVA LOCAL 프로그램 실행 (0) | 2018.05.02 |
Ajax binary를 통한 JSP에서 파일 쓰기 (0) | 2018.01.05 |
JAVA 및 Tomcat 환경설정 (0) | 2017.10.23 |
JAVA File Download (0) | 2016.10.05 |