[英]Struts2 - redirect request to another application - video
我有一個struts2應用程序,我需要在其中顯示正在另一個Web應用程序中顯示的視頻。
這是顯示視頻的代碼。 該IP在Internet上無法訪問,只能在我的struts應用程序所在的服務器上訪問。
<img src="http://<ip_from_other_server/showVideo">
我需要在struts2中執行一個可以發出請求的操作,該操作將轉發到其他服務器的響應。 可能嗎?
除了struts解決方案之外,您還可以嘗試設置一個(apache)代理,它將請求重定向到您的視頻服務器。 這樣一來,您就不必擁有龐大的軟件堆棧。 示例如下: Apache mod_proxy
但是,如果您決定使用struts解決方案,請注意以下幾點:
<img href="mypicture">
-Action中對其進行粉碎,例如: Struts2 ServletResponseAware或此處的Struts流結果 如果您願意,我可以提供更多詳細信息。
我可以找到解決方案。
我使用了這個項目: https : //github.com/mitre/HTTP-Proxy-Servlet
這樣,我可以將請求重定向到其他服務器。 在客戶端視圖中,我自己的服務器正在應答請求。
在web.xml中,我輸入了以下內容:
<servlet>
<servlet-name>otherServer</servlet-name>
<servlet-class>org.mitre.dsmiley.httpproxy.URITemplateProxyServlet</servlet-class>
<init-param>
<param-name>targetUri</param-name>
<param-value>http://{_ipOtherServer}:{_portOtherServer}/myAction</param-value>
</init-param>
<init-param>
<param-name>log</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>otherServer</servlet-name>
<url-pattern>/otherServer/action/*</url-pattern>
</servlet-mapping>
另外,在struts.xml中,我必須排除所有與/ otherServer匹配的請求。
<constant name="struts.action.excludePattern" value="/otherServer/.*"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.