2013-05-12 99 views
0

我有一個JSP從我發送參數到另一個頁面。但其他頁面正在接受參數。我不知道原因。從URL獲取價值到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 = ""; 
+0

您想與我們分享的任何錯誤? – 2013-05-12 11:40:15

+0

沒有錯誤..謝謝 – Divyang 2013-05-14 08:46:28

回答

2

你在你有2個額外的空格網址:

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

或者當你尋找你應該尋找「occid」的get參數

+0

謝謝。你說得對。 – Divyang 2013-05-12 11:52:53

+0

@Divyang然後批准他的回答 – 2013-05-15 17:15:18

+0

@ mrhobo我批准了它。 – Divyang 2013-05-16 07:36:13