JSP compiled into servlet (quad) JSP and Java Line Relationship mapping

Source: Internet
Author: User

We knowJavavirtual machines only knowclassfiles to be run on a virtual machine, you must follow theclassfile format, soJSPcompiled intoservletwill need to be further compiled intoclassfile, but fromJSPfiles toJavafile again toclassfile process need to consider more things, one of the more important is debugging problems, because the syntax is different,JSPHow the logic of a row executesJavafile corresponding to theJVMAn exception or error occurred during execution to findJSPthe corresponding line, providing a friendly debugging information. Similar to theJSPafter the file name is compiledJavaThe file name should also have a mapping relationship.

In general, in order to solve the non-Javalanguage toJavathe problem of file name and line number mapping during language debugging,Java Community Processthe organization proposedJSR-45 (Debugging support for other Languages)specification, it is non-Javalanguage provides a standard mechanism for debugging. Here'sJSPis actually belong to the non-Javalanguage,JSPif you want to facilitate developer development, it has to followJSR-45specifications. In fact, we can simply say that it is to solveJSPpost-compilationJavafiles andJSPdocument correspondence, and is to provide a unified standard, so as to avoid different vendors have different implementation methods.

the core object of the JSR-45 specification is the Resource Mapping table (source map), referred to as SMAP. Here it refers to the JSP file filename and line number of the mapping table, this mapping table is stored in the class file, based on the JPDA Debugging tool, you can get the corresponding jsp file and line number through this mapping table, and prompt the developer for the JSP file information.

Then go ahead andhelloworld.jspexample to seeSMAPHow the mapping table is mapped,helloworld.jspwhen the file is compiled, it becomesHelloworld_jsp.javafiles, according toJSR-45the specification will eventually generate a map of the following, which is not intended to exploreSMAPthe entire syntax, focusing only on the part of line number mapping, that is, from*lto the*emiddle of the content, where1,10:62representshelloworld.jspfiles andHelloworld_jsp.javaThe mapping relationship is1-62,2-63,3-64,... 10-71. The same,10,3:72table when the corresponding relationship is10-72,11-73,12-74. With these mapping tables, you can easilyJavathe line number to executeJSPthe line number corresponds.

SMAP

Helloworld_jsp.java

Jsp

*s JSP

*f

+ 0 helloworld.jsp

helloworld.jsp

*l

1,10:62

10,3:72

*e

Finish it.SMAP, we already know that the generatedSMAPformat, how do I save it? Where to save it? BecauseJVMwill only passClassfile to load related information, so the only way to do that is throughclassfile includedSMAPmessage thatclassthe file format can be accompanied by information only the property sheet collection, inclassother data items in the file format have strict length, order, and format, and the attribute list collection is not strictly required, as long as the property name does not conflict with the existing attribute, anyone can go toclassthe properties of the file are written in a custom property, and the virtual opportunity automatically ignores the attributes that are not recognized, so we need to support debugging information in theJVMThis property is included with the property name heresourcedebugextensionproperty. The structure of this property is as follows, first2byte represents the index value of the name, followed by a4bytes represent the length of the property, and the last array represents the property value. Write in FormatclassfileJVMcan be identified.

Sourcedebugextension_attribute {

U2 Attribute_name_index;

U4 Attribute_length;

U1 Debug_extension[attribute_length];

}

The JSR45 Standard solves the problem of mapping between JSP and java , which makes debugging more convenient. In the Java World in order to achieve unity without losing flexibility, the basic is the Java Community Process specification and then by the vendors to implement the specification.

JSP compiled into servlet (quad) JSP and Java Line Relationship mapping

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.