0
HTML page
計算ボタンをクリックすると、回答テキストフィールドに出力する必要があります。しかし、最初に私はそれがどのように動作するか、いくつかのテキストを渡すことによって、そして回答フィールドのテキストを返すことをクリックすることでチェックしたい。1つのテキストフィールドが入力を通過し、クリックすると結果がサーブレットとhtmlページを使用して別のテキストボックスに表示されます
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form name = 'calculate' action="Calculator" method ="get">
<h1>Text Based Calculator</h1>
<p>
<label>Equation</label>
<input type ="text" style="font-size:10pt;height:20px;width:400px;"
id ="textEquation"/>
<input type="submit" style="height:25px;width:200px" name="Calculate" value="Calculate"">
</p>
<lable>Answer</lable>
<input type = "text" style="font-size:10pt;height:20px;width:400px;"
id = "textAnswer"/>
</body>
</html>
this is servlet class
package textbasedcalculator;
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("/Calculator")
public class Calculator extends HttpServlet {
private static final long serialVersionUID = 1L;
public Calculator() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String Equation = request.getParameter("textEquation");
}
}