Reputation: 92745
The web application uses Java Restlet in the backend running on Google App Engine.
I want to return index.html for all url (/*).
Here, I don't want to use response.redirect
, I mean, client should not aware of redirection.
I used following code in web.xml.
<servlet>
<servlet-name>RestletServlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>com.post.PostApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>RestletServlet</servlet-name>
<url-pattern>/api/v1/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>StartPageServlet1</servlet-name>
<jsp-file>/client/index.html</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>StartPageServlet1</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
It served all /api/v1 request with Restlet. It works fine. But /* should always return index.html. How do I do it?
Upvotes: 2
Views: 4537
Reputation: 946
You can plug in a filter and inspect the Request URI and, based on it, decide whether or not to forward it to your home page:
RequestDispatcher rd = request.getRequestDispatcher("/index.html");
rd.forward(request, response);
Upvotes: 2
Reputation: 1760
You can use interceptor. For each incoming request, you can set the target page as your index.html
Upvotes: -1
Reputation: 4947
You want to serve static files only (no dynamic file, JSP file).
You may try removing all the servlets from your web.xml
and use the welcome-file-list
feature:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app PUBLIC
"-//Oracle Corporation//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
Have a try and let me know if this works.
Upvotes: 0