servlet中的相关程序代码
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException
{
String path="Stu/Stu_list.jsp";
String type=request.getParameter("type");
if("sname".equals(type))
{
String sname=request.getParameter("sname").trim();
if(sname.equals(""))
path="Stu_Manager.jsp";
else
{
Collection c=FactoryDao.getStuOpInstance().searchStuByname(sname);
request.setAttribute("stulist", c);
}
}
request.getRequestDispatcher(path).forward(request, response);
}
Stu_list.jsp代码
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="student.*"%>
<html>
<head>
<title>学生信息管理</title>
<link rel="stylesheet" type="text/css" href="../style/style.css">
<style type="text/css">
<!--
.style1 {
color: black;
font-size: 12pt;
align:center;
}
-->
</style>
</head>
<body>
<div class="h" align="center"> <br/><span class="style1">学生信息管理</span><br/></div>
<DIV class="t">
<TABLE cellSpacing="0" cellPadding="0" width="100%">
<TR class="tr2" align="center">
<TD height="20" style="width:10%">编号</TD><TD style="width:10%">姓名</TD><TD style="width:9%">性别</TD><TD style="width:12%">出生日期</TD><TD style="width:12%">政治面貌</TD><TD style="width:10%">民族</TD>
<TD style="width:10%">身份证号</TD><TD colspan="3">操作</TD> </TR>
<%
Collection c=(Collection)request.getAttribute("stulist");
if(c.isEmpty())
out.print("您查询的学生不存在");
else
{
Iterator i=c.iterator();
while(i.hasNext())
{
Student st=(Student)i.next();
%>
<tr class="tr3" align="center">
<TH><%=st.getSno() %></TH>
<TH><%=st.getSname() %></TH>
<TH><%=st.getSsex() %></TH>
<TH><%=st.getSborth() %></TH>
<TH><%=st.getSpl() %></TH>
<TH><%=st.getSorigin() %></TH>
<TH><%=st.getIdCard() %></TH>
<TH><a href="Stu_detail.jsp?stu=<%=st.getSno() %>">详细 </a>|<a href="Stu_edit.jsp?sno=<%=st.getSno()%>"> 修改 </a>|<a href="Stu_delete.jsp?sno=<%=st.getSno() %>"> 删除 </a></TH>
</tr>
<% }
}
%>
</TABLE>
</DIV>
<BR/>
<CENTER class="gray">ZhengZhou University SoftWare Department JAVA工作室 Co.,Ltd 版权所有</CENTER>
</body>
</html>如果不用Servlet则显示正常,在servlet中用response.sendRedirect(path)进行跳转也能正常显示,本人认为是
request.getRequestDispatcher(path).forward(request, response);这句代码引起的,不知哪位大侠知道什么原因,有什么应对之策!
敬请指教!
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException
{
String path="Stu/Stu_list.jsp";
String type=request.getParameter("type");
if("sname".equals(type))
{
String sname=request.getParameter("sname").trim();
if(sname.equals(""))
path="Stu_Manager.jsp";
else
{
Collection c=FactoryDao.getStuOpInstance().searchStuByname(sname);
request.setAttribute("stulist", c);
}
}
request.getRequestDispatcher(path).forward(request, response);
}
Stu_list.jsp代码
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="student.*"%>
<html>
<head>
<title>学生信息管理</title>
<link rel="stylesheet" type="text/css" href="../style/style.css">
<style type="text/css">
<!--
.style1 {
color: black;
font-size: 12pt;
align:center;
}
-->
</style>
</head>
<body>
<div class="h" align="center"> <br/><span class="style1">学生信息管理</span><br/></div>
<DIV class="t">
<TABLE cellSpacing="0" cellPadding="0" width="100%">
<TR class="tr2" align="center">
<TD height="20" style="width:10%">编号</TD><TD style="width:10%">姓名</TD><TD style="width:9%">性别</TD><TD style="width:12%">出生日期</TD><TD style="width:12%">政治面貌</TD><TD style="width:10%">民族</TD>
<TD style="width:10%">身份证号</TD><TD colspan="3">操作</TD> </TR>
<%
Collection c=(Collection)request.getAttribute("stulist");
if(c.isEmpty())
out.print("您查询的学生不存在");
else
{
Iterator i=c.iterator();
while(i.hasNext())
{
Student st=(Student)i.next();
%>
<tr class="tr3" align="center">
<TH><%=st.getSno() %></TH>
<TH><%=st.getSname() %></TH>
<TH><%=st.getSsex() %></TH>
<TH><%=st.getSborth() %></TH>
<TH><%=st.getSpl() %></TH>
<TH><%=st.getSorigin() %></TH>
<TH><%=st.getIdCard() %></TH>
<TH><a href="Stu_detail.jsp?stu=<%=st.getSno() %>">详细 </a>|<a href="Stu_edit.jsp?sno=<%=st.getSno()%>"> 修改 </a>|<a href="Stu_delete.jsp?sno=<%=st.getSno() %>"> 删除 </a></TH>
</tr>
<% }
}
%>
</TABLE>
</DIV>
<BR/>
<CENTER class="gray">ZhengZhou University SoftWare Department JAVA工作室 Co.,Ltd 版权所有</CENTER>
</body>
</html>如果不用Servlet则显示正常,在servlet中用response.sendRedirect(path)进行跳转也能正常显示,本人认为是
request.getRequestDispatcher(path).forward(request, response);这句代码引起的,不知哪位大侠知道什么原因,有什么应对之策!
敬请指教!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货