ajax练习

来源:互联网 发布:oracle数据库 中文 编辑:程序博客网 时间:2024/04/29 21:31

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <filter>
  <filter-name>struts2</filter-name>
  <filter-class>
   org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>*.action</url-pattern>
 </filter-mapping>
 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>*.jsp</url-pattern>
 </filter-mapping>
 <error-page>
  <error-code>500</error-code>
  <location>/pages/error.jsp</location>
 </error-page>
 <error-page>
  <error-code>404</error-code>
  <location>/pages/error.jsp</location>
 </error-page>
 <error-page>
  <exception-type>java.lang.Exception</exception-type>
  <location>/pages/error.jsp</location>
 </error-page>
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
 </context-param>

 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <welcome-file-list>
  <welcome-file>pages/login/login.jsp</welcome-file>
 </welcome-file-list>
</web-app>

applicationContext.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
 <bean id="LoginService" class="crm.service.LoginService"/>
 <bean id="LoginAction" class="crm.action.LoginAction" scope="prototype">
  <property name="loginService">
   <ref bean="LoginService" />
  </property>
 </bean>
 <bean id="uploadAction" class="crm.action.UploadAction" scope="prototype"/>
 <bean id="downloadAction" class="crm.action.DownloadAction" scope="prototype"/>
</beans>

struts.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
 <constant name="struts.objectFactory" value="spring" />
 <!--<include file="struts-default.xml"></include> -->
 <constant name="struts.i18n.encoding" value="UTF-8" />
 <constant name="struts.multipart.maxSize" value="20971520"></constant>
 <package name="user" extends="struts-default">
  <!-- 定义全部拦截器,所有拦截器和拦截器栈都在该元素下定义 -->
  <interceptors>
   <!-- 定义权限验证拦截器,interceptor是定义拦截器 -->
   <interceptor name="myInterceptor" class="crm.interceptor.MyInterceptor" />
   <!-- 定义拦截器栈,配置了3个拦截器,interceptor-ref是配置拦截器 -->
   <interceptor-stack name="myStacks">
    <interceptor-ref name="myInterceptor" />
    <interceptor-ref name="defaultStack" />
   </interceptor-stack>
  </interceptors>
  <!-- 如果包中没有显示指定拦截器,则默认的拦截器会起作用,如果包中 有其他的拦截器,则默认的拦截器不起作用,需要手动去配置拦截器的引用,
   每个包中只能配置一个默认的拦截器 -->
  <default-interceptor-ref name="myStacks" />
  <!-- 全局的result -->
  <global-results>
   <result name="login">/pages/login/login.jsp</result>
   <result name="error">/pages/error.jsp</result>
   <result name="input">/pages/error.jsp</result>
  </global-results>

  <!-- 登陆系统,不用验证拦截器,用系统默认的拦截器 -->
  <action name="ajaxLogin" class="LoginAction" method="login">
   <interceptor-ref name="defaultStack" />
  </action>

  <!-- 获取验证码 -->
  <action name="nextCheckCode" class="LoginAction" method="changeCheckCode">
   <interceptor-ref name="defaultStack" />
  </action>
  <action name="intoMain" class="LoginAction" method="intoJsp">
   <result>/pages/main/main.jsp</result>
  </action>

  <!-- 注销系统 -->
  <action name="loginOut" class="LoginAction" method="loginOut">
   <result>/pages/login/login.jsp</result>
  </action>

  <!-- 跳转页面 -->
  <action name="toUploadJsp" class="LoginAction" method="intoJsp">
   <result>/pages/file/upload.jsp</result>
  </action>
  <action name="toDownloadJsp" class="LoginAction" method="intoJsp">
   <result>/pages/file/download.jsp</result>
  </action>
  
  <!-- 文件列表 -->
  <action name="fileList" class="LoginAction" method="fileList">
      <result>/pages/file/fileList.jsp</result>
  </action>

  <!-- 文件上传 -->
  <action name="uploadFile" class="uploadAction" method="uploadFile">
   <!-- 文件保存路径,可是相对也可是绝对 -->
   <!-- 绝对:<param name="savePath">E:/upload</param> -->
   <param name="savePath">/upload</param>
   <result>/pages/file/upload.jsp</result>
  </action>

  <!-- 文件下载 -->
  <action name="downloadFile" class="downloadAction">
   <result type="stream">
       <!-- 指定下载的文件类型 -->
    <param name="contentType">application/octet-stream</param>
    <!-- 由getDownloadFile()方法返回下载文件的inputStream -->
    <param name="inputName">downloadFile</param>
    <!-- 下载的文件名 -->
    <param name="contentDisposition">attachment;filename="${downloadChineseFileName}"</param>
    <!-- 下载文件的缓存大小 -->
    <param name="bufferSize">70960</param>
   </result>
  </action>

 </package>
</struts>

LoginAction.java:

package crm.action;

import java.io.File;
import java.io.PrintWriter;
import java.util.Random;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import crm.entity.Worker;
import crm.service.LoginService;

public class LoginAction extends ActionSupport {
 private LoginService loginService;
 private String userName;
 private String userPass;
 
 public String getUserName() {
  return userName;
 }

 public void setUserName(String userName) {
  this.userName = userName;
 }

 public String getUserPass() {
  return userPass;
 }

 public void setUserPass(String userPass) {
  this.userPass = userPass;
 }

 public LoginService getLoginService() {
  return loginService;
 }

 public void setLoginService(LoginService loginService) {
  this.loginService = loginService;
 }

 /**
  * 判断用户登录的Action
  * @return String
  */
 public String login() {
  if(!userName.equals("jiaqiufeng") || !userPass.equals("10910jqf"))
  {
   returnAjax("用户名或密码错误!");
  }
  else
  {
   Worker worker = new Worker();
   worker.setWname(userName);
   worker.setWpassword(userPass);
   loginService.saveToSession(worker);
   returnAjax("000000");
  }
  return null;
 }

 /**
  * 退出系统
  * @return String
  */
 public String loginOut() {
  loginService.loginOut();
  return SUCCESS; 
 }
 
 /**
  * ajax核心代码
  * @return String
  */
 public void returnAjax(String returnMes)
 {
  try {
   // 获取response对象
   HttpServletResponse response = ServletActionContext.getResponse();
   // 设置字符集
   response.setContentType("text/html;charset=GBK");
   PrintWriter out = response.getWriter();
   // 直接输出响应的内容
   //out.print(returnMes);
   out.write(returnMes);
   out.flush();
   out.close();
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
 
 /**
  * 获取验证码核心方法
  * @return String
  */
 private String checkCode(int n)
 {
  StringBuffer sb = new StringBuffer();
  String base="abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(int i = 0 ; i < n ;  i++)
  {
   Random random = new Random();
   int randomNo = random.nextInt(base.length());
   char randomNum = base.charAt(randomNo);
   sb.append(randomNum);
  }
  return sb.toString(); 
 }
 
 /**
  * 获取验证码
  * @return String
  */
 public String changeCheckCode()
 {
  String checkNo = checkCode(4);
  returnAjax(checkNo);
  return null;
 }
 
 /**
  * 跳转页面
  * @return String
  */
 public String intoJsp()
 {
  return SUCCESS;
 }
 
 /**
  * 文件列表
  * @return String
  */
 public String fileList()
 {
  String filePath = ServletActionContext.getServletContext().getRealPath("/upload");
  File file = new File(filePath);
  loginService.fileList(file);
  return SUCCESS;
 }
}

LoginService.java:

package crm.service;

import java.io.File;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import crm.entity.Worker;

public class LoginService{ 
 /**
  * 保存至对象到Session
  */
 public void saveToSession(Worker worker)
 {
  ActionContext context=ActionContext.getContext();
  Map request=(Map) context.get("request");
  Map session=(Map)context.getSession();
  session.put("worker", worker);
 }
  
 /**
  * 清空request和session
  */
 public void loginOut()
 {
  ActionContext context=ActionContext.getContext();
  Map request=(Map) context.get("request");
  Map session=(Map)context.getSession();
  request.clear();
  session.clear();
 }
 /**
  * 获取文件列表
  */
 public void fileList(File file)
 {
  ActionContext context=ActionContext.getContext();
  Map request=(Map) context.get("request");
  if(!file.exists())
  {
   file.mkdir();
  }
  String[] fileLists = file.list();
  if(fileLists.length<1)
  {
   request.put("fileLists", "noFile");
   return;
  }
  request.put("fileLists", fileLists);
 }
}

MyInterceptor.java:

package crm.interceptor;

import java.util.Map;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import crm.entity.Worker;

public class MyInterceptor extends AbstractInterceptor {
 public String intercept(ActionInvocation invocation) throws Exception {
  ServletActionContext.getResponse().setHeader("Pragma", "no-cache");
  ServletActionContext.getResponse().setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
  ServletActionContext.getResponse().addHeader("Cache-Control", "post-check=0, pre-check=0");
  ServletActionContext.getResponse().setHeader("Expires", "0");
  //获取session中保存的用户信息
  Map session=invocation.getInvocationContext().getSession();
  Worker worker=(Worker)session.get("worker");
  if(worker==null)
  {
   return Action.LOGIN;
  } 
  else
  { 
   return invocation.invoke();
  }
 }
}

UploadAction.java:

package crm.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class UploadAction extends ActionSupport {
    private File upload; 
    private String uploadFileName; 
    private String uploadContentType;
    private String savePath;
    
    public File getUpload() {
  return upload;
 }

 public void setUpload(File upload) {
  this.upload = upload;
 }

 public String getUploadFileName() {
  return uploadFileName;
 }

 public void setUploadFileName(String uploadFileName) {
  this.uploadFileName = uploadFileName;
 }

 public String getUploadContentType() {
  return uploadContentType;
 }

 public void setUploadContentType(String uploadContentType) {
  this.uploadContentType = uploadContentType;
 }

 public String getSavePath() {
  //得到savePath的绝对路径
  String filePath = ServletActionContext.getServletContext().getRealPath(savePath);
  File saveFile = new File(filePath);
  if(!saveFile.exists())
  {
   saveFile.mkdir();
  }
  return filePath;
 }

 public void setSavePath(String savePath) {  
  this.savePath = savePath;
 }
 
 public String uploadFile()
 {
  try {
   FileOutputStream fos = new FileOutputStream(getSavePath()+"\\"+getUploadFileName());
   FileInputStream fis = new FileInputStream(getUpload());
   byte[] buffer=new byte[1024];
   int len = 0;
   while((len = fis.read(buffer))>0)
   {
    fos.write(buffer, 0, len);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return SUCCESS;
 }
}

DownloadAction.java:

package crm.action;

import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class DownloadAction extends ActionSupport {
    private String paramName; 
    private File download; 
    private String downloadFileName;
    private String downloadContentType; 

    public String getParamName() {
  return paramName;
 }

 public void setParamName(String paramName) {
  this.paramName = paramName;
 }

 public File getDownload() {
  return download;
 }

 public void setDownload(File download) {
  this.download = download;
 }

 public String getDownloadFileName() {
  return downloadFileName;
 }

 public void setDownloadFileName(String downloadFileName) {
  this.downloadFileName = downloadFileName;
 }

 public String getDownloadContentType() {
  return downloadContentType;
 }

 public void setDownloadContentType(String downloadContentType) {
  this.downloadContentType = downloadContentType;
 }

 // 从下载文件原始存放路径读取得到文件输出流  
    public InputStream getDownloadFile() throws UnsupportedEncodingException {
        paramName = new String(paramName 
                .getBytes("ISO8859-1"), "utf-8");
        downloadFileName = paramName;
        return ServletActionContext.getServletContext().getResourceAsStream("/upload/"+downloadFileName);
    }   
    // 如果下载文件名为中文,进行字符编码转换 
    public String getDownloadChineseFileName() {
        String downloadChineseFileName = ""; 
        try { 
            downloadChineseFileName = new String(downloadFileName 
                    .getBytes("GBK"), "ISO8859-1"); 
        } catch (UnsupportedEncodingException e) { 
            e.printStackTrace(); 
        } 
        return downloadChineseFileName; 
    } 
}

login.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!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">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <style type="text/css">
    #returnMes{ 
 font-size:medium;
 color:#F00;
 font-weight: bold;
    }
    </style>
 <script type="text/javascript">
  //定义一个变量用于存放XMLHttpRequest对象   
    var xmlHttp;
    //改函数用于创建一个XMLHttpRequest对象   
    function createXMLHttpRequest(){   
        if(window.ActiveXObject){   
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");   
        }else if(window.XMLHttpRequest){   
            xmlHttp = new XMLHttpRequest();   
        }   
    }
    //这是一个启动AJAX异步通信的方法   
    function ajaxLogin(){
     var userName = document.getElementById("userName").value;
     var userPass = document.getElementById("userPass").value;   
        //创建一个XMLHttpRequest对象
        createXMLHttpRequest();
        //将状态绑定到一个函数   
        xmlHttp.onreadystatechange=resultAjaxLogin;
        //通过GET方法向指定的URL建立服务器的调用   
        var url="ajaxLogin.action";
        xmlHttp.open("post",url,true);
        //设置请求头
        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        //发送请求
        xmlHttp.send("userName="+userName+"&userPass="+userPass);
    }   
    //这是一个用来处理状态改变的函数   
    function resultAjaxLogin(){   
        //定义一个变量用于存放 从服务器返回的响应结果   
        var responseContext="";   
        if(xmlHttp.readyState==4){
            if(xmlHttp.status==200){
                responseContext = xmlHttp.responseText;
                if(responseContext=="000000"){
                 location="intoMain.action";
                }else{
                 document.getElementById("returnMes").innerHTML=responseContext;
                }     
            }   
        }
    }
    function checkLogin()
    {
     var userName = document.getElementById("userName").value;
     var userPass = document.getElementById("userPass").value;
     var checkCode = document.getElementById("checkCode").value;
     var sureCode = document.getElementById("sureaCode").innerHTML;
     checkCode = checkCode.toLowerCase();
     sureCode = sureCode.toLowerCase();
     if(!userName||!userPass){
      document.getElementById("returnMes").innerHTML="用户名和密码不能为空!";
     } else if(checkCode != sureCode){    
      document.getElementById("returnMes").innerHTML="验证码不正确!";
     }else{
      ajaxLogin();
     }
    }
    //获取验证码
    function nextCheckCode()
    {  
     //创建一个XMLHttpRequest对象
        createXMLHttpRequest();
        //将状态绑定到一个函数   
        xmlHttp.onreadystatechange=resultRandomNo;
        //通过GET方法向指定的URL建立服务器的调用   
        var url="nextCheckCode.action";
        xmlHttp.open("post",url,true);
        //设置请求头
        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        //发送请求
        xmlHttp.send(null);  
    }
    function resultRandomNo(){   
        //定义一个变量用于存放 从服务器返回的响应结果   
        var responseContext="";   
        if(xmlHttp.readyState==4){
            if(xmlHttp.status==200){
                responseContext = xmlHttp.responseText;
                document.getElementById("sureaCode").innerHTML=responseContext;
            }   
        }
    }   
    function cleanAll()
    {
     document.getElementById("userPass").value="";
     document.getElementById("userName").value="";
     document.getElementById("checkCode").value="";
     document.getElementById("returnMes").innerHTML="";
    }
    nextCheckCode();
 </script>
  </head>
 
  <body style="margin:0 auto;">
   <div>
     <table>
      <tr>
       <td colspan="2">用户名:<input id="userName" type="text" name="userName"/></td>
      </tr>
      <tr>
       <td colspan="2">密&nbsp;&nbsp;码:<input id="userPass" type="password" name="userPass"/></td>
      </tr>
      <tr>
       <td>验证码:<input id="checkCode" type="text" name="checkCode"/></td>
       <td><a href="#" onclick="nextCheckCode();" style="text-decoration: none;"><span id="sureaCode"></span></a></td>
      </tr>
      <tr>
       <td colspan="2"><input style="width: 82px;height: 28px;margin-left:27px"  type="button" value="登陆" onclick="checkLogin();"/>
       <input style="width: 82px;height: 28px ;margin-left:40px" type="button" value="重填" onclick="cleanAll();"/></td>
      </tr>
      <tr>
    <td colspan="2"><span id="returnMes"></span></td>
    </tr>
     </table>
    </div>
  </body>
</html>
fileList.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!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">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body style="margin: 0 auto;">
<c:set var="fileLists" value="${fileLists}"></c:set>
<c:if test="${fileLists eq 'noFile'}">
    没有相关数据!
</c:if>
<c:if test="${fileLists ne 'noFile'}">
 <table align="center" style="text-align: center;">
  <tr>
   <td>文件名</td>
  </tr>
  <c:forEach items="${fileLists}" var="list">
   <tr>
    <td><a style="text-decoration: none;"
     href="downloadFile.action?paramName=${list}">${list}</a></td>
   </tr>
  </c:forEach>
 </table>
</c:if>
</body>
</html>
upload.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!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">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body style="margin:0 auto;">
<s:form action="uploadFile.action" enctype="multipart/form-data"
 method="post">
 <table align="center" style="text-align: center;">
  <tr><td>文件:<input type="file" name="upload" /></td></tr>
  <tr><td><s:submit value="上传" /></td></tr>
 </table>
</s:form>
</body>
</html>
main.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
   + request.getServerName() + ":" + request.getServerPort()
   + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>主页面</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
#left {
 float: left;
}
#main {
 width: 100%;
 height: 100%;
 align: center;
}
</style>
</head>

<body>
<div id="main">
<!-- 上侧 -->
<div><img src="<%=basePath%>images/maintop.jpg"
 style="height: 20%; width: 100%;">
<table style="position: absolute; top: 60px; left: 780px">
 <tr>
  <td>当前用户:${sessionScope.worker.wname}</td>
  <td><a href="loginOut.action"
   style="text-decoration: none; font-weight: bold; color: #CF3">退出系统</a>
  </td>
 </tr>
</table>
</div>
<!-- 左侧 --> <iframe id="left" src="<%=basePath%>pages/main/menu.jsp"
 height="75%" width="20%" frameborder="0" scrolling="auto"></iframe>
<!-- 右侧 -->
<iframe id="right" src="<%=basePath%>pages/main/welcome.jsp"
 height="75%" width="80%" frameborder="0" scrolling="auto"
 name="mainRight"></iframe>
<!-- 下侧 -->
<div
 style="text-align: right; padding: 6px; font-size: 12px; color: dark-blue; scroll: no; border-top: solid 1px #666;">
&copy; 2012xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>
</div>
</body>
</html>

menu.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
   + request.getServerName() + ":" + request.getServerPort()
   + path + "/";
%>
<html>
 <link rel="stylesheet" type="text/css"
  href="<%=basePath%>css/style.css">
 <link rel="stylesheet" type="text/css" href="<%=basePath%>css/menu.css">
 <head>
  <title>树形菜单</title>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 </head>
<body class="panel" topmargin="0" leftmargin="0">
<div id="body" style="width: 200px"><!-- OA树开始-->
<ul id="menu">
 <li class="L1"><a href="javascript:c(m01);" id="m01"><span><img
  src="<%=basePath%>images/ico/2.gif" align="absMiddle" /> 客户关系管理系统</span> </a></li>
 <ul id="m01d" style="display: none;" class="U1">
  <li class="L21"><a href="javascript:c(f01);" id="f01"><span><img
   src="<%=basePath%>images/ico/2.gif" align="absMiddle" /> 文件管理</span> </a></li>
  <ul id="f01d" style="display: none;">
   <li class="L3"><a href="fileList.action" target="mainRight"><span><img
    src="<%=basePath%>images/ico/2.gif" align="absMiddle" />文件列表</span> </a></li>
   <li class="L3"><a href="toUploadJsp.action" target="mainRight"><span><img
    src="<%=basePath%>images/ico/2.gif" align="absMiddle" />文件上传</span> </a></li>
  </ul>
 </ul>
</ul>
</div>
<div id="bottom"></div>
<script type="text/javascript" src="<%=basePath%>js/menu.js"></script>
</body>
</html>

error.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!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">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
  </head>
  <body style="margin:0 auto;">
    <img src="<%=basePath%>images/error.gif">
  </body>
</html>