<%@ 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");要改成request.getRequestDispatcher("index.jsp").forward(request,
    response);
      

  2.   

    同意,重定向request里是没值的
      

  3.   


    要用上面这个转发方法。如果实在不行!将<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>改为:
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core_rt" %>
    兼容版本。
      

  4.   

    转发:request.getRequestDispatcher("转发的页面").forward(request, response);
    跳转:response.sendRedirect("跳转的页面");
    如果是转发:你可以把你的list放到内置对象request中,然后在你转发的页面中使用EL表达式显示出来
    如果是跳转:也就是重定向,如果还想要在页面中显示出来,那只能放到session中或者Application内置对象中.. 然后也可以使用EL表达式在前台页显示.再如果:后台可以输出内容,而前台页什么也不显示,也没有报错,那你在前台页试试写java代码,看能否取到内置对象里的内容..回答完毕..
      

  5.   

    这样做也不一定是安全的
    转发是在server端发生,跳转是在client端发生的。转发会将request对象传给服务器上的另一个jsp页面,而跳转只是简单地告诉浏览器定位到另一个URL,它可以定位到不在别的服务器上的页面
    所以LZ最好还是用转发