Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize dynamic page to static page with JSP technology

Shulou Source: shulou.com Published: 2022-06-03 09:49:31 09月16日 Update

This article is about how JSP technology enables dynamic pages to static pages. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The solution of JSP technology to realize dynamic page to static page is first:

In order to understand the origin of this framework, let's first take a look at the contents of the JAVA file that the JSP parser converts the JSP code we wrote into.

Here is a JSP file, test.jsp

<% @ pagelanguage=javacontentType=text/html;charset=GB2312% > <% out.write () % > < html > < head > < body > <% = output% > < / body > < / head > < / html > the test$jsp.java content of the Java file converted by Tomcat is as follows: packageorg.apache.jsp; importjavax.servlet.*; importjavax.servlet.http.*; importjavax.servlet.jsp.*; importorg.apache.jasper.runtime.* Publicclasstest$jspextendsHttpJspBase {static {} publictestOutRedir$jsp () {}

How to realize dynamic page to static page with JSP technology

Privatestaticboolean_jspx_inited=false; publicfinalvoid_jspx_init () throwsorg.apache.jasper.runtime.JspException {} publicvoid_jspService (HttpServletRequestrequest,HttpServletResponseresponse) throwsjava.io.IOException,ServletException {JspFactory_jspxFactory=null; PageContextpageContext=null; HttpSessionsession=null; ServletContextapplication=null; ServletConfigconfig=null; JspWriterout=null; Objectpage=this; String_value=null; try {if (_ jspx_inited==false) {synchronized (this) {if (_ jspx_inited==false) {_ jspx_init () _ jspx_inited=true;} _ jspxFactory=JspFactory.getDefaultFactory (); response.setContentType (text/html;charset=GB2312); pageContext=_jspxFactory.getPageContext (this,request,response, true,8192,true); application=pageContext.getServletContext (); config=pageContext.getServletConfig (); session=pageContext.getSession (); out=pageContext.getOut (); / / to save space, I removed the comment out.write (\ r\ n) added by the interpreter / / the previous sentence is an out.write (. -- start of the file-- >); out.write (\ r\ n < html >\ r\ n < head >\ r\ n < body >\ r\ n); out.print (output); out.write (\ r\ n < / body >\ r\ n < / head >\ n < / html >\ r\ n);} catch (Throwablet) {if (outdated null buffer size out.getBufferSize ()! = 0) out.clearBuffer () If (pageContextdisabled null) pageContext.handlePageException (t);} finally {if (_ jspxFactoryinvalid null) _ jspxFactory.releasePageContext (pageContext);}

From the above code, you can clearly see how several built-in objects in JSP (out, request, response, session, pageContext, application, config, page) are generated, which can be understood by friends who understand servlet.

Thank you for reading! On "JSP technology how to achieve dynamic pages to static pages" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Tags: Pages files dynamic technical static content code more articles output good practical simple objects articles solutions friends frames comments origin Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB NVidia Docker Xiaomi OPPO Reno