The first web application (and the servlet jsp) &

Development tools are easy programmers to write the code actually run the code is not written, but
the deployment of good code tomcat server. tomcat will automatically call the corresponding request according to the
code request processing.

Possible problems encountered:

1、

    No classes file

2、

    Can not inherit HttpServlet

 

---------------------------------------------------------------------------------------------------

Experience:

    Project name can be changed

Code:

  1, inherited HttpServlet

package com.bw.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyServlet extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        . resp.getWriter () the Write ( "Hello, Wang Yan Zhang" );
        
        System.out.println ( "Hello, Wang Yan Zhang" );
    }

}

2, web configuration

<?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation
="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0"> 
 <! - Configure servlet ->
  
   <servlet>
   
      <servlet-name>my</servlet-name>
      <servlet-class>com.bw.servlet.MyServlet</servlet-class>
   </servlet>
 <! - configuration servlet class path ->
 <! - Configuration inquiry mode ->
 <servlet-mapping>
     <servlet-name>my</servlet-name>
     <url-pattern>/my</url-pattern>
  </servlet-mapping>
</web-app>

3, run release

Guess you like

Origin www.cnblogs.com/zwyzwy/p/11923388.html