Skip to content

Instantly share code, notes, and snippets.

@daichan4649
Last active March 29, 2021 02:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daichan4649/fcacff5e82a166beb6125b77181af259 to your computer and use it in GitHub Desktop.
Save daichan4649/fcacff5e82a166beb6125b77181af259 to your computer and use it in GitHub Desktop.
welcome ファイルで Servlet を指定+トップページ(index.jsp)へ遷移するパターン
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 InitServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//TODO do something
// forward(--> index.jsp)
final String url = "index.jsp";
request.getRequestDispatcher(url).forward(request, response);
}
}
<?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"
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>WebTest</display-name>
<welcome-file-list>
<welcome-file>init</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>InitServlet</display-name>
<servlet-name>InitServlet</servlet-name>
<servlet-class>InitServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>InitServlet</servlet-name>
<url-pattern>/init</url-pattern>
</servlet-mapping>
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment