请教jsp连接sql server数据库出现“非法字符”的报错!
我的源代码如下:
<%@page contentType= "text/html;charset=8859_1 "%>
<%@page pageEncoding= "UTF-8 "%>
<%@page import= "java.sql.*,java.sql.Connection " %>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=UTF-8 ">
<title> JSP Page </title>
</head>
<body>
<jsp:useBean id= "mybean " scope= "session " class= "mylib.myname " />
<jsp:setProperty name= "mybean " property= "* "/>
<h1> Hello,
<jsp:getProperty name= "mybean " property= "name " /> .
your password is:
<jsp:getProperty name= "mybean " property= "pass " />
</h1>
<%
Connection con=null;
Statement s=null;
ResultSet rs=null;
try{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
}
catch(ClassNotFoundException ce){
out.println(ce.getMessage());
}
try{
con=DriverManager.getConnection( "jdbc:odbc:student ");
s=con.createStatement();
rs=s.executeStatement( "select * from student ");
while(rs.next()){
out.print(rs.getString( "学号 "));
out.print(rs.getString( "姓名 "));
out.print(rs.getString( "性别 "));
out.print(rs.getString( "小组编号 "));
out.print(rs.getString( "班级编号 "));
out.print( " <br> ");
}
}
catch(SQLException e){
System.out.println(e.getMessage());
}
finally{
s.close();
con.close();
}
%>
</body>
</html>
运行后的报错如下:
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 31 in the jsp file: /response.jsp
Generated servlet error:
C:\Documents and Settings\Emdy\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\WebApplication1\org\apache\jsp\response_jsp.java:99: 非法字符: \65307
out.print(rs.getString( "学号 "));
^
An error occurred at line: 31 in the jsp file: /response.jsp
Generated servlet error:
C:\Documents and Settings\Emdy\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\WebApplication1\org\apache\jsp\response_jsp.java:100: 非法字符: \65307
out.print(rs.getString( "姓名 "));
^
An error occurred at line: 31 in the jsp file: /response.jsp
Generated servlet error:
C:\Documents and Settings\Emdy\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\WebApplication1\org\apache\jsp\response_jsp.java:101: 非法字符: \65307
out.print(rs.getString( "性别 "));
^
An error occurred at line: 31 in the jsp file: /response.jsp
Generated servlet error:
C:\Documents and Settings\Emdy\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\WebApplication1\org\apache\jsp\response_jsp.java:102: 非法字符: \65307
out.print(rs.getString( "小组编号 "));
^
An error occurred at line: 31 in the jsp file: /response.jsp
Generated servlet error:
C:\Documents and Settings\Emdy\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\WebApplication1\org\apache\jsp\response_jsp.java:103: 非法字符: \65307
out.print(rs.getString( "班级编号 "));
^
5 错误
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
root cause
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 31 in the jsp file: /response.jsp
Generated servlet error:
C:\Documents and Settings\Emdy\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\WebApplication1\org\apache\jsp\response_jsp.java:99: 非法字符: \65307
out.print(rs.getString( "学号 "));
^
An error occurred at line: 31 in the jsp file: /response.jsp
Generated servlet error:
C:\Documents and Settings\Emdy\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\WebApplication1\org\apache\jsp\response_jsp.java:100: 非法字符: \65307
out.print(rs.getString( "姓名 "));
^
An error occurred at line: 31 in the jsp file: /response.jsp
Generated servlet error:
C:\Documents and Settings\Emdy\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\WebApplication1\org\apache\jsp\response_jsp.java:101: 非法字符: \65307
out.print(rs.getString( "性别 "));
^
An error occurred at line: 31 in the jsp file: /response.jsp
Generated servlet error:
C:\Documents and Settings\Emdy\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\WebApplication1\org\apache\jsp\response_jsp.java:102: 非法字符: \65307
out.print(rs.getString( "小组编号 "));
^
An error occurred at line: 31 in the jsp file: /response.jsp
Generated servlet error:
C:\Documents and Settings\Emdy\.netbeans\5.5\apache-tomcat-5.5.17_base\work\Catalina\localhost\WebApplication1\org\apache\jsp\response_jsp.java:103: 非法字符: \65307
out.print(rs.getString( "班级编号 "));
^
5 错误
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.AntCompiler.generateClass(AntCompiler.java:249)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
请教各位这是什么原因引起的呢?谢谢大家!
[解决办法]
out.print(rs.getString( "学号 "));
偶发现你的分号是中文的。。
[解决办法]
嗬嗬,编译错误不该来问,LZ别生气,这个错误有点明显,还有,建议你别用中文
------解决方案--------------------
把中文按顺序改成1,2,3..
[解决办法]
“;”与“;”
前者真是大了不少呀。。
[解决办法]
out.print(rs.getString( "学号 "));
后面分号要用英文状态下 输入;
而且建议你数据库字段别用中文,
[解决办法]
将
<%@page contentType= "text/html;charset=8859_1 "%>
改成
<%@ page contentType= "text/html; charset=GBK " %>
将
<%@page pageEncoding= "UTF-8 "%>
删除
试试看
[解决办法]
汗,lz太粗心了
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html