0

我有一个 JSP,我从中将参数发送到另一个页面。但是另一个页面正在接受参数。我不知道原因。

如何从 URL 获取值到 JSP 中?

网址是 -

/ColdStorage/ajaxservlet?occid%20=%203

应该接受参数的 JSP 是 -

 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, ClassNotFoundException, SQLException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    String sql = "";
    PreparedStatement prest ;
    ResultSet rs;
     HttpSession session = null;
    try {
        /* TODO output your page here. You may use following sample code. */


        Class.forName("com.mysql.jdbc.Driver");
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ColdStorage?zeroDateTimeBehavior=convertToNull", "root", "root");
        System.out.println("entering ajaxservlet");
        String occid = (String) request.getParameter("occid");
        System.out.println("occid = "+occid);
        String resid = (String) request.getParameter("resid");
        System.out.println("resid = "+resid);
        String agrnoid = (String) request.getAttribute("agrno");
        System.out.println("agrnoid = "+agrnoid);

        List<AcceptBean> list1 = new ArrayList<AcceptBean>();
       // List<AcceptBean> list3 = new ArrayList<AcceptBean>();

        sql = "select om.OccId,om.FirstName,om.LastName,om.Village,om.SonOf,om.District, rd.ResId,rd.`Date`,"
                + "rd.Weight,rd.Bags,rd.Rate,rd.Amount,rd.advamount,am.agrno,am.lotno,am.`agreeDate`,am.reservid,"
                + "am.weight,am.bags,am.rate,am.amt,am.advamt from OccupantMaster om left outer join user_resdet ud on "
                + "om.OccId = ud.occ_det left outer join ReservationDetails rd on ud.res_det = rd.ResId left outer join "
                + "AgreementMaster am on rd.ResId = am.reservid where occid = ?  ";
        System.out.println("sql = "+sql);
        prest = conn.prepareStatement(sql);
        prest.setString(1, occid);
        rs = prest.executeQuery();
        String agreereservid = "";
        String Date = "";
        String Weight = "";
        String Rate = "";
        String Bags = "";
        String Amount = "";
        String Advance = "";
        String regisamount = "";
        String regisadvance = "";
        String Lotno = "";
4

1 回答 1

2

您的网址中有 2 个额外的空格:

occid%20=%203
sould be:
occid=3

或者当您查找 get 参数时,您应该查找“occid”

于 2013-05-12T11:44:58.790 回答