Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

第 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);
	}

}