how2j.cn

-->
下载区
文件名 文件大小
请先登录 5m
增值内容 5m
5m
请先登录 11m
增值内容 11m
11m

解压rar如果失败,请用5.21版本或者更高版本的winrar

点击下载 winrar5.21

8分7秒
本视频采用html5方式播放,如无法正常播放,请将浏览器升级至最新版本,推荐火狐,chrome,360浏览器。 如果装有迅雷,播放视频呈现直接下载状态,请调整 迅雷系统设置-基本设置-启动-监视全部浏览器 (去掉这个选项)。 chrome 的 视频下载插件会影响播放,如 IDM 等,请关闭或者切换其他浏览器

步骤 1 : 拓扑图点亮   
步骤 2 : jsp的转译和编译   
步骤 3 : Constant   
步骤 4 : JspUtil   
步骤 5 : index_jsp.java   
步骤 6 : 比较可运行项目,快速定位问题   

增值内容,请先登录
自己写一个Tomcat, 几乎使用到了除开框架外的所有Java 技术,如多线程,Socket, J2EE, 反射,Log4j, JSoup, JUnit, Html 等一整套技术栈, 从无到有,循序渐进涵盖全部74个知识点,549个开发步骤, 为竞争高薪资职位加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
拓扑图点亮
步骤 2 :

jsp的转译和编译

edit
增值内容,请先登录
自己写一个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个开发步骤, 为竞争高薪资职位加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
JspUtil
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); } } }
步骤 6 :

比较可运行项目,快速定位问题

edit
增值内容,请先登录
自己写一个Tomcat, 几乎使用到了除开框架外的所有Java 技术,如多线程,Socket, J2EE, 反射,Log4j, JSoup, JUnit, Html 等一整套技术栈, 从无到有,循序渐进涵盖全部74个知识点,549个开发步骤, 为竞争高薪资职位加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢


HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。


问答区域    
2020-11-09 请问这个报错是什么,我对比了文件也没差异。。
LU4N1UAN




运行main方法出现异常。。救助
加载中

							
java.util.EmptyStackException
	at java.util.Stack.peek(Stack.java:102)
	at org.apache.jasper.compiler.ParserController.resolveFileName(ParserController.java:541)
	at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:185)
	at org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:119)
	at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:194)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
	at org.apache.jasper.JspC.processFile(JspC.java:1365)
	at org.apache.jasper.JspC.execute(JspC.java:359)
	at cn.how2j.diytomcat.util.JspUtil.compileJsp(JspUtil.java:43)
	at cn.how2j.diytomcat.util.JspUtil.main(JspUtil.java:23)
org.apache.jasper.JasperException: java.util.EmptyStackException
	at org.apache.jasper.JspC.execute(JspC.java:380)
	at cn.how2j.diytomcat.util.JspUtil.compileJsp(JspUtil.java:43)
	at cn.how2j.diytomcat.util.JspUtil.main(JspUtil.java:23)
Caused by: org.apache.jasper.JasperException: java.util.EmptyStackException
	at org.apache.jasper.JspC.processFile(JspC.java:1398)
	at org.apache.jasper.JspC.execute(JspC.java:359)
	... 2 more
Caused by: java.util.EmptyStackException
	at java.util.Stack.peek(Stack.java:102)
	at org.apache.jasper.compiler.ParserController.resolveFileName(ParserController.java:541)
	at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:185)
	at org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:119)
	at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:194)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
	at org.apache.jasper.JspC.processFile(JspC.java:1365)
	... 3 more


2 个答案

how2j
答案时间:2020-11-11
一般说来是中间某个改动造成的吧

LU4N1UAN
答案时间:2020-11-09
好像是因为我下载了右上角的jar包,我换回了最开始下载的就没问题了。。。



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2020-10-15 TOmcat如何解析\、编译jsp
HOW2JZkk817

工作虽然忙,但是还是,跟着站长一路写下来了,希望站长这里给出Tomcat的思路,让同学通晓下流程,然后有的放矢的去看源码,或者站长讲解下Tomcat的源码是如何解析Tomcat,咱都学到这,也不怕来个番外篇呢!各位童鞋觉得呢?




3 个答案

how2j
答案时间:2020-10-17
apache tomcat 的思路也是这样的啊, diytomcat 就是根据 apache tomcat 的思路简化后做出来的。

HOW2JZkk817
答案时间:2020-10-16
是这个意思哦

how2j
答案时间:2020-10-16
没明白呢? 你是问 apache tomcat 是如何转移和编译 jsp 的吗?



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到








提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 实践项目-DiyTomcat-jsp的转译和编译 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 578362961
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: https://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图