[JavaEE] Getting started with jsp, getting started with javaeejsp
Servlet is good at writing java code, but it is very inconvenient to splice html.
JSP can nest java code in html, which makes it easier to display
Tomcat helps us translate jsp pages into Servlet for running and view the Directory
Tomcat directory \ work \ Catalina \ localhost \
Generate a Servlet File xxx_jsp.java. the jsp script snippets are placed in the _ jspService () method.
After creating a project using eclipse, modify the release path and directly release the project to the webapps directory of Tomcat,
In the Servers tab, delete the following items, right-click open, and select use Tomcat installation.
Jsp Declaration: <%! Several java code %>. The Code will be resolved to the member of the class.
Jsp comment: <% -- Comment content -- %>
Index. jsp
<% @ Page import = "org. apache. jasper. tagplugins. jstl. core. out "%> <% @ page import =" java. util. date "%> <% @ page language =" java "contentType =" text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
Index_jsp.java
Public final class index_jsp extends org. apache. jasper. runtime. httpJspBase implements org. apache. jasper. runtime. jspSourceDependent {public void test () {int a = 0;} 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 pageContex T; 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; charset = UTF-8"); pageContext = _ jspxFac Invalid. 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 ("\ r \ n"); out. write ("\ r \ n"); out. write ("\ r \ n"); out. write ("<! DOCTYPE html PUBLIC \ "-// W3C // dtd html 4.01 Transitional // EN \" \ "http://www.w3.org/TR/html4/loose.dtd\"> \ r \ n "); out. write ("