输入学生ID的JSP页面是下面的<%-- 
    Document   : student_Danyi
    Created on : 2011-6-7, 22:51:34
    Author     : HuleiFanny
--%><%@page import="java.util.Iterator"%>
<%@page import="java.sql.ResultSet"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import ="bean.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<SCRIPT language="javaScript">
function doCheck(form)
{
if(form.ID.value.length !=13)
{
alert("请输入正确编号!");
return false;
}
            return true;
}
</SCRIPT>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>欢迎进入单一学生信息查询页面!</title>
    </head>
    <body text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
    background="12.bmp">
        <br><br><br><br><br><br>
        <form method="post" action="xuesheng" name="xuesheng" id="xuesheng" onsubmit="return doCheck(this)">
        <table align="center">
          <tr>
            <td>请输入学生编号:<input type=text name="ID" value="" length=10 size="17" maxlength="13"></td>
            <td><input type=submit value="提交" name="submit"></td>
          </tr>
        </table>
        </form>
    </body>
</html>servlet是下面的:package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import bean.*;
import java.sql.ResultSet;
import javax.servlet.http.HttpSession;
/**
 *
 * @author HuleiFanny
 */
public class xuesheng extends HttpServlet {
   
    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
public void service(HttpServletRequest request, HttpServletResponse response)
    throws ServletException,IOException {
        HttpSession session=request.getSession(true);
        request.setCharacterEncoding("gb2312");
        response.setContentType("text/html; charset=gb2312");
        PrintWriter out=response.getWriter();
        String id = request.getParameter("ID");
        Student student= new Student();
        DBConnect connect = new DBConnect();
        ResultSet rs = null;
        try{
        String sqlstudent="select * from student where username="+id+";";
        rs = connect.executeQuery(sqlstudent);
        }catch (Exception e) {
            e.getMessage();
        }
        request.setAttribute("cxstudent",rs);
        System.out.println("shuxing创建好了");
        request.getRequestDispatcher("student_Danyixianshi.jsp").forward(request, response);    }
@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
this.service(request, response);
    }
}
最后是显示的页面:<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.sql.ResultSet"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import ="bean.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<SCRIPT language="javaScript">
function doCheck(form)
{
if(form.ID.value.length !=13)
{
alert("请输入正确编号!");
return false;
}
            return true;
}
</SCRIPT>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>欢迎进入单一学生信息查询页面!</title>
    </head>
    <body text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
    background="12.bmp">
<%  rs=(Student)request.getAttribute("student");
    out.print("<table border=1>");
    out.print("<tr>");
    out.print("<th width=72>入学号</td>");
    out.print("<th width=72>名字</td>");
    out.print("<th width=50>家庭地址</td>");
    out.print("<th width=50>出生日期</td>");
    out.print("<th width=62>性别</td>");
    out.print("<th width=50>学生类别</td>");
    out.print("<th width=50>国籍</td>");
    out.print("<th width=50>吸烟者</td>");
    out.print("<th width=50>附加备注</td>");
    out.print("<th width=50>当前情况</td>");
    out.print("<th width=50>正在学习课程</td>");
    out.print("</tr>");
    String a,b,c,d,e,f,g,h,i,j,k;  //这里将数据以表格形式输出
    out.print("<tr>");
    a=rs.getUserName();
    out.print("<td>"+a+"</td>");
    b=rs.getName();
    out.print("<td>"+b+"</td>");
    c=rs.getAddress();
    out.print("<td>"+c+"</td>");
    d=rs.getData();
    out.print("<td>"+d+"</td>");
    e=rs.getSex();
    out.print("<td>"+e+"</td>");
    f=rs.getClas();
    out.print("<td>"+f+"</td>");
    g=rs.getCountry();
    out.print("<td>"+g+"</td>");
    h=rs.getAddition();
    out.print("<td>"+h+"</td>");
    i=rs.getStation();
    out.print("<td>"+i+"</td>");
    j=rs.getCourse();
    out.print("<td>"+j+"</td>");
    k=rs.getPassword();
    out.print("<td>"+k+"</td>");
    out.print("</tr>");
    **/
    %>
    </body>
</html>在数据库中类型如下:

解决方案 »

  1.   

    错误如下:
    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: 31 in the jsp file: /student_Danyixianshi.jsp
    rs cannot be resolved
    28:     </head>
    29:     <body text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
    30:      background="12.bmp">
    31: <%  rs=(Student)request.getAttribute("student");
    32: 
    33:     out.print("<table border=1>");
    34:     out.print("<tr>");
    An error occurred at line: 48 in the jsp file: /student_Danyixianshi.jsp
    rs cannot be resolved
    45:     out.print("<th width=50>姝e湪瀛︿範璇剧▼</td>");
    46:     out.print("</tr>");
    47:     String a,b,c,d,e,f,g,h,i,j,k;  //杩欓噷灏嗘暟鎹互琛ㄦ牸褰㈠紡杈撳嚭
    48:     rs.getAddition();
    49:     /*
    50:     out.print("<tr>");
    51:     a=rs.getUserName();
    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:439)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    servlet.xuesheng.service(xuesheng.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.
    各位大牛 拜托啦 我都弄了2天了 不是这问题就是那问题~~ 
      

  2.   

    看看你的编码问题。。你都没有看到你JSP 输出的乱码!
    先把乱码解决了,再看看出什么错。。这个问题很可能就是你乱码引起的
      

  3.   

    An error occurred at line: 31 in the jsp file: /student_Danyixianshi.jsp
    rs cannot be resolved
    不能识别rs,在哪里定义的rs啊?31: <% rs=(Student)request.getAttribute("student");
    rs有定义吗?
      

  4.   

    rs是在servlet中定义的啊  在输出JSP中取它的数据的啊
      

  5.   

    额 是参数写错了~ rs已经传递给cxstudent了 现在改正如下:
    Student getstudent=(Student)request.getAttribute("cxstudent");
    又出现了错误 总是乱码
    org.apache.jasper.JasperException: An exception occurred processing JSP page /student_Danyixianshi.jsp at line 2017:     </head>
    18:     <body text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
    19:      background="12.bmp">
    20: <%  Student getstudent=(Student)request.getAttribute("cxstudent");
    21:     out.print("<table border=1>");
    22:     out.print("<tr>");
    23:     out.print("<th width=72>鍏ュ鍙�/td>");
      

  6.   

    额 是参数写错了~ rs已经传递给cxstudent了 现在改正如下:
    Student getstudent=(Student)request.getAttribute("cxstudent");
    又出现了错误 总是乱码
    org.apache.jasper.JasperException: An exception occurred processing JSP page /student_Danyixianshi.jsp at line 2017: </head>
    18: <body text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
    19: background="12.bmp">
    20: <% Student getstudent=(Student)request.getAttribute("cxstudent");
    21: out.print("<table border=1>");
    22: out.print("<tr>");
    23: out.print("<th width=72>鍏ュ鍙�/td>");