日期:2014-05-17  浏览次数:20798 次

新手JSP问题 求高手指教
cal.jsp

<%@ page language="java" contentType="text/html;charset=GB18030"%>
<html>
<head><title></title></head>
<body>
<center>
<form name="cal" action="showresult.jsp" method="post">
<input type="text" name="num<SCRIPT LANGUAGE="JavaScript">
<!--

//-->
</SCRIPT>1">
<select name="sign">
<option value=1 selected>+</option>
<option value=2 >-</option>
<option value=3 >*</option>
<option value=4 >/</option>
<input type="text" name="num2">
<input type="submit" name="submit" value="计算">
</form>
</body>
</html>

showresult.jsp
<%@ page language="java" contentType="text/html;charset=GB18030"%>
<html>
<head><title></title></head>
<body>
<%
int num1=Integer.parseInt(request.getParameter(num1));
int num2=Integer.parseInt(request.getParameter(num2));
int sign=Integer.parseInt(request.getParameter(sign));
int total=0;
switch(sign):
 case:1 total=num1+num2;
 case:2 total=num1-num2;
 case:3 total=num1*num2;
 case:4 total=num1/num2;
 out.print(total);

%>
</body>
</html>


点击计算后提交错误如下:
HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 6 in the jsp file: /jspdemo01/showresult.jsp
The method getParameter(String) in the type ServletRequest is not applicable for the arguments (int)
3: <head><title></title></head>
4: <body>
5: <%
6: int num1=Integer.parseInt(request.getParameter(num1));
7: int num2=Integer.parseInt(request.getParameter(num2));
8: int sign=Integer.parseInt(request.getParameter(sign));
9: int total=0;


An error occurred at line: 7 in the jsp file: /jspdemo01/showresult.jsp
The method getParameter(String) in the type ServletRequest is not applicable for the arguments (int)
4: <body>
5: <%
6: int num1=Integer.parseInt(request.getParameter(num1));
7: int num2=Integer.parseInt(request.getParameter(num2));
8: int sign=Integer.parseInt(request.getParameter(sign));
9: int total=0;
10: switch(sign):


An error occurred at line: 8 in the jsp file: /jspdemo01/showresult.jsp
The method getParameter(String) in the type ServletRequest is not applicable for the arguments (int)
5: <%
6: int num1=Integer.parseInt(request.getParameter(num1));
7: int num2=Integer.parseInt(request.getParameter(num2));
8: int sign=Integer.parseInt(request.getParameter(sign));
9: int total=0;
10: switch(sign):
11: case:1 total=num1+num2;


An error occurred at line: 10 in the jsp file: /jspdemo01/showresult.jsp
Syntax error on tokens, delete these tokens
7: int num2=Integer.parseInt(request.getParameter(num2));
8: int sign=Integer.parseInt(request.getParameter(sign));
9: int total=0;
10: switch(sign):
11: case:1 total=num1+num2;
12: case:2 total=num1-num2;
13: case:3 to