Head First Servlet and JSP笔记 - Ch3 MVC 实战

MVC实战

Can't just sit here and read all day

  • [ ] 1. set up development
  • [ ] 2. set up development following the servlet and jsp specs and Tomcat requirement
  • [ ] 3. Writing. Compiling. deploying and running
Web App Content
  • static content
  • JSP pages
  • Servlet classes
  • the deplyment descriptor
  • tag libraries
  • JAR files
  • Java class files

==V==

review the user's views

graph TD
    A[proj-BeerAdvisor] --> B(beerV1)
    B --> C1(web)
    B --> C2(etc)
    C1 --> |static content| C1A[form.html]
    C2 --> |the deplyment descriptor| C2A[web.xml]
form.html

    
        

Beer

select beer characteristics

color:

为什么是POST不是GET?

use the dd web.xml to map com.example.web.BeerSelect

mapping the logical name to a servlet class file P78

web.xml


  Welcome to Tomcat
  
     Welcome to Tomcat
  
  
    Ch3 Beer
    com.example.web.BeerSelect
  
  
    Ch3 Beer
    /SelectBeer.do
  

Deploying and test the opening page

graph TD
    A[tomcat] --> B(webapps)
    B --> C(beer)
    C --> |static content| D1[form.html]
    C --> D2(WEB-INF)
    D2 --> |the deplyment descriptor| E1[web.xml]

此处有测试

==C==

BeerSelect.java
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); } }

java的异常处理怎么长这样?

package 有点名字空间的意思。

import 和python很像,机制想来也不简单。

ContentType

API
graph TD
    A(javax.servlet.http.) --> B1(HttpServlet)
    A --> B2(HttpServletRequest)
    A --> B3(HttpServletResponse)
    B1 --> B1A(javax.servlet.GenericServlet)
    B1A --> C(javax.servlet.)
    B2 --> C
    B3 --> C
    C --> D1(Serverlet)
    C --> D2(ServletRequest)
    C --> D3(ServletResponse)

你可能感兴趣的:(Head First Servlet and JSP笔记 - Ch3 MVC 实战)