1.登录页面:
将上一节中的页面放到/WEB-INF/page/目录下,需要登录后才能访问该页面:
对应页面:/WEB-INF/page/menu/home.jsp
<%@ page language="java" pageEncoding="UTF-8"%> <HTML> <HEAD> <TITLE>电力监测中心首页</TITLE> <LINK href="/css/Font.css" type="text/css" rel="stylesheet"> <STYLE>BODY { SCROLLBAR-ARROW-COLOR: #ffffff; SCROLLBAR-BASE-COLOR: #dee3f7 } </STYLE> <SCRIPT type="text/javascript"> function submitrequest(action){ eval("document.location='"+action+"'"); } </SCRIPT> </HEAD> <FRAMESET border=0 frameSpacing=0 rows=82,* frameBorder=0 id="mainparent"> <FRAME name=topFrame src="${pageContext.request.contextPath }/system/elecMenuAction_title.do" noResize scrolling=no> <FRAMESET id="main" border="0" frameSpacing="0" frameBorder="0" cols="153,1%,*"> <FRAME name="leftFrame" src="${pageContext.request.contextPath }/system/elecMenuAction_left.do" noResize> <frame name="changeButton" src="${pageContext.request.contextPath }/system/elecMenuAction_change.do" frameBorder=0 marginHeight=0 marginWidth=0 scrolling=no noresize> <FRAME name="mainFrame" src="${pageContext.request.contextPath }/system/elecMenuAction_loading.do" > </FRAMESET> </FRAMESET> </HTML>
创建elecMenuAction.java文件:
package com.itheima.elec.web.action; @SuppressWarnings("serial") @Controller("elecMenuAction") @Scope(value="prototype") public class ElecMenuAction extends BaseAction<MenuForm>{//需要一个Modeldriver MenuForm menuForm = this.getModel(); /** * MenuHome系统登录的首页 * @return */ //执行保存 public String menuHome(){ System.out.println(menuForm.getName() + "--" + menuForm.getPassword()); return "menuHome"; } public String title(){ return "title"; } public String left(){ return "left"; } public String change(){ return "change"; } public String loading(){ return "loading"; } /** * 重新登录 * @return 跳转到主页面index.jsp */ public String logout(){ //清空指定名称的session // request.getSession().removeAttribute("arg0"); //清空所有session request.getSession().invalidate(); return "logout"; } }
对应struts.xml文件
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- 开发模式 --> <constant name="struts.devMode" value="true"></constant> <!-- ui主题,简单主题 --> <constant name="struts.ui.theme" value="simple"></constant> <!-- 修改struts的后缀 改成do --> <constant name="struts.action.extension" value="do"></constant> <!-- 系统管理 --> <package name="system" namespace="/system" extends="struts-default"> <!-- 测试 --> <action name="elecTextAction_*" class="elecTextAction" method="{1}"> <result name="save">/system/textAdd.jsp</result> </action> <action name="elecMenuAction_*" class="elecMenuAction" method="{1}"> <result name="menuHome">/WEB-INF/page/menu/home.jsp</result> <result name="title">/WEB-INF/page/menu/title.jsp</result> <result name="left">/WEB-INF/page/menu/left.jsp</result> <result name="change">/WEB-INF/page/menu/change.jsp</result> <result name="loading">/WEB-INF/page/menu/loading.jsp</result> <result name="logout" type="redirect"> /index.jsp </result> </action> </package> </struts>
然后:登录后点击重新登录,退出首页
还有对应的loading.jsp页面
<%@ page language="java" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache">
<link href="${pageContext.request.contextPath }/css/Style.css" type="text/css" rel="stylesheet" /> <style type="text/css"> <!-- body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } body,td,th { color: #000000; } --> </style> <style> BODY {SCROLLBAR-FACE-COLOR: #cccccc; SCROLLBAR-HIGHLIGHT-COLOR: #ffffFF; SCROLLBAR-SHADOW-COLOR: #ffffff; SCROLLBAR-3DLIGHT-COLOR: #cccccc; SCROLLBAR-ARROW-COLOR: #ffffff; SCROLLBAR-TRACK-COLOR: #ffffFF; SCROLLBAR-DARKSHADOW-COLOR: #cccccc; } </style> <script language="javascript"> function shiftiframe(value) { if(value==1){ if(document.all.station.width==500) { document.all.station.width=1100; document.getElementById("devtd").style.display="none"; } else if(document.all.station.width==1100) { document.all.station.width=500; document.getElementById("devtd").style.display=""; } } else{ if(document.all.dev.width==500) { document.all.dev.width=1100; document.getElementById("stationtd").style.display="none"; } else if(document.all.dev.width==1100) { document.all.dev.width=500; document.getElementById("stationtd").style.display=""; } } } /**添加10分钟后自动刷新页面,站点和设备运行的实时性*/ window.onload=function(){ setTimeout('refresh10()',1000*60*10) ; } function refresh10(){ window.location.reload(); } </script> <link href="${pageContext.request.contextPath }/css/login.css" rel="stylesheet" type="text/css"> </head> <body> <form name="Form1" method="post" action="name.aspx" id="Form1"> <table width="100%" border="0" height="88" border="1" background=${pageContext.request.contextPath }/images/back1.jpg> <tr> <td colspan=3 class="ta_01" align="center" background="${pageContext.request.contextPath }/images/b-info.gif"><strong>系统首页</strong></td> </tr> <tr> <td width="50%" height="84" align="left" valign="top" id="stationtd"> <fieldset id="stationset" style=" 500px; height: 430px; padding: 1 background:${pageContext.request.contextPath }/images/back1.JPG"><legend> <font color="#0000FF"> <img border="0" src="${pageContext.request.contextPath }/images/zoom.gif" width="14" height="14"><a href="#" onclick="shiftiframe('1')">站点运行情况</a></font></legend> <IFRAME src="elecMenuAction_alermStation.do" name="station" id="station" frameBorder="0" width="500" scrolling="auto" height="400"></IFRAME> </fieldset> </td> <td width="50%" align="left" valign="top" id="devtd"> <fieldset id="devset" style=" 500px; height: 430px; padding: 1 background:${pageContext.request.contextPath }/images/back1.JPG"><legend> <font color="#0000FF"> <img border="0" src="${pageContext.request.contextPath }/images/zoom.gif" width="14" height="14"><a href="#" onclick="shiftiframe('2')">设备运行情况</a></font></legend> <IFRAME src="elecMenuAction_alermDevice.do" name="dev" id="dev" frameBorder="0" width="500" scrolling="auto" height="400"></IFRAME> </fieldset> </td> </tr> <tr><td height=2></td></tr> </table> </form> </body> </html>