9월 2023 | ||||||
---|---|---|---|---|---|---|
일 | 월 | 화 | 수 | 목 | 금 | 토 |
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
간단한 엑셀파일 다운로드
이경희 일반 1 3,064 2005.09.30 17:31
인터넷 뒤지면 여기저기서 나오는 간단 소스 입니다.
JSP 페이지 head 에 두줄만 적어주세요!
1. 엑셀파일로 다운받고 싶은 페이지(list.jsp)에 엑셀파일 버튼을 만들고 excel.jsp(파일명은 각자 정하세요) 파일을 링크한다.
2. excel.jsp는 엑셀파일로 다운받고 싶은 페이지(list.jsp)와 동일하게 생성한다.
3. excel.jsp 파일에 <head>에 아래 두줄을 작성한다.
<head>
<title>엑셀다운로드</title>
<%
// EXCEL 파일 다운로드 처리
response.setHeader("Content-Disposition", "attachment; filename=myexcel.xls");
response.setHeader("Content-Description", "JSP Generated Data");
%>
</head>
4. list.jsp 페이지에서 excel.jsp 로 파라미터 값을 넘겨야 겠죠?
히든값으로 해서 넘겨주세요!
참고로..
list.jsp 파일 form 안에 적어주세요!
<!--엑셀 다운로드를 위한 프레임 시작-->
<iframe name="excel" width="0" height="0" frameborder="0"></iframe>
<!--엑셀 다운로드를 위한 프레임 끝-->
5. excel.jsp 에서 각자 상황에 맞게 테이블 모양을 변경하세요.
한글 깨짐 처리
application.properties에 설정 추가
# UTF-8 세팅 server.servlet.encoding.charset=UTF-8 server.servlet.encoding.force=true
https://smpark1020.tistory.com/169
2023-05-27 09:03:02
한글 깨짐 처리
http://honeymon.io/tech/2019/10/23/spring-deprecated-media-type.html
2023-05-22 22:47:39
날짜 데이터가 DB 에 문자열로 다음과 같은 한국 표순시 UTC(GMT) 날짜 형식 "2023-03-14T12:00:00+09:00" 저장 처리되는데
다음과 같은 콛로 LocalDateTime 으로 변경 할수 있다.
@Test public void 팝업테스트() { try { PopupVO popupVO=new PopupVO(); PopupVO popup=popupService.findByPopupId(popupVO); System.out.println("팝업테스트() : " +popup.toString()); //T 가있으면 에러 ////2023-03-14T12:00:00+09:00 과 같은 문자열을 LocalDateTime 형으로 변환 결과 : 2023-03-14T12:00 // 포맷터 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss+09:00"); LocalDateTime startDate = LocalDateTime.parse(popup.getStartDate().replaceAll("T", " "), formatter); LocalDateTime endDate = LocalDateTime.parse(popup.getEndDate().replaceAll("T", " "), formatter); System.out.println(startDate + " : " +endDate + " : "+ startDate.isBefore(LocalDateTime.now()) + " : " + endDate.isBefore(LocalDateTime.now())); // 2021-06-19T21:05:07 //시작날짜가 현재날짜보다 작고 true , 종료 날짝 현재시간보다 큰경우 false if(startDate.isBefore(LocalDateTime.now())&& !endDate.isBefore(LocalDateTime.now())) { System.out.println("화면출력 : on"); }else { System.out.println("화면출력 : off"); } }catch(Exception e) { e.printStackTrace(); } }
2023-03-27 14:44:41
★★★ 깃허브 소스 trip.festival 참조 할것
https://github.com/braverokmc79/springboot-green2209S_16
1. net.sf.log4jdbc.DriverSpy 사용하고 있으면 원래 datasource.driverClassName 으로 변경 처리 한다.
2.
package trip.festival; import javax.sql.DataSource; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.Bean; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.scheduling.annotation.EnableScheduling; //exclude = { SecurityAutoConfiguration.class } 사용시 시큐리티 자동로그인 설정을 배제한다 @SpringBootApplication() @MapperScan(value = { "trip.festival.model.dao.mapper" }) @EnableScheduling public class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(Application.class); } public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Bean public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); Resource[] res = new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*Mapper.xml"); sessionFactory.setMapperLocations(res); return sessionFactory.getObject(); } }
3.pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.6</version> <relativePath /> <!-- lookup parent from repository --> </parent> <groupId>trip.festival</groupId> <artifactId>trip-festival</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>system</name> <description>trip.festival</description> <properties> <java.version>11</java.version> </properties> <dependencies>
<build> <finalName>${artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> <defaultGoal>install</defaultGoal> </build>
4. 빌드
[Spring Boot] Maven 빌드
https://hgko1207.github.io/2021/03/09/springboot-1/
5. Tomcat 서버에 Spring Boot WAR 배포
https://recordsoflife.tistory.com/392
2023-02-27 21:42:14
macaronics.net 는 그어떠한 동영상, 이미지, 파일등을 직접적으로 업로드 제공을 하지 않습니다. 페이스북, 트위터 등 각종 SNS 처럼 macaronics.net 는 웹서핑을 통하여 각종 페이지위치등을 하이퍼링크, 다이렉트링크, 직접링크등으로 링크된 페이지 주소만을 수집 저장하여 제공하고 있습니다. 저장된 각각의 주소에 연결된 페이지등은 그 페이지에서 제공하는 "서버, 사이트" 상황에 따라 페이지와 내용이 삭제 중단 될 수 있으며 macaronics.net 과는 어떠한 연관 관련이 없음을 알려드립니다. 또한, 저작권에 관련된 문제있는 글이나 기타 저작권에 관련된 문제가 있는 것은 연락주시면 바로 삭제해 드리겠습니다.
댓글 ( 0)
댓글 남기기