Skip to content

Commit

Permalink
Lesson9: Change forward to redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
RuslanSatybaev committed Feb 20, 2023
1 parent 37d5bce commit b6c995a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>ru.javawebinar</groupId>
<artifactId>topjava</artifactId>
<packaging>jar</packaging>
<packaging>war</packaging>

<version>1.0-SNAPSHOT</version>

Expand Down Expand Up @@ -34,6 +34,13 @@
</build>

<dependencies>
<!--Web-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/ru/javawebinar/topjava/web/UserServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ru.javawebinar.topjava.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UserServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.sendRedirect("/users.jsp");
// request.getRequestDispatcher("/users.jsp").forward(request, response);
}
}
19 changes: 19 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">

<display-name>Topjava</display-name>

<servlet>
<servlet-name>userServlet</servlet-name>
<servlet-class>ru.javawebinar.topjava.web.UserServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>userServlet</servlet-name>
<url-pattern>/users</url-pattern>
</servlet-mapping>

</web-app>
13 changes: 13 additions & 0 deletions src/main/webapp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html>
<head>
<meta charset="UTF-8">
<title>Java Enterprise (Topjava)</title>
</head>
<body>
<h3>Проект <a href="https://github.com/JavaWebinar/topjava" target="_blank">Java Enterprise (Topjava)</a></h3>
<hr>
<ul>
<li><a href="users">Users</a></li>
</ul>
</body>
</html>
11 changes: 11 additions & 0 deletions src/main/webapp/users.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Users</title>
</head>
<body>
<h3><a href="index.html">Home</a></h3>
<hr>
<h2>Users1</h2>
</body>
</html>

0 comments on commit b6c995a

Please sign in to comment.