3

I know this is long but please bear with me......

I am using xubuntu. I have a spring mvc project named Fitness Tracker.It has a standard directory structure. I also have apache2 on my machine which i installed using commandline. I have created a file named default1 inside sites-available directory which contains following code:

<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>

My httpd.conf contains following code

ServerName localhost     
DirectoryIndex hello.jsp

Additioanlly ,My spring controller name is Hello Controller and it contains following code:-

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";
}
}

Now when i type east.example.org in address bar of my browser i get hello.jsp page which contains code of hello.jsp page(i.e.spring mvc code along with html code).

My requirement is when i start my apache server and type east.example.org in address bar of my browser i want to display greeting.html page. How can this be done?? Note that there exists no page of name greeting.html. But Spring enables us to route the request to hello.jsp page when greeting.html page is requested.

P.S. I have used spring tags inside my jsp page.How can i get access to greeting.html page??

cmbuckley
  • 40,217
  • 9
  • 77
  • 91
Pratik.S
  • 470
  • 10
  • 30

2 Answers2

6
  • Apache - Is a web server.

  • Tomcat - Is an Application server(Servlet container).

Apache cannot host servlets, It can be done only with Servlet Containers like Tomcat, Jboss etc.

Refer Difference between the Apache HTTP Server and Apache Tomcat?

Community
  • 1
  • 1
KingMaker
  • 199
  • 6
3

I have used tomcat for java apps.It is kind of complicated using spring mvc with apache.

You configure Tomcat to run your Spring application (by configuring web.xml), and then you configure Tomcat to connect with Apache using mod-jk. You have to set up your apache configurations files to know about mod-jk, and you configure mod-jk.conf (See: http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html)

Hope this helps

Santino 'Sonny' Corleone
  • 1,735
  • 5
  • 25
  • 52
  • I think I was not clear in my question....let me add some details.I have built my spring mvc project in eclipse and i have installed tomcat server there. If i go through tomcat , everything is fine...the page greeting.html appears. But what i want is without running the tomcat server i want to browse to greeting.html by typing the relevant url in address bar . For this purpose i have installed apache. Did you get me?? – Pratik.S Mar 13 '14 at 05:49
  • but u cant use apache directly,u need to use tomcat and den use a connector to connect apache server...check my answer....apache is used commonly for php not java apps – Santino 'Sonny' Corleone Mar 13 '14 at 05:51
  • so let me get this .....you are saying that i can't directly use apache........ i have to get my tomcat running externally(not inside eclipse) and then connect it to apache and then host......am i right?? – Pratik.S Mar 13 '14 at 05:54
  • yup i feel like that..I havent tried java apps wid apache so cant suggest u much...but yes i feel u need to install tomcat and den apache..or else u could wait for more suggestions.. I have dont jsp web app on ubuntu,but i just installed jre and tomcat..dats it..and my web app was up.. – Santino 'Sonny' Corleone Mar 13 '14 at 05:58
  • Thanks for the explanation.......i would have liked to vote your answer but i think other answers may also come. – Pratik.S Mar 13 '14 at 06:01
  • @PratikSharma you could give an upvote ..:) :) :) try searching on google...there could be more ways – Santino 'Sonny' Corleone Mar 13 '14 at 06:01
  • 1
    He is right. You need to run your application on Tomcat or another Servlet container. You can also install Apache, for example if you want access your application on different port, loadbalance request between more Tomcat containers, point two domain names to two different applications, etc. – Robert Balent Mar 13 '14 at 10:37