GAEでAdministratorしか使えないページを作る場合.
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
UserService userService = UserServiceFactory.getUserService();
String thisURL = request.getRequestURI();
if (request.getUserPrincipal() != null && userService.isUserAdmin()) {
String urlLogout = userService.createLogoutURL(thisURL);
request.setAttribute("urlLogout", urlLogout);
RequestDispatcher rd = request.getRequestDispatcher(jsp).forward(request, response);
} else {
response.getWriter().println("<p>
Please <a href=\"" +userService.createLoginURL(thisURL) +"\">sign in</a>.</p>");
}
}
これで,jsp側で
<%
String urlLogout = (String)request.getAttribute("urlLogout");
%>
・・・
<a href="<%=urlLogout%>">ログアウト</a>
としてあげればOk.
0 件のコメント:
コメントを投稿