博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Head First Servlet and JSP 笔记(前三章)
阅读量:5017 次
发布时间:2019-06-12

本文共 1456 字,大约阅读时间需要 4 分钟。

前三章

1、servlet name

Internal name 1
foo.Servlet1
Internal name 2
foo.Servlet2
Internal name 1
/Public1
Internal name 2
/Public2

 

 

2、P80简单Servlet

package com.example.web;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;public class BeerSelect extends HttpServlet {    public void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException {    response.setContentType(“text/html”);    PrintWriter out = response.getWriter();    out.println(“Beer Selection Advice
”); String c = request.getParameter(“color”); out.println(“
Got beer color “ + c); }}

P89简单dispatch至JSP

package com.example.web;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;public class BeerSelect extends HttpServlet {    public void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException {    response.setContentType(“text/html”);    PrintWriter out = response.getWriter();    request.setAttribute(“styles”, result);    RequestDispatcher view = request.getRequestDispatcher(“result.jsp”);    view.forward(request, response); }}

 

转载于:https://www.cnblogs.com/wxy325/archive/2013/05/10/3071986.html

你可能感兴趣的文章