---
# System prepended metadata

title: JSP&Servlet 14回目

---

# JSP&Servlet 14回目

## やること

TomcatのみインストールされたサーバへのWebアプリケーションのデプロイを行う。

## 参考にしてほしい資料(授業資料)

> https://drive.google.com/file/d/1mkYv9CM-znDb5s4KiykdNLYPay18Me9V/view
> https://drive.google.com/file/d/1X1QBAz3jfRRrJDiP4T2e9Lwk2RSRwE0-/view

## テストプログラム

![](https://i.imgur.com/b04pkcX.png)
![](https://i.imgur.com/cZgSA66.png)

### hello.jsp
```html=
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello</title>
</head>
<body>
	<form method="post" action="HelloServlet">
		ニックネーム<input type="text" name="nickname"><br>
		<input type="submit" value="送信">
	</form>

</body>
</html>
```

### HelloServlet.java
```java=

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/HelloServlet")
public class HelloServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public HelloServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().append("Served at:").append(request.getContextPath());
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String nickname = request.getParameter("nickname");

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.println("<html lang='ja'><body>");
        out.println("ようこそ: " + nickname  + "さん");
        out.println("</body></html>");
    }

}

```


