步骤 1 : 拓扑图点亮 步骤 2 : jsp的转译和编译 步骤 3 : Constant 步骤 4 : JspUtil 步骤 5 : index_jsp.java 步骤 6 : 比较可运行项目,快速定位问题
增值内容,请先登录
自己写一个Tomcat, 几乎使用到了除开框架外的所有Java 技术,如多线程,Socket, J2EE, 反射,Log4j, JSoup, JUnit, Html 等一整套技术栈, 从无到有,循序渐进涵盖全部74个知识点,549个开发步骤, 为竞争高薪资职位加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
自己写一个Tomcat, 几乎使用到了除开框架外的所有Java 技术,如多线程,Socket, J2EE, 反射,Log4j, JSoup, JUnit, Html 等一整套技术栈, 从无到有,循序渐进涵盖全部74个知识点,549个开发步骤, 为竞争高薪资职位加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
自己写一个Tomcat, 几乎使用到了除开框架外的所有Java 技术,如多线程,Socket, J2EE, 反射,Log4j, JSoup, JUnit, Html 等一整套技术栈, 从无到有,循序渐进涵盖全部74个知识点,549个开发步骤, 为竞争高薪资职位加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package cn.how2j.diytomcat.util;
import cn.hutool.system.SystemUtil;
import java.io.File;
public class Constant {
public static final int CODE_200 = 200;
public static final int CODE_302 = 302;
public static final int CODE_404 = 404;
public static final int CODE_500 = 500;
public static final String response_head_200 =
"HTTP/1.1 200 OK\r\n" +
"Content-Type: {}{}" +
"\r\n\r\n";
public static final String response_head_200_gzip =
"HTTP/1.1 200 OK\r\nContent-Type: {}{}\r\n" +
"Content-Encoding:gzip" +
"\r\n\r\n";
public static final String response_head_404 =
"HTTP/1.1 404 Not Found\r\n" +
"Content-Type: text/html\r\n\r\n";
public static final String response_head_500 = "HTTP/1.1 500 Internal Server Error\r\n"
+ "Content-Type: text/html\r\n\r\n";
public static final String textFormat_404 =
"<html><head><title>DIY Tomcat/1.0.1 - Error report</title><style>" +
"<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} " +
"H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} " +
"H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} " +
"BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} " +
"B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} " +
"P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}" +
"A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> " +
"</head><body><h1>HTTP Status 404 - {}</h1>" +
"<HR size='1' noshade='noshade'><p><b>type</b> Status report</p><p><b>message</b> <u>{}</u></p><p><b>description</b> " +
"<u>The requested resource is not available.</u></p><HR size='1' noshade='noshade'><h3>DiyTocmat 1.0.1</h3>" +
"</body></html>";
public static final String textFormat_500 = "<html><head><title>DIY Tomcat/1.0.1 - Error report</title><style>"
+ "<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} "
+ "H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} "
+ "H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} "
+ "BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} "
+ "B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} "
+ "P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}"
+ "A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> "
+ "</head><body><h1>HTTP Status 500 - An exception occurred processing {}</h1>"
+ "<HR size='1' noshade='noshade'><p><b>type</b> Exception report</p><p><b>message</b> <u>An exception occurred processing {}</u></p><p><b>description</b> "
+ "<u>The server encountered an internal error that prevented it from fulfilling this request.</u></p>"
+ "<p>Stacktrace:</p>" + "<pre>{}</pre>" + "<HR size='1' noshade='noshade'><h3>DiyTocmat 1.0.1</h3>"
+ "</body></html>";
public final static File webappsFolder = new File(SystemUtil.get("user.dir"),"webapps");
public final static File rootFolder = new File(webappsFolder,"ROOT");
public static final File confFolder = new File(SystemUtil.get("user.dir"),"conf");
public static final File serverXmlFile = new File(confFolder, "server.xml");
public static final File webXmlFile = new File(confFolder, "web.xml");
public static final File contextXmlFile = new File(confFolder, "context.xml");
public static final String workFolder = SystemUtil.get("user.dir") + File.separator + "work";
}
增值内容,请先登录
自己写一个Tomcat, 几乎使用到了除开框架外的所有Java 技术,如多线程,Socket, J2EE, 反射,Log4j, JSoup, JUnit, Html 等一整套技术栈, 从无到有,循序渐进涵盖全部74个知识点,549个开发步骤, 为竞争高薪资职位加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package cn.how2j.diytomcat.util;
import java.io.File;
import org.apache.jasper.JasperException;
import org.apache.jasper.JspC;
import cn.how2j.diytomcat.catalina.Context;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
public class JspUtil {
private static final String javaKeywords[] = { "abstract", "assert", "boolean", "break", "byte", "case", "catch",
"char", "class", "const", "continue", "default", "do", "double", "else", "enum", "extends", "final",
"finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long",
"native", "new", "package", "private", "protected", "public", "return", "short", "static", "strictfp",
"super", "switch", "synchronized", "this", "throw", "throws", "transient", "try", "void", "volatile",
"while" };
public static void main(String[] args) {
try {
Context context = new Context("/javaweb", "d:/project/javaweb/web", null,true);
File file = new File("d:/project/javaweb/web/index.jsp");
compileJsp(context,file);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void compileJsp(Context context, File file) throws JasperException {
String subFolder;
String path = context.getPath();
if ("/".equals(path))
subFolder = "_";
else
subFolder = StrUtil.subAfter(path, '/', false);
String workPath = new File(Constant.workFolder, subFolder).getAbsolutePath() + File.separator;
String[] args = new String[] { "-webapp", context.getDocBase().toLowerCase(), "-d", workPath.toLowerCase(), "-compile", };
JspC jspc = new JspC();
jspc.setArgs(args);
jspc.execute(file);
}
public static final String makeJavaIdentifier(String identifier) {
return makeJavaIdentifier(identifier, true);
}
public static final String makeJavaIdentifier(String identifier, boolean periodToUnderscore) {
StringBuilder modifiedIdentifier = new StringBuilder(identifier.length());
if (!Character.isJavaIdentifierStart(identifier.charAt(0))) {
modifiedIdentifier.append('_');
}
for (int i = 0; i < identifier.length(); i++) {
char ch = identifier.charAt(i);
if (Character.isJavaIdentifierPart(ch) && (ch != '_' || !periodToUnderscore)) {
modifiedIdentifier.append(ch);
} else if (ch == '.' && periodToUnderscore) {
modifiedIdentifier.append('_');
} else {
modifiedIdentifier.append(mangleChar(ch));
}
}
if (isJavaKeyword(modifiedIdentifier.toString())) {
modifiedIdentifier.append('_');
}
return modifiedIdentifier.toString();
}
public static final String mangleChar(char ch) {
char[] result = new char[5];
result[0] = '_';
result[1] = Character.forDigit((ch >> 12) & 0xf, 16);
result[2] = Character.forDigit((ch >> 8) & 0xf, 16);
result[3] = Character.forDigit((ch >> 4) & 0xf, 16);
result[4] = Character.forDigit(ch & 0xf, 16);
return new String(result);
}
public static boolean isJavaKeyword(String key) {
int i = 0;
int j = javaKeywords.length;
while (i < j) {
int k = (i + j) / 2;
int result = javaKeywords[k].compareTo(key);
if (result == 0) {
return true;
}
if (result < 0) {
i = k + 1;
} else {
j = k;
}
}
return false;
}
public static String getServletPath(String uri, String subFolder) {
String tempPath = "org/apache/jsp/" + uri;
File tempFile = FileUtil.file(Constant.workFolder, subFolder, tempPath);
String fileNameOnly = tempFile.getName();
String classFileName = JspUtil.makeJavaIdentifier(fileNameOnly);
File servletFile = new File(tempFile.getParent(), classFileName);
return servletFile.getAbsolutePath();
}
public static String getServletClassPath(String uri, String subFolder) {
return getServletPath(uri, subFolder) + ".class";
}
public static String getServletJavaPath(String uri, String subFolder) {
return getServletPath(uri, subFolder) + ".java";
}
public static String getJspServletClassName(String uri, String subFolder) {
File tempFile = FileUtil.file(Constant.workFolder, subFolder);
String tempPath = tempFile.getAbsolutePath() + File.separator;
String servletPath = getServletPath(uri, subFolder);
String jsServletClassPath = StrUtil.subAfter(servletPath, tempPath, false);
String jspServletClassName = StrUtil.replace(jsServletClassPath, File.separator, ".");
return jspServletClassName;
}
}
增值内容,请先登录
自己写一个Tomcat, 几乎使用到了除开框架外的所有Java 技术,如多线程,Socket, J2EE, 反射,Log4j, JSoup, JUnit, Html 等一整套技术栈, 从无到有,循序渐进涵盖全部74个知识点,549个开发步骤, 为竞争高薪资职位加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
/*
* Generated by the Jasper component of Apache Tomcat
* Version: JspCServletContext/1.0
* Generated at: 2020-05-13 03:08:11 UTC
* Note: The last modified time of this file was set to
* the last modified time of the source file after
* generation to assist with modification tracking.
*/
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
private static final javax.servlet.jsp.JspFactory _jspxFactory =
javax.servlet.jsp.JspFactory.getDefaultFactory();
private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;
private volatile javax.el.ExpressionFactory _el_expressionfactory;
private volatile org.apache.tomcat.InstanceManager _jsp_instancemanager;
public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
return _jspx_dependants;
}
public javax.el.ExpressionFactory _jsp_getExpressionFactory() {
if (_el_expressionfactory == null) {
synchronized (this) {
if (_el_expressionfactory == null) {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
}
}
}
return _el_expressionfactory;
}
public org.apache.tomcat.InstanceManager _jsp_getInstanceManager() {
if (_jsp_instancemanager == null) {
synchronized (this) {
if (_jsp_instancemanager == null) {
_jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
}
}
}
return _jsp_instancemanager;
}
public void _jspInit() {
}
public void _jspDestroy() {
}
public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException {
final javax.servlet.jsp.PageContext pageContext;
javax.servlet.http.HttpSession session = null;
final javax.servlet.ServletContext application;
final javax.servlet.ServletConfig config;
javax.servlet.jsp.JspWriter out = null;
final java.lang.Object page = this;
javax.servlet.jsp.JspWriter _jspx_out = null;
javax.servlet.jsp.PageContext _jspx_page_context = null;
try {
response.setContentType("text/html");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write("hello jsp@javaweb");
} catch (java.lang.Throwable t) {
if (!(t instanceof javax.servlet.jsp.SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try {
if (response.isCommitted()) {
out.flush();
} else {
out.clearBuffer();
}
} catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
else throw new ServletException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
}
增值内容,请先登录
自己写一个Tomcat, 几乎使用到了除开框架外的所有Java 技术,如多线程,Socket, J2EE, 反射,Log4j, JSoup, JUnit, Html 等一整套技术栈, 从无到有,循序渐进涵盖全部74个知识点,549个开发步骤, 为竞争高薪资职位加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
问答区域
2020-11-09
请问这个报错是什么,我对比了文件也没差异。。
2 个答案
how2j 跳转到问题位置 答案时间:2020-11-11 一般说来是中间某个改动造成的吧
LU4N1UAN 跳转到问题位置 答案时间:2020-11-09 好像是因为我下载了右上角的jar包,我换回了最开始下载的就没问题了。。。
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2020-10-15
TOmcat如何解析\、编译jsp
3 个答案
how2j 跳转到问题位置 答案时间:2020-10-17 apache tomcat 的思路也是这样的啊, diytomcat 就是根据 apache tomcat 的思路简化后做出来的。
HOW2JZkk817 跳转到问题位置 答案时间:2020-10-16 是这个意思哦
how2j 跳转到问题位置 答案时间:2020-10-16 没明白呢? 你是问 apache tomcat 是如何转移和编译 jsp 的吗?
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|