<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="Model.*" %>
<%@ page import="Servlet.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
  </head>
  
  <body>
    <form action="" method="post" name="myform"><div align="center">
    <table>
    <tr>
    <td colspan=3 align="center">汽车显示</td>
    </tr>
    <tr>
    <td>序号</td><td>名称</td><td>价格</td>
    </tr>
    <c:forEach var="current" items="${requestScope.Arrlist}">
    <tr>
    <td>${current.id }</td><td>${current.name }</td><td>${current.price }</td>
    </tr>
    </c:forEach>
    </table>   
    </form>
  </body>
</html>
-------------------以上是jsp显示页面package Model;import java.net.URLEncoder;
import java.sql.*;
import java.util.*;public class GetFunction {
Connection conn=null;
PreparedStatement pState=null;
ResultSet res=null;
BusBean bus=null;
List list=null;

public List getSelA(){
list=new ArrayList();
try {
String sql="select * from Bus ";
conn=DBConnectionDao.getConn();
pState=conn.prepareStatement(sql);
res=pState.executeQuery();
if(res.next()){
bus=new BusBean();
bus.setId(res.getString("id"));
bus.setName(res.getString("name"));
bus.setPrice(res.getString("price"));
list.add(bus);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBConnectionDao.closeAll(conn, pState, res);
}
return list;
}
}
---------------------------------以上是方法package Servlet;import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.util.List;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import Model.GetFunction;public class busServlet extends HttpServlet {
public void destroy() {
super.destroy(); 
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=GBK");
PrintWriter out = response.getWriter();
         GetFunction gf=new GetFunction();
List list=gf.getSelA();
request.setAttribute("Arrlist", list);
response.sendRedirect("index.jsp");
}
public void init() throws ServletException {
// Put your code here
}}
----------------------------以上是servlet
我用小脚本做是可以显示数据库的东西的 证明数据库连接方面没问题  但是一旦用这个标签来做 就无显示了 程序没有报错 但是数据库的内容一行也没显示  高手请指点

解决方案 »

  1.   


    response.sendRedirect("index.jsp");
    变成
    RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
    rd.forward(request, response)注意forward/include和redirect的区别,
    redirect是服务器把redirct的地址发还给客户端,客户端根据redirect地址发出新的请求,属于两个request/response,所以你的request.setAttribute("Arrlist", list);和<c:forEach var="current" items="${requestScope.Arrlist}">是没法联系起来的