JSPs and HTML files in Google AppEngine
Further from my previous post, you can add JSPs and HTML files to the project, simply by placing them under the src/main/webapp directory.
So for a JSP, you want something like src/main/webapp/index.jsp:-
1 2 3 4 5 6 7 8 |
<html> <head> <head><title>Hello from DevSoup</title></head> </head> <body> <p><a href="http://www.devsoup.co.uk">DevSoup</a>'s JSP says hello @ <%= new java.util.Date().toString() %>.</p> </body> </html> |
Or you can put anything in src/main/webapp/index.html:-
1 2 3 4 5 6 7 8 9 10 11 12 |
<html> <head> <head><title>Hello from DevSoup</title></head> </head> <body> <p>Welcome! This is a static HTML file. For dynamic usage, try one of the following:-</p> <ul> <li><a href="servlet/">Servlet</a></li> <li><a href="index.jsp">JSP</a></li> </ul> </body> </html> |
I also changed the deployment descriptor in src/main/webapp/WEB-INF/web.xml so requests under the servlet directory are handled by my servlet, and the other files are handled by the default servlet.:-
1 2 3 4 5 6 7 8 9 10 11 |
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"> <servlet> <servlet-name>devsoup-gae_helloworld</servlet-name> <servlet-class>uk.co.devsoup.gae.helloworld.Main</servlet-class> </servlet> <servlet-mapping> <servlet-name>devsoup-gae_helloworld</servlet-name> <url-pattern>/servlet/*</url-pattern> </servlet-mapping> </web-app> |
<servlet-mapping>
<servlet-name>devsoup-gae_helloworld</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
</web-app>
You can then deploy this and it should work.