Websphere 应用程序服务器:servlet 部署描述符的 web.xml 位置以及过滤器 servlet 将记录的日志文件位置
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 WebSphere 中,您确实应该部署整个 EAR 文件。部署后不要尝试修改部署描述符(web.xml 等)。更改部署描述符后,您应该构建并重新部署。相信我,其他一切都行不通,或者至少会在操作中产生麻烦。
默认情况下,WebSphere 会将
/logs/
记录到SystemOut.log
或trace.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>
intoSystemOut.log
ortrace.txt
. Logging configuration depends on your environment.