为什么我不能插入带有错误消息的表#34;找不到符号(JSP页面第8行)"。我尝试了很多东西,比如从数组变换到变量。我正在使用带有jdk 1.6的Orion Application Server 2.0.7
错误消息:
Syntax error in source
/a/submitted.jsp.java:35: cannot find symbol (JSP page line 8)
symbol : method getParameterValue(java.lang.String)
location: interface javax.servlet.http.HttpServletRequest
String skill[] = request.getParameterValue("skill");
^
1 error
的 Register.jsp
<html>
<head>
<title> Pendaftaran</title>
<style>
#myDIV {
width: 1500px;
height: 800px;
background: white;
animation: mymove 5s infinite;
}
@-webkit-keyframes mymove {
from {background-color: #3CB5B5;}
to {background-color: #FCD920;}
to {background-color: #E53B51;}
to {background-color: #EC6C20;}
}
button{ background: white; width:150px; height: 50px; font-size: 30px }
input{ background: white; width:150px; height: 40px; font-size: 30px }
p{background: white; font-size: 5}
</style>
<script type="text/javascript">
function validateForm()
{
var x=document.mydata.ID.value;
var y=document.mydata.Name.value;
var z0=document.mydata.sex[0].checked;
var z1=document.mydata.sex[1].checked;
var a0=document.mydata.skill[0].checked ;
var a1=document.mydata.skill[1].checked ;
var a2=document.mydata.skill[2].checked ;
var c=document.mydata.major.selectedIndex;
if (((a0==false) && (a1==false) && (a2==false))||x==null || x==""||y==null || y==""|| c==0||((z0==false)&&(z1==false)))
{
alert("There is still unfilled data!");
return false;
}
}
</script>
</head>
<body>
<div id="myDIV">
<br><center><h1>SSK3408 SYSTEM</h1></center></br>
<hr>
<body style="background: #d8d8d8; color: White">
<br>
<form name="mydata" action="submitted.jsp" onsubmit="return validateForm()" method="post">
<table border="0">
<tr>
<td><h1>Student ID: </td>
<td><h1><input type="text" name="ID"> </td>
</tr>
<tr>
<td><h1>Name:</td>
<td><h1><input type="text" name="Name"> </td>
</tr>
<tr>
<td><h1>Gender :</td>
<td><h1><input type="radio" id="sex" name="sex" value="male" /> Male
<input type="radio" id="sex" name="sex" value="female" /> Female<br/> </td>
</tr>
<tr>
<td><h1>Skill :</td>
<td><h1><input type="checkbox" name="skill" value="C++"> C++<br>
<input type="checkbox" name="skill" value="Java"> Java<br>
<input type="checkbox" name="skill" value="Phyton"> Phyton
<br></td>
</tr>
<tr>
<td><h1>Major :</td>
<td><h1><select name="major">
<option value="">Please select here :</option>
<option value="Software Enginnering">Software Enginnering</option>
<option value="Information Technology">Information Technology</option>
<option value="Network">Network</option>
<option value="Multimedia">Multimedia</option>
</select></td>
</tr>
<tr>
<td><h1></td>
<td><h1></td>
<td><h1></td>
<td><h1><br><button type="button"onclick="location.href='Registration.jsp"><strong>Reset</strong></button></td>
<td><h1><br><button type="submit"><strong>Submit</strong></button></td>
<td><h1><br><button type="button"onclick="location.href='MainMenu.jsp'"><strong>Back</strong></button></td>
</tr>
</form>
</div>
</body>
</html>
submitted.jsp
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%
//Create an empty new variable
String message = null;
String ID = request.getParameter("ID");
String name = request.getParameter("Name");
//String male = request.getParameter("sex");
String gender = request.getParameter("sex");
String skill = request.getParameterValue("skill");
//String skillJ = request.getParameter("skillJ");
//String skillP = request.getParameter("skillP");
String major = request.getParameter("major");
//CONNECTION initiator
PreparedStatement stmt = null;
Connection conn = null;
try {
//Connect to the database
Class.forName("oracle.jdbc.driver.OracleDriver");
String hostname = "172.16.60.13";
int port = 1521;
String sid = "orcl";
String oracleURL = "jdbc:oracle:thin:@"+hostname+":"+port+":"+sid;
String user = "C180495";
String pass = "180495";
conn = DriverManager.getConnection(oracleURL, user, pass);
// Make the query
stmt=conn.prepareStatement("insert into STUDENTS values(?,?,?,?)");
stmt.clearParameters();
stmt.setString(1,ID);
stmt.setString(2,name);
stmt.setString(3,gender);
stmt.setString(4,major);
//Run the query
stmt.executeUpdate();
for(int i = 0; i<4;i++){
stmt=conn.prepareStatement("insert into skill values(?,?)");
stmt.clearParameters();
stmt.setString(1,ID);
stmt.setString(2,skill[i]);
out.println("<p><b> SQL ERROR </b></p><p>" + skill[i]+ "</p>");
stmt.executeUpdate();
}
conn.commit();
out.println("<p> <b> You have been registered !</b></p>");
//Close the database connection
stmt.close();
conn.close();
} catch (SQLException ex) {
out.println("<p><b> SQL ERROR </b></p><p>" + ex.getMessage()+ "</p>");
stmt.close();
conn.close();
}
%>
答案 0 :(得分:0)
您尝试在getParameterValue
对象上调用名为request
的方法,并且该方法不存在。
您正在界面HttpServletRequest
上寻找方法getParameterValues
(它以“复数”结尾)。
但是,您稍后为JSP发布的代码与错误消息不一致,因此您必须更改代码。
在JSP错误中,您的代码行为:
String skill[] = request.getParameterValue("skill");
但是在您发布的行中的JSP中显示:( []
后面没有skill
)
String skill = request.getParameterValue("skill");
如果您只想在一个String中使用一个值,而不是数组中的所有值,那么您应该调用方法getParameter
,因此您将代码更改为:
String skill = request.getParameter("skill");
如果您想要数组中的所有值,请将代码更改为:
String skill[] = request.getParameterValues("skill");