servlet向jsp页面传参时浏览器状态栏一直显示正在连接中,代码附上

发布于 2021-11-16 22:57:08 字数 9236 浏览 906 评论 3

代码一、navigation.jsp

代码2.bookCaseQuery.java

package cn.edu.xcu.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;


import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.xcu.dao.BookCaseDao;

public class bookCaseQuery extends HttpServlet {

	
	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=UTF-8");
		response.setCharacterEncoding("UTF-8");
		String str=null;
		BookCaseDao bookCaseDao=new BookCaseDao();			
		Collection coll=bookCaseDao.query(str);
		request.setAttribute("bookcase", coll);
		/*HttpSession session=request.getSession();
		session.setAttribute("bookcase", coll);*/
		//request.getRequestDispatcher("bookcase/bookcase.jsp").forward(request, response);
		RequestDispatcher de=request.getRequestDispatcher("bookcase/bookcase.jsp");
	    de.forward(request, response);
	}

}
代码3.bookcase.jsp
%@ page language="java" import="java.util.*,java.sql.*,cn.edu.xcu.bean.*,cn.edu.xcu.dao.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<%
Collection coll=(Collection)request.getAttribute("bookcase");
%>
  <head>
    <base href="<%=basePath%>">    
    <title>书架信息</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>
    <table width="778" border="0" align="center" cellpadding="0" cellspacing="0" class="tableBorder">
  <tr>
    <td height="183">
	<%@ include file="/navigation.jsp"%>
	</td>
	</tr>
	<td>
	<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" bgcolor="#FFFFFF"><table width="99%" height="510"  border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="tableBorder_gray">
  <tr>
    <td height="510" valign="top" style="padding:5px;"><table width="98%" height="487"  border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="22" valign="top" class="word_orange">当前位置:系统设置 &gt; 书架设置 &gt;&gt;&gt;</td>
      </tr>
      <tr>
        <td align="center" valign="top"><%
			if(coll==null || coll.isEmpty()){
		%>
          <table width="100%" height="30"  border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td height="36" align="center">暂无书架信息!</td>
            </tr>
          </table>
          <table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
      <a href="bookcase/bookcase_add.jsp" >添加书架信息</a> </td>
  </tr>
</table>
<%
}else{
  //通过迭代方式显示数据
  Iterator it=coll.iterator();
  int ID=0;
  String name="";
  %>
 <table width="91%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="84%">&nbsp;      </td>
<td width="16%" align="right">
      <a href="bookcase/bookcase_add.jsp" >添加书架信息</a> </td>	  
  </tr>
</table>  
  <table width="91%"  border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bordercolordark="#D2E3E6" bordercolorlight="#FFFFFF">
  <tr align="center" bgcolor="#e3F4F7">
    <td width="70%">书架名称</td>
    <td width="16%">修改</td>
    <td width="14%">删除</td>
  </tr>
<%
  while(it.hasNext()){
    BookCase bookCase=(BookCase)it.next();
	ID=bookCase.getId().intValue();
	name=bookCase.getName();
	%>
  <tr>
    <td style="padding:5px;"><%=name%></td>
    <td align="center"><a href="bookcase/bookcase_modify.jsp" >修改</a></td>
    <td align="center"><a href="">删除</a></td>
  </tr>
<%
  }
}
%> 
</table></td>
      </tr>
    </table>
</td>
  </tr>
</table>
<%@ include file="/copyright.jsp"%>
</td>
  </tr>
</table>
</td>

</table>
  </body>
</html>
4.web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name></display-name>
  
 <filter>
   <filter-name>SetCharacterEncodingFilter</filter-name>
   <filter-class>peom.SetCharacterEncodingFilter</filter-class>
 </filter>
 <filter-mapping>
   <filter-name>SetCharacterEncodingFilter</filter-name>
   <url-pattern>/*</url-pattern>
 </filter-mapping>
 
  <servlet>
    <servlet-name>bookAdd</servlet-name>
    <servlet-class>cn.edu.xcu.servlet.bookAdd</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>bookCaseAdd</servlet-name>
    <servlet-class>cn.edu.xcu.servlet.bookCaseAdd</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>bookCaseModify</servlet-name>
    <servlet-class>cn.edu.xcu.servlet.bookCaseModify</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>bookTypeAdd</servlet-name>
    <servlet-class>cn.edu.xcu.servlet.bookTypeAdd</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>bookCaseQuery</servlet-name>
    <servlet-class>cn.edu.xcu.servlet.bookCaseQuery</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>managerAdd</servlet-name>
    <servlet-class>cn.edu.xcu.servlet.managerAdd</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>readerAdd</servlet-name>
    <servlet-class>cn.edu.xcu.servlet.readerAdd</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>readerTypeAdd</servlet-name>
    <servlet-class>cn.edu.xcu.servlet.readerTypeAdd</servlet-class>
  </servlet>








  <servlet-mapping>
    <servlet-name>bookAdd</servlet-name>
    <url-pattern>/bookAdd</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>bookCaseAdd</servlet-name>
    <url-pattern>/bookCaseAdd</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>bookCaseModify</servlet-name>
    <url-pattern>/bookCaseModify</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>bookTypeAdd</servlet-name>
    <url-pattern>/bookTypeAdd</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>bookCaseQuery</servlet-name>
    <url-pattern>/bookCaseQuery</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>managerAdd</servlet-name>
    <url-pattern>/managerAdd</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>readerAdd</servlet-name>
    <url-pattern>/readerAdd</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>readerTypeAdd</servlet-name>
    <url-pattern>/readerTypeAdd</url-pattern>
  </servlet-mapping>	
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

问题:如上代码,点击1中的书架设置,到servlet里面调用数据库,查询书架信息,并将结果集传到3中的jsp页面接受,但现在点击后没有出现想象中的结果,如下图:找了半天也没解决好,大家帮忙看看,谢谢!这个是mvc模式,不用structs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

滥情空心 2021-11-20 22:11:39

getRequestDispatcher 内部跳转的路径也要查查对不对

归途 2021-11-19 07:19:24

firefox debug 看
请求路径 是否正确,  直接拷出来到流量器地址看看

居里长安 2021-11-18 22:33:09

似乎你在页面元素中使用了框架,应该是路径问题。尝试在
request.getRequestDispatcher和href中使用绝对路径,不要使用相对路径

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文