Reputation: 1
there is some Syntax error showing on token "jspInit", AnnotationName expected after this token and Syntax error showing on token "jspDestroy", AnnotationName expected after this token.
<% connection con;
public void jspInit() {
try{
Class.forName("Oracle.jdbc.driver.OracleDriver");
con= DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","tiger");
}
catch(SQLException sqle){
sqle.printStackTrace();
}
}
public void jspDestroy () {
try{
con.close();
}
catch(SQLException sqle){
sqle.printStackTrace();
}
}
%>
Upvotes: 0
Views: 263
Reputation: 4509
First of all i don't recommend to write java code in JSP page.
You need to use declaration syntax (<%! ... %>):
not scriptlet
<%!
public String yourMethod() {
//
}
%>
Your Code should be like this
<%!
Connection con;
public void jspInit() {
try{
Class.forName("Oracle.jdbc.driver.OracleDriver");
con= DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","tiger");
}
catch(SQLException sqle){
sqle.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public void jspDestroy () {
try{
con.close();
}
catch(SQLException sqle){
sqle.printStackTrace();
}
}
%>
Upvotes: 1
Reputation: 2924
The methods (jspInit()
and jspDestroy()
in your case) have to be defined in a declarations block, not in a scriptlet. I.e. <%!
instead of just <%
.
<%! connection con;
public void jspInit() {
// ...
}
%>
Upvotes: 0