分类: Java
2006-11-18 19:14:42
web.xml和taglib
作servlet映射是个讨厌的工作,当你接收别的项目的时候,这个项目的servlet怎么用可能比较麻烦,可能当时web.xml的映射找不到了,这时怎么办呢?
看这个文件
package com.xdocletbook.blog.servlet;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
/**
* @web.servlet
* name="HomePage"
* @web.servlet-init-param
* name="LogLevel"
* value="{LOG_LEVEL}"
* @web.servlet-mapping
* url-pattern="/home"
*
* @web.security-role
*role-name="{OwnerRole}"
* @web.security-role-ref
*role-name="blogowner"
*role-link="{OwnerRole}"
*/
public class HomePageServlet
extends HttpServlet {
private static Logger LOGGER = Logger.getLogger(HomePageServlet.class);
public void init() throws ServletException {
String logLevel = getInitParameter("LogLevel");
if (logLevel != null && logLevel.length() > 0) {
LOGGER.setLevel(Level.toLevel(logLevel));
}
}
public void service(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
LOGGER.debug("Displaying home page");
request.getRequestDispatcher("jsp/home.jsp").forward(request, response);
}
}
然后配置build.xml增加如下任务
然后运行ant generate-web
结果就是这样一个web.xml