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 reportmessagedescription The server encountered an internal error () that prevented it from fulfilling this request.exceptionorg.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 total=num1*num2;
An error occurred at line: 11 in the jsp file: /jspdemo01/showresult.jsp
Syntax error, insert ") SwitchBlock" to complete SwitchStatement
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 total=num1*num2;
14: case:4 total=num1/num2;
An error occurred at line: 13 in the jsp file: /jspdemo01/showresult.jsp
Syntax error on token "case", invalid Label
10: switch(sign):
11: case:1 total=num1+num2;
12: case:2 total=num1-num2;
13: case:3 total=num1*num2;
14: case:4 total=num1/num2;
15: out.print(total);
16:
An error occurred at line: 13 in the jsp file: /jspdemo01/showresult.jsp
Syntax error, insert "AssignmentOperator Expression" to complete Assignment
10: switch(sign):
11: case:1 total=num1+num2;
12: case:2 total=num1-num2;
13: case:3 total=num1*num2;
14: case:4 total=num1/num2;
15: out.print(total);
16:
An error occurred at line: 13 in the jsp file: /jspdemo01/showresult.jsp
Syntax error, insert ";" to complete Statement
10: switch(sign):
11: case:1 total=num1+num2;
12: case:2 total=num1-num2;
13: case:3 total=num1*num2;
14: case:4 total=num1/num2;
15: out.print(total);
16:
An error occurred at line: 14 in the jsp file: /jspdemo01/showresult.jsp
Syntax error on token "case", invalid Label
11: case:1 total=num1+num2;
12: case:2 total=num1-num2;
13: case:3 total=num1*num2;
14: case:4 total=num1/num2;
15: out.print(total);
16:
17: %>
An error occurred at line: 14 in the jsp file: /jspdemo01/showresult.jsp
Syntax error, insert "AssignmentOperator Expression" to complete Assignment
11: case:1 total=num1+num2;
12: case:2 total=num1-num2;
13: case:3 total=num1*num2;
14: case:4 total=num1/num2;
15: out.print(total);
16:
17: %>
An error occurred at line: 14 in the jsp file: /jspdemo01/showresult.jsp
Syntax error, insert ";" to complete Statement
11: case:1 total=num1+num2;
12: case:2 total=num1-num2;
13: case:3 total=num1*num2;
14: case:4 total=num1/num2;
15: out.print(total);
16:
17: %>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.
<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 reportmessagedescription The server encountered an internal error () that prevented it from fulfilling this request.exceptionorg.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 total=num1*num2;
An error occurred at line: 11 in the jsp file: /jspdemo01/showresult.jsp
Syntax error, insert ") SwitchBlock" to complete SwitchStatement
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 total=num1*num2;
14: case:4 total=num1/num2;
An error occurred at line: 13 in the jsp file: /jspdemo01/showresult.jsp
Syntax error on token "case", invalid Label
10: switch(sign):
11: case:1 total=num1+num2;
12: case:2 total=num1-num2;
13: case:3 total=num1*num2;
14: case:4 total=num1/num2;
15: out.print(total);
16:
An error occurred at line: 13 in the jsp file: /jspdemo01/showresult.jsp
Syntax error, insert "AssignmentOperator Expression" to complete Assignment
10: switch(sign):
11: case:1 total=num1+num2;
12: case:2 total=num1-num2;
13: case:3 total=num1*num2;
14: case:4 total=num1/num2;
15: out.print(total);
16:
An error occurred at line: 13 in the jsp file: /jspdemo01/showresult.jsp
Syntax error, insert ";" to complete Statement
10: switch(sign):
11: case:1 total=num1+num2;
12: case:2 total=num1-num2;
13: case:3 total=num1*num2;
14: case:4 total=num1/num2;
15: out.print(total);
16:
An error occurred at line: 14 in the jsp file: /jspdemo01/showresult.jsp
Syntax error on token "case", invalid Label
11: case:1 total=num1+num2;
12: case:2 total=num1-num2;
13: case:3 total=num1*num2;
14: case:4 total=num1/num2;
15: out.print(total);
16:
17: %>
An error occurred at line: 14 in the jsp file: /jspdemo01/showresult.jsp
Syntax error, insert "AssignmentOperator Expression" to complete Assignment
11: case:1 total=num1+num2;
12: case:2 total=num1-num2;
13: case:3 total=num1*num2;
14: case:4 total=num1/num2;
15: out.print(total);
16:
17: %>
An error occurred at line: 14 in the jsp file: /jspdemo01/showresult.jsp
Syntax error, insert ";" to complete Statement
11: case:1 total=num1+num2;
12: case:2 total=num1-num2;
13: case:3 total=num1*num2;
14: case:4 total=num1/num2;
15: out.print(total);
16:
17: %>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.
int num1=Integer.parseInt(request.getParameter("num1"));
int num2=Integer.parseInt(request.getParameter("num2"));
int sign=Integer.parseInt(request.getParameter("sign"));
应该这么写吧
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>
The method getParameter(String) in the type ServletRequest is not applicable for the arguments (int)
这里告诉你 在showresult.jsp中第六行
应该是request.getParameter(这里放string类型),你放的是int类型