aspose file tools*
The moose likes JSP and the fly likes org.apache.jasper.JasperException: Unable to compile class for JSP: cannot be resolved to a variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "org.apache.jasper.JasperException: Unable to compile class for JSP: cannot be resolved to a variable" Watch "org.apache.jasper.JasperException: Unable to compile class for JSP: cannot be resolved to a variable" New topic
Author

org.apache.jasper.JasperException: Unable to compile class for JSP: cannot be resolved to a variable

Aditi Joshi
Greenhorn

Joined: Aug 03, 2012
Posts: 4
Hi All,

I am getting this error while accessing java variable in jsp. Please help. Following is my code.

<%
int num;
try{

String enquiry_no;
ResultSet rs=null;
String url = "jdbc:mysql://localhost:3306/test";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url, "root", "root");
Statement statement = connection.createStatement();

String query = "select id from employee_table";

rs = statement.executeQuery(query);
rs.last();
num=rs.getRow();
int rowCount=num+1;;
emp_id=Integer.toString(rowCount);

System.out.println(emp_id);

}
catch(SQLException e){e.printStackTrace();}
%>
<tr>
<td width="134">Enquiry Number - </td>
<td colspan="2"><input type="text" name="emp_id" value="<%=emp_id%>" readonly="readonly" /></td>
</tr>


Thanks in Advance.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

1. the cannot resolved variable is emp_id ? if yes define as you defined num .

2. why do you depends on row count for your employee id. you will endup with same employee id for different employees.
for example: employee_id is 10 now . then somebody remove some employee(say 5th employee) now rowcount become 9.
=> when you enter new employee he will get 10 again!

3.please move your db/java code to a java class.WhyNotUseScriptlets
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Welcome to JavaRanch Aditi Joshi :)
Aditi Joshi
Greenhorn

Joined: Aug 03, 2012
Posts: 4
Thanks a lott sir....it worked....also thanks for suggesting logic...:-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.apache.jasper.JasperException: Unable to compile class for JSP: cannot be resolved to a variable