如何在Apache服务器中托管spring应用程序?

时间:2014-03-13 04:47:35

标签: apache jsp spring-mvc xubuntu

我知道这很长但请耐心等待......

我正在使用xubuntu。我有一个名为 Fitness Tracker 的spring mvc项目。它有一个标准的目录结构。我在使用命令行安装的机器上也有 apache2 。我在sites-available目录中创建了一个名为 default1 的文件,其中包含以下代码:

<VirtualHost *:80>
 ServerName east.example.org
 DocumentRoot /var/www/hello/FitnessTracker/src/main/webapp/WEB-INF/jsp  
<Directory /var/www/hello/FitnessTracker/src/main/webapp/WEB-INF/jsp>
Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
</Directory>
</VirtualHost>

我的httpd.conf包含以下代码

ServerName localhost     
DirectoryIndex hello.jsp

Additioanlly,我的Spring控制器名称是Hello Controller,它包含以下代码: -

package com.pluralsight.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloController {

    @RequestMapping(value="/greeting")
    public String sayHello(Model model)
{
        model.addAttribute("greeting", "Hello World");
        return "hello";
}
}

现在当我在浏览器的地址栏中输入 east.example.org 时,我会得到hello.jsp页面,其中包含hello.jsp页面的代码(iespring mvc代码和html代码)。

我的要求是当我启动我的apache服务器并在浏览器的地址栏中输入 east.example.org 时,我想显示 greeting.html 页面。如何才能做到这一点??请注意,没有名称greeting.html的页面。但是当我们请求greeting.html页面时,Spring允许我们将请求路由到hello.jsp页面。

P.S。我在jsp页面中使用了spring标签。如何才能访问greeting.html页面?

2 个答案:

答案 0 :(得分:6)

  • Apache - 是一个Web服务器。

  • Tomcat - 是一个应用程序服务器(Servlet容器)。

Apache无法托管servlet,只能使用Tomcat,Jboss等Servlet容器。

<强>参见  Difference between the Apache HTTP Server and Apache Tomcat?

答案 1 :(得分:3)

我已经使用tomcat for java apps.使用带有apache的spring mvc有点复杂。

您配置Tomcat以运行Spring应用程序(通过配置web.xml),然后配置Tomcat以使用mod-jk与Apache连接。您必须设置apache配置文件才能了解mod-jk,并配置mod-jk.conf(参见:http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html

希望这有帮助

相关问题