简体   繁体   English

如何在java Web应用程序中同时使用http服务器和应用程序服务器

[英]How to use both http server and application server in a java web application

I have some deployment model question for a Java EE web application. 我有一些Java EE Web应用程序的部署模型问题。 Currently we are deploying our web application as a WAR file in Tomcat 6. All the content is packaged with the WAR file including the static content like images, static html pages and so on. 目前,我们正在将我们的Web应用程序部署为Tomcat 6中的WAR文件。所有内容都与WAR文件一起打包,包括静态内容,如图像,静态html页面等。 But i want to deploy these static content in a HTTP server and use the Application server only for retrieving the dynamic content. 但我想在HTTP服务器中部署这些静态内容,并仅使用Application服务器来检索动态内容。 How do i split these things? 我如何拆分这些东西? Does any one has done any thing of this sort and have a good deployment model for my scenario. 是否有任何人做过这种事情,并为我的场景提供了良好的部署模型。 Help will be appreciated. 帮助将不胜感激。

Is it a good idea to make 2 WAR files one with only static content and deploy that WAR in HTTP server and the rest as a different WAR file and deploy it in the Application server? 制作2个仅包含静态内容的WAR文件是一个好主意,并将该WAR部署在HTTP服务器中,其余部分作为不同的WAR文件部署并部署在应用服务器中? But this approach will have impact on all the pages where the static content is currently referred and requires code changes which is very cumbersome since our project is Huge and the code based is very very big. 但是这种方法会对当前引用静态内容的所有页面产生影响,并且需要更改代码,因为我们的项目是巨大的,并且基于代码非常大。

Any strategy and ideas are welcome. 任何策略和想法都是受欢迎的。

This can be something interesting to do for performance reasons. 出于性能原因,这可能是有趣的事情。

You should have separate deployment scripts / deployment files to do this. 您应该有单独的部署脚本/部署文件来执行此操作。 Having multiple file/WAR/folder/scripts to deploy for one project is not an issue. 为一个项目部署多个文件/ WAR /文件夹/脚本不是问题。 We have the same thing when you have to deploy your WAR and to update your database. 当您必须部署WAR并更新数据库时,我们会有同样的事情。

I would have a WAR file and a folder with your static content to deploy. 我将有一个WAR文件和一个包含静态内容的文件夹进行部署。


Edit 编辑

Deploying the static content in a HTTP server depends on the server. 在HTTP服务器中部署静态内容取决于服务器。 If you want to use Apache on a Linux server, you have to set up a Virtual Host . 如果要在Linux服务器上使用Apache ,则必须设置虚拟主机

<VirtualHost *:80>
  # This first-listed virtual host is also the default for *:80
  ServerName www.example.com
  DocumentRoot /www/domain
</VirtualHost>

In this example, you have the a virtual host that listens on 80 port, for any IP address and for the server name www.example.com . 在此示例中,您拥有一个侦听80端口的虚拟主机,任何IP地址和服务器名称www.example.com Then this is redirected to the /www/domain path. 然后将其重定向到/www/domain路径。

You will find much more examples and configuration options in the documentation. 您将在文档中找到更多示例和配置选项。

You can not deploy WAR file into HTTP server. 您无法将WAR文件部署到HTTP服务器。 A WAR is used for Java web applications it must be deployed into application server or servlet container (like Tomcat ). WAR用于Java Web应用程序,它必须部署到应用程序服务器或servlet容器(如Tomcat )中。 I don't think that its a good idea to separate static content in a separate web application. 我不认为在单独的Web应用程序中分离静态内容是个好主意。 If this is one project it should be one web application, besides: 如果这是一个项目,它应该是一个Web应用程序,除此之外:

A WAR file has a special folder structure and contains special files in addition to JSP pages, Java servlets, Java classes, HTML pages etc. which combined forms a Web Application. WAR文件具有特殊的文件夹结构,除JSP页面,Java servlet,Java类,HTML页面等外,还包含特殊文件,这些文件组合成Web应用程序。

You can hold your static contents in your one application and there is really nothing bad about it. 您可以在一个应用程序中保存静态内容,并且实际上没有什么不好的。

If your project is very huge and has a lot of files it is no problem, you just need to use the project structure like that, that it should be easily understandable and readable and the application server or servlet container will take care of deploying as many contents as there is. 如果你的项目非常庞大并且有很多文件就没问题,你只需要使用这样的项目结构,它应该易于理解和读取,应用程序服务器或servlet容器将负责部署尽可能多的文件。有的内容。

Up to version 4, Tomcat has been quite slow in serving static content. 直到版本4,Tomcat在提供静态内容方面一直很慢。 This is why it was frequently recommended to split dynamic from static content and serve the latter using a regular web server (the book you mentioned was issued in 2002...). 这就是为什么经常建议将动态从静态内容中分离出来并使用常规Web服务器为后者服务(你提到的那本书是在2002年发布的......)。 Recent Tomcat versions do not face this problem, thus you can IMHO refrain from splitting, which can be a nightmare for both organization and security. 最近的Tomcat版本没有遇到这个问题,因此你可以免除劈开,这可能是组织和安全的噩梦。

For static resources, you might rather focus on configuring proper caching, so they will not be transferred more often than necessary. 对于静态资源,您可能更关注配置正确的缓存,因此不会更频繁地传输它们。

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

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