Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Search | Email

第 3 章 Servlet

目录

3.1. Example
3.2. Session
3.3. HttpServletRequest
3.4. Filter
3.4.1. web.xml
3.4.2. Filter 类
3.5. Listener
3.5.1. web.xml
3.5.2. NewsListener 类
3.5.3. NewsTask 类
3.5.4. JSP 中心显示
3.6. JSP
3.6.1. 注释
3.6.2. pageContext
3.6.2.1. queryString
3.6.3. request
3.6.3.1. Form
3.6.4.
3.6.4.1. sendRedirect
3.6.5. cookie
3.6.6. session
3.6.7. page
3.6.7.1. Session
3.6.8. trimDirectiveWhitespaces
3.6.9. include
3.6.10. jsp
3.6.10.1. jsp:forward
3.6.11. error-page
3.6.12. JSP 编程
3.6.12.1. 随机数
3.6.13. FAQ
3.6.13.1. http://www.netkiller.cn/test.html;jsessionid=7D25CE666FF437F2094AA945E97CEB37
3.7. JSTL(JavaServer Pages Standard Tag Library)
3.7.1. c:set
3.7.1.1. c:remove
3.7.2. c:out
3.7.3. c:url
3.7.4. c:redirect
3.7.5. c:import
3.7.6. c:if
3.7.6.1. boolean
3.7.7. c:choose
3.7.8. c:forEach
3.7.8.1. List 处理
3.7.8.2. Map 处理
3.7.9. empty 判断是否为空
3.7.10. JSTL fmt Tag setBundle Example
3.7.10.1. fmt:message
3.7.10.1.1. Language Package
3.7.10.1.2. fmt:message 变量
3.7.10.2.
3.8. WebSocket
3.8.1. Server
3.8.2. Client

3.1. Example

package cn.netkiller.helloworld;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HelloWorld
 */
@WebServlet("/HelloWorld")
public final class HelloWorld extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HelloWorld() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Servlet#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath()).append("<br></br> Helloworld");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}