时间:2021-05-20
首先,在main方法的类上添加注解:
@ServletComponentScan(basePackages = "application.servlet")示例代码:
package application; import io.seata.spring.annotation.datasource.EnableAutoDataSourceProxy;import javafx.application.Application;import javafx.fxml.FXMLLoader;import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.servlet.ServletComponentScan;import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;import org.springframework.cache.annotation.EnableCaching;import org.springframework.cloud.openfeign.EnableFeignClients; import javax.annotation.Resource; /** * @author wtl */@SpringBootApplication@EnableFeignClients@EnableCaching@EnableAutoDataSourceProxy@MapperScan(basePackages = "application.mybatis.mappers")@ServletComponentScan(basePackages = "application.servlet")public class SpringBootMain extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(SpringBootMain.class,args); Application.launch(FxmlRunner.class,args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(SpringBootMain.class); }}使用 @WebServlet(name = "DownloadServlet",urlPatterns = "/test") 进行使能Servlet:
@WebServlet(name = "DownloadServlet",urlPatterns = "/test")示例:
package application.servlet; import application.service.BiliBiliIndexService;import lombok.SneakyThrows; import javax.annotation.Resource;import javax.servlet.*;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException; /** * @author: wtl * @Date: 2020/7/5 * @Time: 18:48 * @Description: */@WebServlet(name = "DownloadServlet",urlPatterns = "/test")public class DownloadServlet extends HttpServlet { @Resource private BiliBiliIndexService biliBiliIndexService; @SneakyThrows @Override protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { String aid = httpServletRequest.getParameter("aid"); String cid = httpServletRequest.getParameter("cid"); biliBiliIndexService.getVideoStream(aid,cid,httpServletRequest,httpServletResponse); }}到此这篇关于SpringBoot里使用Servlet进行请求的实现示例的文章就介绍到这了,更多相关SpringBoot Servlet请求内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
实现Servlet程序的三种方法1.手动实现Servlet程序1.编写一个类去实现Servlet接口2.实现service方法,处理请求并响应数据示例代码://
SpringBoot中实现一个过滤器相当简单,实现javax.servlet.Filter接口即可。下面以实现一个记录接口访问日志及请求耗时的过滤器为例:1、定
过滤器简介过滤器依赖Servlet容器,属于Servlet规范的一部分。在实现上基于Servlet容器的函数回调,可以对几乎所有请求进行过滤。Filter的生命
在SpringBoot中使用Servlet,根据Servlet注册方式的不同,有两种使用方式。若使用的是Servlet3.0+版本,则两种方式均可使用;若使用的
上篇写了一个简单的Javaweb服务器实现,只能处理一些静态资源的请求,本篇文章实现的Servlet容器基于前面的服务器做了个小改造,增加了Servlet请求的