1 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>simpleWebApp</display-name>
<!-- 上下文 ServletContext 初始化参数-->
<context-param>
<param-name>mainEmail</param-name>
<param-value>songguo.hit@gmail.com</param-value>
</context-param>
<!-- 一个 web应用 -->
<servlet>
<servlet-name>servletName</servlet-name>
<servlet-class>org.songuo.MyServlet</servlet-class>
<!--ServletConfig 初始化参数-->
<init-param>
<param-name>adminEmail</param-name>
<param-value>songguo.hit@gmail.com</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>servletName</servlet-name>
<url-pattern>/virtual path/to/urlPatternName</url-pattern>
</servlet-mapping>
<!--监听者类-->
<listener>
<listenerclass>org.songuo.MyServletContextListener</listenerclass>
</listener>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
2 标记tag xxx.tld
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd ">
<tlib-version>2.0</tlib-version>
<short-name>NMTOKEN</short-name>
<!--Very important URI-->
<uri>simpleTags</uri>
<tag>
<description>menu item example</description>
<name>menuItem</name>
<tag-class>org.songuo.MyTagClass</tag-class>
<!--empty/scriptless/tagdependent/JSP-->
<body-content>scriptless</body-content>
<attribute>
<name>itemValue</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
3 Servlet
package org.songuo.servlet;
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 CheckCookie extends HttpServlet {
public CheckCookie() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// ...
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
}
4 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 prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
5 Making a Web Application Compatible with Jython
<servlet>
<servlet-name>PyServlet</servlet-name>
<servlet-class>org.python.util.PyServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>python.home</param-name>
<param-value>/path/to/jython</param-value>
</init-param>
<init-param>
<param-name>python.path</param-name>
<param-value>/path/to/jython/Lib</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>PyServlet</servlet-name>
<url-pattern>*.py</url-pattern>
</servlet-mapping>