http://www.yesky.com/72342367549521920/index.shtml

解决方案 »

  1.   

    我写了一个,你试试看。希望对你有帮助。
    是先从jsp1.jsp 传递到 servlet1然后再传递到 jsp2.jsp。以下程序没有经过调试。但大体方法是如下所示。jsp1.jsp:
    <html>
    <head><%@ page contentType="text/html;charset=gb2312" %></head><body>
    <center>
    <br><form action="/project/servlet/com.servlet.servlet1" method="post" name="iform">
    //project/servlet/com.servlet.servlet1为servlet的路径和名字
    <center>
    <input type="text" maxlength="10" size="20" name="T1" value="">
    <button type="submit">ok</button>
    </center>
    </form>
    </body>
    </html>servlet1.java:
    package com.servlet.servlet1;import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;public class servlet1 extends HttpServlet {
      public void doPost(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {
          HttpSession session = req.getSession(true);
          String str1 = req.getParameter("T1");
          String str2 = "Hello" + str1 + ", Welcome!"
          session.putValue("str2", str2);  RequestDispatcher rd =getServletContext().getRequestDispatcher("/jsp/jsp2.jsp");
      rd.forward(req, res);
      }
    }jsp2.jsp:
    <html>
    <head><%@ page contentType="text/html;charset=gb2312" %></head><body>
    <center>
    <br><form>
    <%
    String str3 = (String)session.getValue("str2");
    %>
    <h3><%= str3%></h3>
    <center>
    </center>
    </form>
    </body>
    </html>