Servlet
来源:互联网 发布:淘宝助手如何导出图片 编辑:程序博客网 时间:2024/06/09 17:51
JSP vs. JSF
Servlets and JSP (JavaServer Pages)
Original, widely-deployed standard
Used by google.com, ebay.com, walmart.com, and thousands of other popular sites
Low level by today’s standards
Covered in this tutorial
JSF (JavaServer Faces) Version 2
An official part of Java EE as of Java EE 6
runs in any recent Java-enabled server, including Tomcat
Higher-level features: integrated Ajax support, field validation, page templating, rich third-party component libraries such as PrimeFaces, etc. Designed around the MVC architecture.
Recommended for almost all new projects
Covered later
JSP vs. JSF: When to Use Which
Servlets and JSP
For maintaining and extending existing legacy projects
Servlets only
For apps with front ends that do not use a server-side framework
E.g., HTML with jQuery and jQuery UI
Servlets primarily handle the Ajax requests from jQuery and do not build full pages
JSF 2
For almost all new projects that involve dynamic pages
Usually combined with a rich component toolkit such as PrimeFaces
See http://www.coreservlets.com/JSF-Tutorial/primefaces
Technologies Used Internally with JSF
What Servlets and JSP are All About
Servlet:
read explicit date sent by client(from data)
read implicit data sent by client(request headers)
Generate the results
Send the explicit data back to client (HTML)
Send the implicit data to client(status codes and response headers)
简单说就是实现了数据传输
这样就使的动态网页成为可能
Mainstream
最流行的是java,Google报告说超过650 million网页用JSP
Simple Servlets
@WebServlet("/test1")public class TestServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println ("<!DOCTYPE html>\n" + "<html>\n" + "<head><title>A Test Servlet</title></head>\n" + "<body bgcolor=\"#fdf5e6\">\n" + "<h1>Test</h1>\n" + "<p>Simple servlet for testing.</p>\n" + "</body></html>"); }}
Using Helper Classes ##针对书写规范
所有的java代码都要写在一个包里
要坚持OOP原则
Generating the Server Response: HTTP Response Headers
response.setHeader(String headerName,String headerValue)//rename headerresponse.setDateHeader(String name, long millisecs)
.有一些可以定义HTTP传输的 语句
Advanced Topics
初始化:确保servlet最先加载,防止加载前有请求
service:dont touch it
why: service method does other things besides just calling doGet
,
To be continued
- Servlet
- servlet
- Servlet
- servlet
- Servlet
- servlet
- servlet
- Servlet
- Servlet
- servlet
- Servlet
- servlet
- servlet
- servlet
- Servlet
- servlet
- servlet
- servlet
- 创建线程的2种方式
- Java生成大素数
- 安装MicrosoftOfficeProfessionalPlus2007和sqlserver时,遇到这个问题,已解决
- 使用angular实现双向数据绑定
- eclipse创建maven web项目报错:Could not resolve archetype org.apache.maven.archetypes:maven-archetype-weba
- Servlet
- Collections.synchronizedCollection
- java-poi-excel报表
- 拦截器与filter的区别
- A*算法(一)——简单实现
- phpstorm License Server激活
- 浅读java.util.Map及其实现类(一)
- zynq功耗
- 自动驾驶传感器 你真正了解的能有多少?