레이블이 spring인 게시물을 표시합니다. 모든 게시물 표시
레이블이 spring인 게시물을 표시합니다. 모든 게시물 표시

2013년 6월 25일 화요일

html의 데이타를 excle로 저장하기 간단소스 jsp (html table excel export simple jsp source)

//Data.html-------------data what you want to make to Excel(엑셀로만들 데이타)


<script type="text/javascript">
function excel(){
document.frm.action = "excel.jsp";
document.frm.excel_data.value = document.getElementById("excel_body").outerHTML;
document.frm.submit();

}
<form name="frm" method="post">
       <input type="hidden" name="excel_data" />
</form>
<table id="excel_body">
<caption>list</caption>
<thead>
<tr>
<th>userid</th>
<th>name</th>
<th>mail</th>
</tr>
</thead>
<tbody>
<c:forEach items="${list}" var="data" varStatus="status">
<tr>
<td>
<c:out value='${data.userid}' />
</td>
<td>
<c:out value='${data.username}' />
</td>
<td>
<c:out value='${data.email}' />
</td>
</c:forEach>

</tbody>
</table>



//excel.jsp---------------------use just C&P (그냥복사해서 쓰세요)
<%
request.setCharacterEncoding("utf-8");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment; filename=\"excel.xls\"");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
out.print("<meta http-equiv=\"Content-Type\" content=\"application/vnd.ms-excel; charset=utf-8\">");
%>
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<style type="text/css">
body {font-family:tahoma;font-size:12px}
table {padding:2px;border-spacing:0px;font-family:tahoma;font-size:12px;border-collapse:collapse}
td {text-align:center}
</style>
</head>
<body>
<% out.print(request.getParameter("excel_data")); %>
</body>
</html>

spring security logouthandler source

spring security logouthandler는 기본적으로 log-ut-url을 설정해서 사용하지만. 특별한 경우 예를들면 서브도메인이 존재하는 경우 로그아웃을 눌렀을 경우 서브도메인에 따라 로그아웃 후에 경로를 달리해야할 경우가 있다. 1)기본적인 logout 방법 url을 지정해서 사용하는 경우(하나의 url로만 지정된다) <logout invalidate-session="true" logout-success-url="/" /> 2)로그아웃 경로를 달리해야할경우 <logout invalidate-session="true" success-handler-ref="logoutSuccessHandler" /> <beans:bean id="logoutSuccessHandler" class="com.xxx.xxx.security.LogoutSuccessHandler" />

아래는 class SOURCE =====SOURCE

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;
import org.springframework.stereotype.Component;

@Component
public class LogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {

    @Override
    public void onLogoutSuccess(javax.servlet.http.HttpServletRequest request,
                                javax.servlet.http.HttpServletResponse response,
                                Authentication authentication)
            throws java.io.IOException, javax.servlet.ServletException {

       

                if(request.getParameter("SOMEVALUE")){
response.sendRedirect("/url A"); //이부분을 분기처리(if)해서 달리해주면 된다.
}else{
response.sendRedirect("/url B");
}

    }
}

//HTML
<a href="<c:url value="j_spring_security_logout/?logoutURL=SOMEVALUE" />" > Logout</a>






혹시나 하는 맘에 분기처리하는 방법은
request.getParameter로 로그아웃화면에서 특정한 parameter를 날려도 좋고
혹은 request.getServerName() 등으로 받아서 처리해도 좋다. 
사용방법은 본인의 생각에 따라 달리하면 될듯하다.

가장 간단한 방법은
이런식으로 넘겨주고 request.getParameter로 받아서 if로 처리하는 방법이 가장 간단하다. 

더 좋은 방법이 있다면 알려주면 감사합니다.~