What is JSP and comparison with Servlet?

Source: Internet
Author: User

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?:

 
 
  1. ﹤HTML﹥  
  2. ﹤HEAD﹥  
  3. ﹤TITLE﹥——HelloWorld!——﹤/TITLE﹥  
  4. ﹤/HEAD﹥  
  5. ﹤BODY﹥  
  6. ﹤%  
  7. out.println("﹤h1﹥Hello World!﹤/h1﹥Your name is:");  
  8. %﹥  
  9. ﹤/BODY﹥  
  10. ﹤/HTML﹥  
  11.  

What is a Servlet File?:

 
 
  1. import java.io.*;  
  2. import javax.servlet.*;  
  3. import javax.servlet.http.*;  
  4. public class HelloWorld extends HttpServlet  
  5. {  
  6. public void doGet(HttpServletRequest request, HttpServletResponse response)  
  7. throws IOException, ServletException  
  8. {  
  9. response.setContentType("text/html");  
  10. PrintWriter ut = response.getWriter();  
  11. out.println("");  
  12. out.println("");  
  13. out.println("");  
  14. out.println("");  
  15. out.println("");  
  16. out.println("Hello World! Your name is: "+ response.getParameter("name"));  
  17. out.println("");  
  18. out.println("");  
  19. }  

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.

  1. Analysis of JSP Design Mode
  2. What is JSP and its strong weakness?
  3. Five Aspects to get started with JSP
  4. JSP tutorial-traffic count JSP source code
  5. Functions and principles of several encodings in JSP and Servlet

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.