收集Tomcat使用的坑

1.tomcat6支持ssi

ssi,涉及到的html文件的后缀名通常为*.shtml,相关参考 http://www.divcss5.com/html/h59.shtml

http://www.cnblogs.com/naruto469/p/3938980.html

貌似没法嵌套着支持,只能支持一层?使用的filter方法。

http://tomcat.apache.org/tomcat-6.0-doc/ssi-howto.html

 

目前直接将进一层的ssi直接复制粘贴过去。

似乎更常见是nginx+tomcat的解决方案,静态html放在nginx容器中,java的class文件存放在tomcat容器中

目前还没有做此尝试,可以参考http://www.jbxue.com/article/12850.html

 

2.tomcat的根目录

目前实践。原封的什么都不改动,将原来的ROOT文件目录打包备份为ROOT.tar.gz,同时将自己的web.war包重命名为ROOT.war文件,放在webapps目录下,重启tomcat。

配置默认index,目前是在tomcat的ROOT目录之下,放置一个index.jsp文件。问了使得访问域名时候可以直接跳转到想设置的首页,可以通过在index.jsp中写js脚本来进行跳转windows.location.href=“”

参考http://blog.csdn.net/tfy1332/article/details/22854387

参考http://wiki.apache.org/tomcat/HowTo

 

 

 

3.tomcat 配置远程debug

增加setenv.sh

#!/bin/sh
#to enable romete debug, the port is currently 8000
CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

 

4.tomcat使用时增加filter

增加filter是在所在web工程的web.xml中配置。filter本身是一种特殊的servlet。

servlet是没有main方法的,不能独立的执行,需要容器来执行。servlet通常会是单例的,多线程工作(?来源及准确性)。

下图是增加filter之后的网络请求流程。

参考了http://otndnld.oracle.co.jp/document/products/as10g/101300/B25221_03/web.1013/b14426/filters.htm

Description of invfilt.gif follows

 

在web.xml中配置时,通常如下配置

 1     <filter>
 2         <filter-name>perfStatisticsFilter</filter-name>
 3         <filter-class>com.xxx.interceptors.PerfStatisticsFilter</filter-class>
 4     </filter>
 5     <filter-mapping>
 6         <filter-name>perfStatisticsFilter</filter-name>
 7         <url-pattern>/*</url-pattern>
 8         <dispatcher>REQUEST</dispatcher>
 9         <dispatcher>FORWARD</dispatcher>
10         <dispatcher>INCLUDE</dispatcher>
11     </filter-mapping>

其中的filter-mapping部分,用来匹配该serveltrequest是否需要经由此filter处理。dispatcher:如果没有指定任何< dispatcher >元素,默认REQUEST。filter将会处理直接从客户端过来的request,(在处理过程中可以返回,也可以filterChain.doFilter(req, rep);)通过forward过来的request,通过include过来的request和通过<error-page>过来的request。

 1 public class PerfStatisticsFilter implements Filter{
 2     
 3     private FilterConfig filterConfig;
 4     
 5     @Override
 6     public void destroy() {
 7         // TODO Auto-generated method stub
 8         filterConfig = null;
 9     }
10 
11     @Override
12     public void doFilter(ServletRequest req, ServletResponse rep,
13             FilterChain filterChain) throws IOException, ServletException {
14         // TODO Auto-generated method stub
15         StopWatch stopWatch = new Log4JStopWatch();
16         stopWatch.start();    
17         filterChain.doFilter(req, rep);
18         if(req instanceof HttpServletRequest){
19             String path = ((HttpServletRequest)req).getRequestURI();
20             //String queryString = ((HttpServletRequest)request).getQueryString();
21             stopWatch.stop(path);
22         }
23         else{
24             stopWatch.stop("UnRecognized_TAG");
25         }
26     }
27 
28     @Override
29     public void init(FilterConfig filterConfig) throws ServletException {
30         // TODO Auto-generated method stub
31         this.filterConfig = filterConfig;
32     }
33 
34 }

 

 

5.tomcat服务器处理流程

java 构建服务器主要是用java.net.socket和java.net.serversocket来通信。

主要核心组件是Connector和Container两个,Connector会建request/response对象,管理线程池,从而响应http请求。具体servlet处理部分是在Container部分。

参考http://www.ibm.com/developerworks/cn/java/j-lo-tomcat1/index.html

 

 

tomcat配置访问日志

http://hanxin0311.iteye.com/blog/1026636

org.apache.catalina.valves.AccessLogValve

posted on 2015-02-27 14:30  majia1949  阅读(148)  评论(0)    收藏  举报

导航