struts,java frameset,frame,iframeフレームワーク,jspフレームワーク
主jsp
Index.jsp
Left.jsp
左のjspです
上のjsp
Login.jsp
下のjsp
Main.jsp
ログイン成功後のjsp
ユーザログインフィルタ
OnlineFilter.java
//上陸フィルター
Web.xmlでは注意
黒い髪 http://heisetoufa.iteye.com
Index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<frameset cols='20%,*'>
<frame src='Left.jsp'noresize bordercolor='skyblue'>
<frameset rows='20%,*'>
<frame src='Login.jsp'noresize bordercolor='skyblue'>
<frame src='Main.jsp' name='bottom'>
</frameset>
</frameset>
<body>
</body>
</html>
Left.jsp
左のjspです
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
上のjsp
Login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> </title>
</head>
<body>
<html:form action="/login.do" method="post">
<tr>
<td> :</td><td><html:text property="loginUName" style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9"/></td>
</tr>
<tr>
<td> :</td><td><html:password property="loginUPwd" style="ime-mode:disabled;width: 130 px; "/></td>
</tr>
<tr>
<td colspan="2" align="center"><html:submit value=" "/></td>
</tr>
</html:form>
</body>
</html>
下のjsp
Main.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
ログイン成功後のjsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
ユーザログインフィルタ
OnlineFilter.java
//上陸フィルター
package filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import dointerface.ApplicationSource;
public class OnlineFilter extends HttpServlet implements Filter
{
private static final long serialVersionUID = 1L;
public void init(FilterConfig filterConfig) throws ServletException
{
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
HttpServletRequest httpRequest = (HttpServletRequest)request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
HttpSession session = httpRequest.getSession();
if(session.getAttribute(ApplicationSource.USER) == null
&& !httpRequest.getRequestURI().endsWith("/public/Index.jsp") //
&& !httpRequest.getRequestURI().endsWith("/public/Left.jsp")
&& !httpRequest.getRequestURI().endsWith("/public/Login.jsp")
&& !httpRequest.getRequestURI().endsWith("/public/Main.jsp")){
// System.out.println(ApplicationSource.USER);
// System.out.println(httpRequest.getContextPath()+httpRequest.getRequestURI().endsWith("/public/Login.jsp"));
// System.out.println(httpRequest.getContextPath() + "/public/Index.jsp");
httpResponse.sendRedirect(httpRequest.getContextPath() + "/public/Index.jsp");
}
chain.doFilter(request, response);
}
public void destroy()
{
}
}
Web.xmlでは注意
<welcome-file-list>
<welcome-file>/public/Index.jsp</welcome-file>
</welcome-file-list>
,
<filter>
<filter-name>onlineFilter</filter-name>
<filter-class>filter.OnlineFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>onlineFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
黒い髪 http://heisetoufa.iteye.com