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的“門”?——所謂入門就是入門
- scala 從入門到入門+
- makefile從入門到入門
- gRPC(二)入門:Protobuf入門RPC
- 【小入門】react極簡入門React
- Android入門教程 | RecyclerView使用入門AndroidView
- 新手入門,webpack入門詳細教程Web
- Android入門教程 | Kotlin協程入門AndroidKotlin
- 《Flutter 入門經典》之“Flutter 入門 ”Flutter
- MyBatis從入門到精通(一):MyBatis入門MyBatis
- Tableau入門
- angular入門Angular
- lodash入門
- Webpack 入門Web
- golang 入門Golang
- lapis入門API
- MarkDown入門
- JSP入門JS
- UML入門
- VuePress 入門Vue
- RSA入門
- jQuery入門jQuery
- Hive 入門Hive
- scrapy入門
- Fetch 入門
- WebSocket 入門Web
- indexedDB入門Index
- Netty入門Netty
- GraphQL入門
- Serlvet入門
- ORM入門ORM
- RESTful入門REST
- Feathers 入門
- HTTP入門HTTP
- 入門WebpackWeb
- JPA入門