Why can't I insert into table with error message "cannot find symbol (JSP page line 8)". I have tried so many things like change from array to variable. I am using Orion Application Server 2.0.7 with jdk 1.6
The error message:
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();
}
%>
You're trying to call a method called
getParameterValueon therequestobject, and that method doesn't exist.You're looking for the method
getParameterValues(it ends in an 's', it's plural) on interfaceHttpServletRequest.However the code that you later posted for your JSP is inconsistent with your error message, so you must have changed your code.
In the JSP error, your line of code reads:
But in the JSP that you posted the line reads: (without the
[]behindskill)If you just want one value in a single String, instead of all values in an array, then you should call the method
getParameter, so you change your code to:If you want all values in an array, you change your code to: