What JSP? What is the relationship with Servlet? JSP is an extension of Servlets technology. Everything that JSP can do can be done by Servlet. However, JSP allows you to easily mix Java code with the HTML language and complete powerful functions. This allows you to easily read the code and view the program execution results in a browser.
The following is an example.
What is a JSP file?:
- ﹤HTML﹥
- ﹤HEAD﹥
- ﹤TITLE﹥——HelloWorld!——﹤/TITLE﹥
- ﹤/HEAD﹥
- ﹤BODY﹥
- ﹤%
- out.println("﹤h1﹥Hello World!﹤/h1﹥Your name is:");
- %﹥
- ﹤/BODY﹥
- ﹤/HTML﹥
-
What is a Servlet File?:
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- public class HelloWorld extends HttpServlet
- {
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException
- {
- response.setContentType("text/html");
- PrintWriter ut = response.getWriter();
- out.println("");
- out.println("");
- out.println("");
- out.println("");
- out.println("");
- out.println("Hello World! Your name is: "+ response.getParameter("name"));
- out.println("");
- out.println("");
- }
- }
The output results of the above two programs are exactly the same, so we can see what JSP is and Its Relationship with Servlet is clear at a glance. JSP can implement the general functions of Servlet, the JSP program is easier to read and write. JSP and Servlet have different characteristics and different application scenarios. When Using JSP and Servlet, programmers can choose based on their own needs.
- Analysis of JSP Design Mode
- What is JSP and its strong weakness?
- Five Aspects to get started with JSP
- JSP tutorial-traffic count JSP source code
- Functions and principles of several encodings in JSP and Servlet