我正在制作一个包含HTML页面,JSP页面和JavaBean的简单程序。 HTML页面用于让用户输入数据。然后,JSP将数据发送到JavaBean,该JavaBean应该使用等式1 inch = 2.54 cm将值从英寸转换为厘米。但是,我无法使其正常工作。我错过了什么还是做错了什么。请帮忙。
HTML页面
<html>
<head>
<title>Input an Inch</title>
</head>
<body style="background-color:lightblue">
<center>
<form action="DisplayJSP.jsp">
Input an inch value:<input type="text" name="clientValue">
<br/>
<input type="submit" value="Submit">
</form>
</center>
</body>
JSP页面
<html>
<head>
<title>Results</title>
</head>
<body style="background-color:lightblue">
<center>
<jsp:useBean id="convertBean" class="unit4.MBean" scope="session">
<jsp:setProperty name="convertBean" property="myInches" param="clientValue" />
</jsp:useBean>
<jsp:getProperty name="convertBean" property="myInches" />
inches =
<jsp:getProperty name="convertBean" property="myCentimeters" />
cm
</center>
</body>
</html>
最后是JavaBean
package unit4;
import java.io.*;
public class MBean implements Serializable {
private double myInches;
private double myCentimeters;
public MBean() {
myCentimeters = myInches * 2.45;
}
public void setMyInches(double tempInches) {
this.myInches = tempInches;
}
public double getMyInches() {
return myInches;
}
public double getMyCentimeters() {
return myCentimeters;
}
}
答案 0 :(得分:0)
表单的默认方法是get
,我认为您应该尝试使用post
,例如:
<form action="DisplayJSP.jsp" method="post">