jsp
テキストフィールドがあります。テキストフィールドに挿入したテキストを印刷したいのですが、方法がわかりません。JSP ページ:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Return the name</title>
</head>
<body>
<h1>Welcome</h1>
Insert your text here:<br>
<form name="txtForm" action="Main.java" method="post">
<input type="text" name="txt">
<input type="submit" value="Send">
</form>
</body>
</html>
そして、これはclass(Main.java)
JSP を処理しているものです。
public class Main extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String text = request.getParameter("txt");
Date d = new Date();
System.out.println("The name you enter is:" + text + "at the time : " + d);
}
}
私が欲しいのは、クラスを介してjspから情報を取得し、それをjspに出力することです。これはどのように行うことができますか?使用しようとしましたが<%@ import ... >
、機能しませんでした。:(
ありがとうございます。