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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>
com.huawei.forest.CallQueueLisener
</listener-class>
</listener>
<servlet>
<servlet-name>loginServlet</servlet-name>
<servlet-class>com.huawei.forest.LoginServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>loginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<filter>
<filter-name>auditFilter</filter-name>
<filter-class>com.huawei.forest.AuditFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>auditFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
</web-app>
LoginServlet.java
package com.huawei.forest;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
super.doGet(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String username = req.getParameter("username");
String password = req.getParameter("password");
resp.setContentType("text/html;charset=gb2312");
PrintWriter out = resp.getWriter();
out.print("<html><body>");
if (username.equals("admin") && password.equals("admin"))
{
out.print(" you login in successful!..."+username);
}
else
{
out.print(" sorry,you login failed!..."+username);
}
out.print("</body></html>");
}
@Override
public void init() throws ServletException {
// TODO Auto-generated method stub
System.out.println("The servlet is init.....");
}
}
AuditFilte.java
package com.huawei.forest;
import java.io.IOException;
import java.util.Date;
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.HttpServletRequest;
public class AuditFilter implements Filter{
private FilterConfig config;
public void destroy() {
// TODO Auto-generated method stub
this.config= null;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// HttpServletRequest httpRequest = (HttpServletRequest)request;
// String username = httpRequest.getRemoteUser();
System.out.println("The request will be filted.....");
// if (username !=null)
// {
// config.getServletContext().log("User:"+username+"\nTime:"+new Date());
// }
// chain.doFilter(httpRequest, response);
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
System.out.println("the filter is starting.......");
}
}
callqueuelicenser.java
package com.huawei.forest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Timer;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class CallQueueLisener implements ServletContextListener{
public void contextDestroyed(ServletContextEvent sce) {
System.out.println("The listener is destroying.........");
}
public void contextInitialized(ServletContextEvent sce) {
System.out.println("The listener is starting.........");
// try {
// InputStream inputFile = this.getClass().getClassLoader().getResourceAsStream("vpn.properties");
// System.out.println(inputFile.toString());
// Properties pro=new Properties();
// pro.load(inputFile);
// inputFile.close();
// System.out.println(pro.getProperty("seeLocation"));
//
// File f =new File("vpn.properties");
// if (f.exists())
// {
// System.out.println("0000000");
// f.delete();
// }
// FileOutputStream fos =new FileOutputStream("1234.properties");
//
//
// pro.setProperty("NewFile", "----------------------");
// System.out.println(pro.getProperty("seeLocation"));
// pro.store(fos, null);
// fos.flush();
// fos.close();
//
// } catch (FileNotFoundException e1) {
// // TODO Auto-generated catch block
// System.out.println("------------------------");
// e1.printStackTrace();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// Timer timer = new Timer();
// timer.scheduleAtFixedRate(new MyTask(), 0, 1000);
}
}
index.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>This is just a test jsp...</title></head>
<script type="text/javascript">
window.onbeforeunload = onbeforeunload_handler;
window.onunload = onunload_handler;
function onbeforeunload_handler(){ //监听IE关闭时间
var warning="确认退出?";
return warning;
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && window.event.clientY < 0 || window.event.altKey){
alert("是关闭而非刷新");
window.event.returnValue = ""; }else{
alert("是刷新而非关闭");
}
function onunload_handler(){
var warning="谢谢光临";
alert(warning);
}
</script>
<body>
<a>This jsp is to test the IE lisener.....</a>
<form action="login" method="post">
<table>
<td><input type="text" name="username" size=15/></td>
<td><input type="password" name="password" size=15/></td>
<input type="submit" value="login"/>
<input type="reset" value="cancel"/>
</table>
</form>
</body>
</html>
分享到:
相关推荐
web.xml配置详解web.xml配置详解web.xml配置详解web.xml配置详解web.xml配置详解web.xml配置详解web.xml配置详解
全面详细讲述web.xml个元素的用途 还有实例哦
web.xml配置文件详解让开发人员更加清楚web.xml是怎么配置。以及各个配置的作用。
在web.xml中引入其他xml配置文件的步骤,含引入错误解决。
struts.xml和applicationContext.xml、web.xml的配置
web.xml 各属性作用描述 Web.xml 常用元素 <web‐app> ‐name>‐name>定义了WEB 应用的名字 <description></description> 声明WEB 应用的描述信息
Tomcat中用web.xml控制Web应用详解
spring-mvc.xml spring-mybatis.xml web.xml log4j.properties,项目中需要用到的配置文件。直接可用。
web.xml加载顺序与web.xml常用节点解析
servlet的写登陆管理系统用到的web.xml
为tomcat服务器配置https,tomcat需要设置的server.xml与web.xml配置。可以帮助小白为tomcat服务器配置https协议(域名)。
jboss-web.xml jndi.properties oracle-ds.xml三个文件,EJB+JPA 所需要的一些配置文件
web.xml dwr.xml 任何一个dwr.xml的文件都需要包含DWR DOCTYPE的声明行,。。 有几个术语有必要理解,参数叫做converted,远程Bean叫做created.如果远程Bean A有个方法A.blah(B),那么你需要为A建立一个created,为B建立...
web.xml 文件详解 web.xml 文件详解 web.xml 文件详解 web.xml 文件详解
由于经常使用Maven创建web工程所以需要使用web.xml默认模板
web.xmlweb.xmlweb.xml
JSP里web.xml实现错误处理页面的制作404,和500
ssh的web.xml的配置,很实用的哦!
web.xml 配置详解,需要的下载了。。。Web.xml常用元素和在java web规范中说明.按照listner,filter,servlet的顺序初始化
web.xml 中的listener、 filter、servlet 加载顺序及其详解