求教一个servlet结果返回问题
下面是第一个servlet代码:::::
package com.gem.servlet.day3;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Login1Servlet1 extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("GBK");
response.setCharacterEncoding("GBK");
String name = request.getParameter("userName");
String password = request.getParameter("pwd");
Userdao userDao = new UserdaoI();
User user = userDao.login(name, password);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD>");
out.println("</head>");
out.println(" <BODY>");
if(user == null){
out.println("用户名或密码错误");
out.println("<a href='login.html'>重新登陆</a>");
}else{
out.println("<form>");
out.println("<input type='button' value='课程信息表管理' onclick=\"location.href('Course.jsp')\">");
out.println("</form>");
}
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
}这段是登陆成功后到一个servlet页面,通过点击“课程信息表管理“这个button到一个jsp页面,就是下面这段代码
。。。。。。。。。。。。。。。。。。。。。。。。。。。
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@page import="java.sql.ResultSet"%>
<%
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 'shuru.jsp' starting page</title>
<script language="javascript">
function fc(thisurl){
window.open(thisurl) ;
window.close();
window.opener.location.reload();
}
</script>
<script language="javascript">
function fu(){
var s=document.shuru.courid.value;
var s1=document.shuru.courname.value;
var s2=document.shuru.courcredit.value;
var s3=document.getElementById("stusex").value;
var s4=document.getElementById("stusex1").value;
if(s==""||s1==""||s2==""||s3==""||s4==""){
alert("请输入完整信息");
}else if(!/^[0-9]*$/.test(s)){
alert("请输入数字");
document.getElementById('courid').focus();
}else if(!/^[0-9]*$/.test(s2)){
alert("请输入数字");
document.getElementById('courcredit').focus();
}
else{
document.getElementById("shuru").submit();
}
}
</script>
<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 name="shuru" action="shuru" method="post">
<center>
课程编号<input type="text" name="courid">
课程名称<input type="text" name="courname">
学分<input type="text" name="courcredit"><br/>
<br/>
课程类型<select id="stusex" name="courtype">
<option value="请选择" >请选择</option>
<option value="公共基础课">公共基础课</option>
<option value="选修课" >选修课</option>
<option value="专业基础课">专业基础课</option>
<option value="专业课" >专业课</option>
</select>
考试类型<select id="stusex1" name="courexam">
<option value="请选择" >请选择</option>
<option value="开卷">开卷</option>
<option value="闭卷" >闭卷</option>
</select>
<input type="button" value="确定" onclick="fu()">
<input type="reset" value="重置">
<input type="button" value="返回" onclick="fc('Course.jsp')">
</center>
</form>
</body>
</html>
这边点击确定后提交到另一个servlet中进行数据的插入。。。并把插入的数据返回,代码如下::
package com.gem.servlet.day4;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CshuruServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletContext sc = getServletContext();
RequestDispatcher rd = null;
request.setCharacterEncoding("GBK");
response.setCharacterEncoding("GBK");
String a = request.getParameter("courid");
int courid=Integer.parseInt(a);
String courname = request.getParameter("courname");
String b=request.getParameter("courcredit");
int courcredit=Integer.parseInt(b);
String courtype=request.getParameter("courtype");
String courexam=request.getParameter("courexam");
Shuru s=new ShuruI();
ResultSet r=s.R(courid, courname, courcredit, courtype, courexam);
request.setAttribute("sc", r);
rd = sc.getRequestDispatcher("/shuru.jsp"); //定向的页面
rd.forward(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
}
到这儿就是问题的关键,我怎么把结果集取回到jsp页面中。。。。
[解决办法]
c:foreach
------解决方案--------------------
jstl标签