最近师傅要搞清楚tomcat的启动方式,里面放什么文件,于是打开了相应的资料开始学习。
之后在命令行执行:ant ide-eclipse下载必要的jar包,通过project structure导入jar包。
同时会发现缺少一个类,代码如下,直接拷贝到test/util文件夹下面。
package util;
import java.util.Locale;
import java.util.StringTokenizer;
public class CookieFilter {
private static final String OBFUSCATED = "[obfuscated]";
private CookieFilter() {
// Hide default constructor
}
public static String filter(String cookieHeader, String sessionId) {
StringBuilder sb = new StringBuilder(cookieHeader.length());
// Cookie name value pairs are ‘;‘ separated.
// Session IDs don‘t use ; in the value so don‘t worry about quoted
// values that contain ;
StringTokenizer st = new StringTokenizer(cookieHeader, ";");
boolean first = true;
while (st.hasMoreTokens()) {
if (first) {
first = false;
} else {
sb.append(‘;‘);
}
sb.append(filterNameValuePair(st.nextToken(), sessionId));
}
return sb.toString();
}
private static String filterNameValuePair(String input, String sessionId) {
int i = input.indexOf(‘=‘);
if (i == -1) {
return input;
}
String name = input.substring(0, i);
String value = input.substring(i + 1, input.length());
return name + "=" + filter(name, value, sessionId);
}
public static String filter(String cookieName, String cookieValue, String sessionId) {
if (cookieName.toLowerCase(Locale.ENGLISH).contains("jsessionid") &&
(sessionId == null || !cookieValue.contains(sessionId))) {
cookieValue = OBFUSCATED;
}
return cookieValue;
}
}
在server.xml的配置文件中定义了`<Context path="/HelloLuban" relaodable="false" docBase="/Users/renyong/IdeaProjects/HelloServlet/target/HelloServlet"/>
Context表示了一个应用,也可以叫一个容器。
Context是放到Host下面的,Host可以说是虚拟主机
Engine在server.xml中是用来管理Host的
原文:https://www.cnblogs.com/moxi-moxi/p/15303242.html