Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Syntax error on token "class", invalid Expression

800418Apr 26 2006 — edited Apr 26 2006
Hai,
i am new to java beans and i have written the following code which gives an error

Code jsp:
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>beancode</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<!--<form name="form1" action="beancode" method="POST"> -->


Name: <input type="text" name ="nname"> <br><br><br>
Address: <input type="text" name ="naddress"> <br><br><br>
<input type = "submit" value="Submit">

<% useBean id="sampl"; class="beancode.class"; scope="page"; %>
<% setProperty name="sampl"; property="*"; %>
<%--</jsp:useBean> --%>



<table border="1">
<tr><td>S.NO</td><td>NAME</td><td width="95">ADDRESS</td></tr>
<%
int count =1;
while (rs.next())
{
String name = rs.getString("Name");
String address = rs.getString("ADDRESS");
%>


<tr>
<td>
<%
out.print(count);
%> </td>
<td>
<% out.println(name);
%> </td>
<td>
<% out.print(address);
count++;
%> </td>
</tr>

<% }
%>

</table>
<!--</form> -->

</body>
</html>


JAVA Class code:

import java.sql.*;
/**
*
* @author
*/
public class beancode
{

private String employid;
private Connection con = null;
// private ResultSet rs = null;
private PreparedStatement st = null;
String name, address;




/** Creates a new instance of beancode */
public beancode()
{ok

try
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/test";
Connection con =DriverManager.getConnection(url,"root","shasi");
Statement s = con.createStatement();
ResultSet rs = s.executeQuery ("Select * FROM Test");
}

catch(Exception e)
{
System.out.println(e.getMessage());
}

}
public void setemployid(String nname,String naddress)
{
name = nname;
address = naddress;

}

public String getemployid()
{
return(name);

}

public String getemployadd()
{
return(address);

}

public void insert()
{

try
{
String s1="insert into samp values('"+name+"','"+address+"')";
st = con.prepareStatement(s1);
st.executeUpdate();
st.clearParameters();
st.close();
}

catch(Exception m)
{
//
}
}


}
/*
public static void main(String args[])
{
beancode b = new beancode();
b.insert();

}*/



The error
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 18 in the jsp file: /bean.jsp
Generated servlet error:
Syntax error on token "class", invalid Expression


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)




PLEASE HELP ME OUT

I AM WAITING PLEASE


Thanks,
Shasi
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 24 2006
Added on Apr 26 2006
1 comment
1,117 views