プロジェクト

全般

プロフィール

« | » 

リビジョン c6832eb9

高橋徹 さんが10ヶ月前に追加

Add Input/Output page for SpringBoot MVC

差分を表示:

learn/java/spring/SpringThoroughIntroduction/hello_mvc/build.gradle.kts
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.apache.tomcat.embed:tomcat-embed-jasper")
implementation("jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.2")
implementation("org.glassfish.web:jakarta.servlet.jsp.jstl:3.0.1")
}
learn/java/spring/SpringThoroughIntroduction/hello_mvc/src/main/java/com/torutk/spring/echo/EchoController.java
package com.torutk.spring.echo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("echo")
public class EchoController {
@RequestMapping(method = RequestMethod.GET)
public String viewInput(Model model) {
EchoForm form = new EchoForm();
model.addAttribute(form);
return "echo/input";
}
@RequestMapping(method = RequestMethod.POST)
public String echo(EchoForm form) {
return "echo/output";
}
}
learn/java/spring/SpringThoroughIntroduction/hello_mvc/src/main/java/com/torutk/spring/echo/EchoForm.java
package com.torutk.spring.echo;
import java.io.Serial;
import java.io.Serializable;
public class EchoForm implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
learn/java/spring/SpringThoroughIntroduction/hello_mvc/src/main/webapp/WEB-INF/echo/input.jsp
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Input Message</title>
</head>
<body>
<h2>入力画面</h2>
<form:form modelAttribute="echoForm">
<div>テキストを入力して下さい:</div>
<div>
<form:input path="text" />
</div>
<div>
<form:button>送信</form:button>
</div>
</form:form>
</body>
</html>
learn/java/spring/SpringThoroughIntroduction/hello_mvc/src/main/webapp/WEB-INF/echo/output.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Output Message</title>
</head>
<body>
<h2>出力画面</h2>
<div>入力したテキストは・・・</div>
<div>
「<span><c:out value="${echoForm.text}" /></span>」
</div>
<div>です。</div>
<br>
<div>
<a href="<c:url value='/' />">トップ画面へ戻る</a>
</div>
</body>
</html>
learn/java/spring/SpringThoroughIntroduction/hello_mvc/src/main/webapp/WEB-INF/index.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Welcome</title>
</head>
<body>
<p>Hello, World!</p>
</body>
<head>
<meta charset="UTF-8"/>
<title>Welcome</title>
</head>
<body>
<h2>Hello, World!</h2>
<ul>
<li><a href="<c:url value='echo' />">エコーアプリケーションへ</a></li>
</ul>
</body>
</html>

他の形式にエクスポート: Unified diff