在 Tomcat 中触发内部 ServletRequest

编程入门 行业动态 更新时间:2024-10-09 22:18:11
本文介绍了在 Tomcat 中触发内部 ServletRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在使用 Quartz 为 Web 应用程序安排后台任务.其中一些任务只是针对同一个网络应用发出请求.

I am using Quartz to schedule background tasks for a web application. Some of these tasks just fire off requests against the same web application.

我想避免依赖于任何类型的网络设置(例如,如果在数据中心内发出请求,使用我自己的域名的请求可能无法正确路由).是否有 Java API 来触发 ServletRequest 并让 Tomcat 在内部处理它(不涉及任何实际的 HTTP)?

I want to avoid depending on any kind of network settings (for example a request with my own domain name might not be routed properly if made from within the data center). Is there a Java API to fire off a ServletRequest and have it handled by Tomcat internally (without any actual HTTP involved)?

我仍然想将工作包装成一个 Servlet 请求,而不是直接调用后台任务的 Java 代码,这样我就可以回到常规 HTTP 请求作为配置选项.

I still want to wrap the work into a Servlet request rather than calling the Java code for the background tasks directly, so that I can go back to regular HTTP request as a configuration option.

Tomcat 特定的代码是可以接受的.

Tomcat-specific code is acceptable.

推荐答案

你想从那些计划任务中得到什么?标准的 Web 服务器行为是获取 HTTP 请求并使用特定数据进行响应.我假设您的任务不需要那个,即您只想执行代码库驻留在网络应用程序中的特定处理.

What do you want to get from that scheduled tasks? Standard web-server behavior is to get HTTP request and respond with particular data. I assume that your tasks don't need that, i.e. you want just to perform particular processing which codebase resides within the web-application.

如果上述假设是正确的,您可以将 servlet/jsp 逻辑与业务处理逻辑分离,并直接从您的计划任务中调用业务逻辑层类.

If the assumption above is correct you can just decouple servlet/jsp logic from business-processing logic and call business-logic layer classes directly from your scheduled tasks.

这篇关于在 Tomcat 中触发内部 ServletRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 03:59:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1388914.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Tomcat   ServletRequest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!