Servlet-01-入門
1.建立專案-webapp專案
2.在src下建立包,xom.liuboss.demo servlet
package com.liuboss.demo;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*@WebServlet("/ser01")*/
@WebServlet(name = "servlet01",value = {"/ser01"})
public class servlet01 extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("hello servlet!!!");
resp.getWriter().write("hello servlet!!!");
}
}
啟動tomact
瀏覽器輸出 控制檯輸出
@WebServlet("/ser01") 瀏覽器訪問路徑
-------實現servlet的三種方法
package com.liuboss.demo;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*@WebServlet("/ser01")*/
@WebServlet(name = "servlet01",value = {"/ser01"})
public class servlet01 extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("hello servlet!!!");
resp.getWriter().write("hello servlet!!!");
}
}
02
package com.liuboss.demo;
import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/ser02")
public class servlet02 extends GenericServlet {
@Override
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
System.out.println("GenericServlet hello servlet!!!");
}
}
03
package com.liuboss.demo;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
@WebServlet("/ser03")
public class servlet03 implements Servlet {
@Override
public void init(ServletConfig servletConfig) throws ServletException {
}
@Override
public ServletConfig getServletConfig() {
return null;
}
@Override
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
System.out.println("實現介面!!!");
}
@Override
public String getServletInfo() {
return null;
}
@Override
public void destroy() {
}
}
控制檯輸出頁面內容。
相關文章
- 入門入門入門 MySQL命名行MySql
- 何入CTF的“門”?——所謂入門就是入門
- 如何入CTF的“門”?——所謂入門就是入門
- gRPC(二)入門:Protobuf入門RPC
- makefile從入門到入門
- scala 從入門到入門+
- Android入門教程 | RecyclerView使用入門AndroidView
- 【小入門】react極簡入門React
- Android入門教程 | Kotlin協程入門AndroidKotlin
- 《Flutter 入門經典》之“Flutter 入門 ”Flutter
- 新手入門,webpack入門詳細教程Web
- MyBatis從入門到精通(一):MyBatis入門MyBatis
- jupyter 入門
- Poetry 入門
- Servlet入門Servlet
- CSS入門CSS
- HTML入門HTML
- redis入門Redis
- marktext入門
- Git入門Git
- WebRTC入門Web
- QT入門QT
- BitTorrent 入門
- Pandas入門
- solidity入門Solid
- Quartus 入門
- Django入門Django
- SpringCloud入門SpringGCCloud
- JVM入門JVM
- JMESPath 入門
- docker入門Docker
- MySQL入門MySql
- pthread 入門thread
- Web入門Web
- Mybatis入門MyBatis
- shell入門
- Typescript 入門TypeScript
- 入門PrometheusPrometheus