简体   繁体   English

Struts 2:是否可以在拦截器中获取html内容?

[英]Struts 2 : Is it possible to get html content in interceptor?

I'd like to know if it is possible to get html content send to browser in interceptor ? 我想知道是否有可能在拦截器中将html内容发送到浏览器? My aim is to get one div content and convert it in pdf. 我的目标是获取一个div内容并将其转换为pdf。 Thanks 谢谢

I am not sure about your question,and moreover if they are with respect to some specific actions i do not favor the approach to handle such use-case in interceptors,since in general interceptors are more towards cross-cutting concern and they are applied to whole stack you have configured rather than for some particular action. 我不确定您的问题,而且我不确定您是否针对某些特定操作,因此我不赞成在拦截器中处理此类用例的方法,因为一般而言,拦截器更倾向于跨领域关注,并且它们已应用于您已经配置了整个堆栈,而不是执行某些特定操作。

Additionally the data will not be thread safe if its specific to action, being said that you can still have access to the parameters send to your action class from UI 此外,如果数据特定于操作,则该数据将不是线程安全的,也就是说,您仍然可以访问从UI发送到您的操作类的参数

Map parameters = ActionContext.getContext().getParameters();

The request parameters are available on the ActionContext instance, which is made available via ThreadLocal. 请求参数在ActionContext实例上可用,该实例通过ThreadLocal可用。

You can create your own interceptor and can get access to the parameters as follow 您可以创建自己的拦截器,并可以按以下方式访问参数

actionInvocation.getInvocationContext().getParameters();

above line will give you all request parameters from jsp page on which you have called any action. 上面的代码行将为您提供您在jsp页面上调用了所有操作的所有请求参数。

Hope that will help you. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM