Reputation: 15320
I'm a beginner with Tomcat/Java; I have a simple web application for which I would like to show a different <welcome-file>
in web.xml
depending on whether the application is being run locally development or deployed live.
Right now I have:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
For local development I would like the <welcome-file>
in web.xml
to be index-dev.html
for development and index-live.html
for the deployed live application. Reason being I want to load different *.css
and *.js
depending on whether I'm local or live.
Any way in which I can achieve this setup?
Upvotes: 1
Views: 692
Reputation:
As an option: make a jsp file as a welcome page.
In that jsp file analyze current client location (local computer or not), and forward to the relevant page.
ADDITIONAL EDIT:
Your jsp has a predefined request
object.
Use it to get client ip, like that:
<%
String remoteIp = request.getRemoteAddr();
%>
Compare it with localhost address, which can be obtained via:
<%
InetAddress address = InetAddress.getLocalHost();
String localhostIp = address.getHostAddress();
%>
And use jsp:forward
to forward to a relevant page.
<%
// getting jsp (servlet) client ip
String remoteIp = request.getRemoteAddr();
// getting local ip
InetAddress address = InetAddress.getLocalHost();
String localhostIp = address.getHostAddress();
// checking and forwarding
if(localhostIp.equals(remoteIp)){
%>
<jsp:forward page="localhost.html"/>
<%}else{%>
<jsp:forward page="remote.html"/>
<%}%>
Additional edit:
Make sure that localhostIp contains only IP address, otherwise use String
methods to get substring with ip-address inside.
Upvotes: 1
Reputation: 1986
Live should always have a apache httpd who proxy-redirect to the tomcat.
This have multiple pros:
Regards
Upvotes: 1
Reputation: 5654
Create a header page (which is going to be included in all the pages including welcome page). Write a <c:if>
to do a simple check for you. I don't think servlet spec supports different welcome pages based of requesting machine's IP address. Ideally any web-app is suppose to be serving the same pages from where ever it is accessed
Upvotes: 1