Websphere 应用程序服务器:servlet 部署描述符的 web.xml 位置以及过滤器 servlet 将记录的日志文件位置

发布于 2024-11-25 19:08:45 字数 1811 浏览 0 评论 0原文

我在 Tomcat 中部署了一个过滤器,它记录所有 servlet 的 URL 和请求参数。 现在我想在 Websphere 应用程序服务器中部署相同的内容。 1. 在哪里复制我的过滤器类文件? 2. web.xml 的位置,我必须在其中输入 Filter 类部署描述符 xml 标记。 3. 过滤器类将在其中记录 URL 和请求参数的日志文件。

下面是我的 Filter 类的代码。

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.text.SimpleDateFormat;

import java.util.Date;

public class T24RequestTime implements Filter {

  private FilterConfig config = null;

  Date dt = new Date();

  public void init(FilterConfig config) throws ServletException {

    this.config = config;

  }

  public void destroy() {

    config = null;

  }

  public void doFilter(ServletRequest request, ServletResponse response,

                     FilterChain chain) throws IOException, ServletException {

    long before = System.currentTimeMillis();

    chain.doFilter(request, response);

    long after = System.currentTimeMillis();

    SimpleDateFormat dateFormat = new SimpleDateFormat("[dd/MMM/yyyy:HH:mm:ss]");

    String endDate = dateFormat.format(new Date());    

    String name = "";

    if (request instanceof HttpServletRequest) {

      name = ((HttpServletRequest)request).getRequestURI();

    }

    config.getServletContext().log("T24: !Date-Time: !"+endDate+ "! Total Elapsed Time: !" +         (after - before) + "!ms!"+"! Company: !"+((HttpServletRequest)request).getParameter("companyId")+"! User: !"+((HttpServletRequest)request).getParameter("user")+"! Version: !"+((HttpServletRequest)request).getParameter("version")+"! Application: !"+((HttpServletRequest)request).getParameter("application")+"! Routine Name: !"+((HttpServletRequest)request).getParameter("routineName")+"! Timing: !"+((HttpServletRequest)request).getParameter("timing")+"! URL: !"+ name );

    System.out.println("fsfsfsd");

  }
}

I have deployed a filter in Tomcat which logs the URLs and a request parameter for all servlets.
Now I want to deploy the same in Websphere Application server.
1. Where to copy my Filter Class file?
2. Location of web.xml in which I have to enter the Filter class deployment descriptor xml tags.
3. The log file in which the filter class will log the URLs and request parameters.

Below is the code of my Filter class.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.text.SimpleDateFormat;

import java.util.Date;

public class T24RequestTime implements Filter {

  private FilterConfig config = null;

  Date dt = new Date();

  public void init(FilterConfig config) throws ServletException {

    this.config = config;

  }

  public void destroy() {

    config = null;

  }

  public void doFilter(ServletRequest request, ServletResponse response,

                     FilterChain chain) throws IOException, ServletException {

    long before = System.currentTimeMillis();

    chain.doFilter(request, response);

    long after = System.currentTimeMillis();

    SimpleDateFormat dateFormat = new SimpleDateFormat("[dd/MMM/yyyy:HH:mm:ss]");

    String endDate = dateFormat.format(new Date());    

    String name = "";

    if (request instanceof HttpServletRequest) {

      name = ((HttpServletRequest)request).getRequestURI();

    }

    config.getServletContext().log("T24: !Date-Time: !"+endDate+ "! Total Elapsed Time: !" +         (after - before) + "!ms!"+"! Company: !"+((HttpServletRequest)request).getParameter("companyId")+"! User: !"+((HttpServletRequest)request).getParameter("user")+"! Version: !"+((HttpServletRequest)request).getParameter("version")+"! Application: !"+((HttpServletRequest)request).getParameter("application")+"! Routine Name: !"+((HttpServletRequest)request).getParameter("routineName")+"! Timing: !"+((HttpServletRequest)request).getParameter("timing")+"! URL: !"+ name );

    System.out.println("fsfsfsd");

  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

朕就是辣么酷 2024-12-02 19:08:45

在 WebSphere 中,您确实应该部署整个 EAR 文件。部署后不要尝试修改部署描述符(web.xml 等)。更改部署描述符后,您应该构建并重新部署。相信我,其他一切都行不通,或者至少会在操作中产生麻烦。

默认情况下,WebSphere 会将 /logs/ 记录到 SystemOut.logtrace.txt 中。日志记录配置取决于您的环境。

In WebSphere you should really deploy the whole EAR file. Do not try to modify the deployment descriptors (web.xml, etc.) after deployment. After changing a deployment descriptor you should build and redeploy. Believe me, everything else will not work or at least generate trouble in operations.

Per default WebSphere logs to <profilepath>/logs/<servername> into SystemOut.log or trace.txt. Logging configuration depends on your environment.

白馒头 2024-12-02 19:08:45
  1. 您的过滤器类文件通常应与其他应用程序类一起部署到您的 WAR 文件中。如果您想要将此过滤器应用于多个应用程序而不部署到每个应用程序,请参阅 此有关使用常见应用程序文件的文章
  2. 与 Tomcat 不同,WebSphere 没有共享/全局 web.xml,因此您必须在每个 WAR 的 web.xml 中配置过滤器。
  1. Your filter class file should usually be deployed into your WAR file along with the other application classes. If you want to apply this filter to multiple applications without deploying to each, see this article on using common application files.
  2. Unlike Tomcat, WebSphere doesn't have a shared/global web.xml, so you'll have to configure the filter in each WAR's web.xml.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文