I am trying to redirect to an HTML page from a servlet. For debugging, I have minimal amount of code in my servlet, HTML page and in web.xml
I can load HTML page fine in browser without the servlet. But when I try to redirect to the same page from a servlet, only a blank page is rendered. No error is displayed. Following is the relevant code.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>name</display-name>
<listener>
<listener-class>net.semandex.salsa.webapp.SalsaWebApp</listener-class>
</listener>
<servlet>
<description>
</description>
<display-name>SalsaValidationServlet</display-name>
<servlet-name>SalsaValidationServlet</servlet-name>
<servlet-class>net.semandex.salsa.validationServlets.SalsaValidationServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SalsaValidationServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
</web-app>
Servlet
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SalsaValidationServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String path = request.getPathInfo();
if(path == null) return;
String []p = path.split("/");
if( !path.endsWith("licenseValidation.html") )
//request.getRequestDispatcher("/auth/licenseValidation.html").forward(request, response);
response.sendRedirect( request.getContextPath() + "/auth/licenseValidation.html" );
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doGet(req, resp);
}
}
HTML Page - licenseValidation.html
<html>
<head>
<title>License upload page</title>
</head>
<body>
<form>
<input type="text" name="name"/><br>
<input type="text" name="group"/>
<input type="text" name="pass"/>
<input type="submit" value="submit">
</form>
</body>
</html>
Why is this code loading a blank page and not an HTML page? Redirection does happen but to a blank page. Status code for the new URL in browser is 200 but the response is empty in debugger.
Edit:
The problem was "/*" URL pattern as stated by BalusC. Found more useful information in his another answer. Difference between / and /* in servlet mapping url pattern