jsp文件是:
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="java.sql.ResultSet"%>   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<h1>主页</h1><%
ResultSet rs ;
String sql;
String name = request.getParameter("name");
sql = "select no from peopele where name=" +name ;
rs = new DbConnection().queryInfo(sql);

%>
你好:
<%=name %>
你的登陆帐号为:
</body>
</html>DbConnection 类为:
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;import com.mysql.jdbc.Connection;
public class DbConnection 
{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
PreparedStatement ps = null;
DbConnection()
{ try 
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/test";
String username = "root";
String password = "881023";
conn = (Connection) DriverManager.getConnection(url,username,password);

catch (ClassNotFoundException e)
{
e.printStackTrace();
} catch (SQLException e) 
{
e.printStackTrace();
}
} public ResultSet queryInfo(String sql) throws SQLException
{
System.out.println("ok__1");
stmt = conn.createStatement();
System.out.println("ok__2");
rs = stmt.executeQuery(sql);
System.out.println("ok__3");
return rs;
}
}
错误信息为
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage 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: /success.jsp
DbConnection cannot be resolved to a type
15: String sql;
16: String name = request.getParameter("name");
17: sql = "select no from peopele where name=" +name ;
18: rs = new DbConnection().queryInfo(sql);
19: 
20: %>
21:
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:443)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:362)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:316)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.2 logs.
--------------------------------------------------------------------------------Apache Tomcat/7.0.2弄了很久不明白 求指导JSP

解决方案 »

  1.   

    很明显啊,你在JSP页面里边写得java代码出错了啊,java都不知道要怎么编译成他识别的servlet了
      

  2.   

    你的数据不是在java程序里边准备的么,直接在jsp里边准备啊
      

  3.   


    你在jsp页面里用了DbConnection 这个类的queryInfo()方法。但是你没有引入这个包<%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8" import="java.sql.ResultSet[size=12px][/size]"%>   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
    </head>
    <body>
    <h1>主页</h1><%
    ResultSet rs ;
    String sql;
    String name = request.getParameter("name");
    sql = "select no from peopele where name=" +name ;
    rs = new DbConnection().queryInfo(sql);%>
    你好:
    <%=name %>
    你的登陆帐号为:
    </body>
    </html>