Jsp http server's support for JSP

Source: Internet
Author: User

1. Design Ideas

Use the jsp http server to explain the local JSP source file and generate the intermediate java source file. Then, the javac compilation tool is called to compile the java source file into a class file. The jsp http server loads and runs the classes defined in the class file.

2. Key Points of Design

1) JSP file syntax definition
2) convert JSP files to java source files
3) Compile the java source file
4) load the java class and execute the Instance Object of the class Object

3. Design implementation

1) Develop JSP File Syntax, and interpret the code as a java source file according to the JSP syntax form. Considering the simplification of JSP file interpretation, three JSP syntax forms are mainly considered in the design. In this design, the following code explains the compiled statement block in the JSP file:

 
 
  1. //Current line contain JSP compile block start flag   
  2. if(line.indexOf("<%@") >= 0)  
  3. {  
  4. //file .jsp contains compiled header   
  5. is_has_compiled_header = true;  
  6. //Those statements in same line.   
  7. if(line.indexOf("%>") >= 0) //JSP cimpile block end flag   
  8. {  
  9. int start = line.indexOf("<%@");  
  10. int end = line.indexOf("%>");  
  11. fout.println(line.substring(start + 3, end) );  
  12. }  
  13. else //Those statements no in same line.   
  14. {  
  15. while(true)  
  16. {  
  17. line = fin.readLine();  
  18. if(line == null) //The compiled header is broken   
  19. {  
  20. return (false);  
  21. }  
  22. if(line.equals("%>") == true) //JSP compiled block end flag   
  23. {  
  24. break;  
  25. }  
  26. else  
  27. {  
  28. fout.println(line); //Output the middle statements of compiled header   
  29. }  
  30. }//while(true)   
  31. }  
  32. }//if(line.indexOf("<%@") >= 0)  

The above code is to explain the compiled statement block in the JSP file into a java source file. If the compiled statement exists in one row, the compilation statement in the middle of the start and end signs of the statement is taken out to form java code. If the compiled statement block exists in multiple rows, the compiled statement line between the start and end flag lines of the statement is taken out to form java code. In this design, the code for interpreting JSP expression statements is as follows:

 
 
  1. //Current line contain JSP expression (mark "<%=" and "%>" must be in same line)   
  2. if(line.indexOf("<%=") >= 0)  
  3. {  
  4. //Get start flag position   
  5. int start = line.indexOf("<%=");  
  6. //Get end flag position   
  7. int end = line.indexOf("%>");  
  8. //Get frontal part of JSP expression block   
  9. String pre = line.substring(0, start);  
  10. //Get expression from line   
  11. String exp = line.substring(start + 3, end);  
  12. //Get back part of JSP expression block   
  13. String back = line.substring(end + 2);  
  14. //Replace character " of frontal part and back part with character '   
  15. prepre = pre.replace('\"', '\'');  
  16. backback = back.replace('\"', '\'');  
  17. //Output the new line (java statement)   
  18. fout.println("outln(\"" + pre + "\" + " + exp + " + \"" + back + "\");");  
  19. }  

In the above Code, the line where the JSP expression is located is extracted according to the first part of the expression, the expression and the last part of the expression. After the symbol is replaced, the java statement is synthesized. In this design, the parsing of JSP statement blocks is as follows:

 
 
  1. //As to JSP statements block, mark "<%" and "%>" must be in sigle line   
  2. while(true)  
  3. {  
  4. //Read next line   
  5. line = fin.readLine();  
  6. if(line == null || line.equals("%>") == true) //JSP statements block end flag is "%>"   
  7. {  
  8. break;  
  9. }  
  10. fout.println(line);  
  11. }  

In the preceding jsp http server code, extract the compiled statement lines between the statement block start flag line <%) and end flag line %> to form the java code.

  1. Analysis on CGI supported by jsp http Server
  2. Use JSP pages to generate PDF reports
  3. Step for customizing JSP labels
  4. Detailed test of JSP containers
  5. Describes the following features of jsp http Server

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.