今天头晕大了看这个程序
<html>
<body>
<form>
<input type= "text " name= "num1 "> <br>
+
<input type= "text " name= "num2 "> <br>
<input type= "submit " name= "sunmit1 " value= "= ">
<input type= "text " name= "console "> <br>
</form>
</body>
</html>
能不能不通过写js,在点提交后,直接在console文本框中显示计算结果,或者不用提交,用其他方法,大概就是这个意思
------解决方案-------------------- <%
Double a = Double.parseDouble(request.getParameter( "num1 "));
Double b = Double.parseDouble(request.getParameter( "num2 "));
Double sum = a + b;
out.write( " " + sum);
%>
------解决方案--------------------应该这样:
<%@ page language= "java " contentType= "text/html; charset=GB18030 "
pageEncoding= "GB18030 "%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<%
int console = 0;
try{
int num1 = Integer.parseInt(request.getParameter( "num1 "));
int num2 = Integer.parseInt(request.getParameter( "num2 "));
console = num1 + num2;
}catch(Exception e){}
%>
<body>
<form>
<input type= "text " name= "num1 " > <br/>
+
<input type= "text " name= "num2 "> <br/>
<input type= "submit " name= "sunmit1 " value= "= ">
<input type= "text " value= " <%=console%> "> <br/>
</form>
</body>
</html>