' "+response.encodeURL("Step2")+"'
仔细看看,多了一个空格啊

解决方案 »

  1. 可能是step2位置中指向的servlet没定义post方法
      

  2. 检查了半天还是没搞定,我把源码贴上来大家帮忙看一下:(STEP1。JAVAimport java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;public class Step1 extends HttpServlet
    {
        public Step1()
        {
        }    public void doGet(HttpServletRequest request, HttpServletResponse response) throws
    IOException, ServletException
        {
    HttpSession session = request.getSession();
    displayPage(request, response);
        }    public void displayPage(HttpServletRequest request,
        HttpServletResponse response) throws IOException
        {
    response.setContentType("text/html;charset=gb2312");
    PrintWriter out = response.getWriter(); out.println("<html>");
    out.println("<head>");
    out.println("<title>Step 1:选择要购买的书籍</title>");
    out.println("</head>");
    out.println(
        "<meta http-equiv=Content-Type content=text/html;charset=GB2312>");
    out.println("<body>");
    out.println("<b><font size=4>Step 1:选择要购买的书籍</font></b>"); out.println("<form action='"+response.encodeURL("Step2")+"' method='POST'>");
    out.println("<table border=1 width=80%>");
    out.println("<tr>");
    out.println("<td align=center bgcolor=#008080>");
    out.println("<font color=#ffffff>书名</font>");
    out.println("</td>");
    out.println("<td align=center bgcolor=#008080>");
    out.println("<font color=#ffffff>购买</font>");
    out.println("</td>");
    out.println("</tr>");。以下HTML代码略。STEP2。JAVA
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;public class Step2 extends HttpServlet
    {
        public Step2()
        {
        }    public void doPost(HttpServletRequest request, HttpServletResponse response) throws
    IOException, ServletException
        {
    processStep1(request, response);
    displayPage(request, response);
        }    public void processStep1(HttpServletRequest request,
         HttpServletResponse response)
        {
    HttpSession session = request.getSession();
    String b[] = request.getParameterValues("buy");
    books booksWanted = new books(b);
    session.setAttribute("A_booksWanted", booksWanted);
        }    public void displayPage(HttpServletRequest request,
        HttpServletResponse response) throws IOException
        {
    response.setContentType("text/html;charset=gb2312");
    PrintWriter out = response.getWriter(); out.println(" <title>Step 2:输入寄送地址与信用卡信息</title>");
    out.println(
        "    <meta http-equiv=content-type content=text/html;charset=gb2312>");
    out.println("    <style type=text/css>");
    out.println("    <!--");
    out.println("    .style1 {color: #FFFFFF}");
    out.println("    -->");
    out.println("    </style>"); out.println("    <p>Step 2:输入寄送地址与信用卡信息</p>");
    out.println("    <form name=form1 method=post action="+response.encodeURL("Confirm2")+">");
    out.println("      <table width=80%  border=1>");
    out.println(" <tr bgcolor=#008080>");
    out.println("   <td colspan=2><span class=style1>基本信息</span></td>");
    out.println(" </tr>");
    以下HTML代码略。CONFIRM2。JAVA:public class Confirm2 extends HttpServlet
    {
        public Confirm2()
        {
        }    public void doPost(HttpServletRequest request, HttpServletResponse response) throws
    IOException, ServletException
        {
    processStep2(request, response);
    displayPage(request, response);
        }    public void processStep2(HttpServletRequest request,
         HttpServletResponse response) throws IOException
        {
    HttpSession session = request.getSession(true);
    String customername = new String(request.getParameter("customername").
     getBytes("iso-8859-1"));
    //byte[] java.lang.String.getBytes(String charsetName);以getBytes("iso-8859-1")方法取出以避免中文字的转码问题
    String address = new String(request.getParameter("address").getBytes(
        "iso-8859-1"));
    String credittype = request.getParameter("credittype");
    String expiredate = request.getParameter("expiredate");
    String creditno = request.getParameter("creditno"); session.setAttribute("A_customername", customername);
    session.setAttribute("A_address", address);
    session.setAttribute("A_credittype", credittype);
    session.setAttribute("A_expiredate", expiredate);
    session.setAttribute("A_creditno", creditno);    }    public void displayPage(HttpServletRequest request,
        HttpServletResponse response) throws IOException
        {
    response.setContentType("text/html;charset=gb2312");
    PrintWriter out = response.getWriter();
    HttpSession session = request.getSession(true); books booksWanted = (books) session.getAttribute("A_booksWanted");
    String customername = (String) session.getAttribute("A_customername");
    String address = (String) session.getAttribute("A_address");
    String credittype = (String) session.getAttribute("A_credittype");
    String creditno = (String) session.getAttribute("A_creditno");
    String expiredate = (String) session.getAttribute("A_expiredate");。谢谢各位~
      

  3. 搞定了。原来out.println("    <form name=form1 method=post action="+response.encodeURL("Confirm2")+">");这句要加两个单引号。= =b
    SERVLET和JSP不像ASP那样可以把所有的引号都去掉啊~~~
      

类似问题 »