web 開發中的條件查詢實現

2021-08-08 20:55:04 字數 1803 閱讀 9684

在form表單中有如下**

商品名稱是否熱門不限是否

商品類別不限$

商品類別為資料庫中查詢來的,表單提交到如下位址

action="$/adminsearchproduct" method="post"

在adminsearchproductservlet中**如下

實現

protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception  catch (illegalacces***ception | invocationtargetexception e) 

adminproductlistservice service = new adminproductlistservice();//將資料傳遞帶service層

listproducts = null;

try catch (sqlexception e)

//獲取商品類別

listcategories = null;

try catch (sqlexception e)

request.setattribute("condition", condition);

request.setattribute("categories", categories);

request.setattribute("products", products);

request.getrequestdispatcher("/admin/product/list.jsp").forward(request, response);

}

condition類實現如下

package com.vo;

public class condition

public void setpname(string pname)

public string getis_hot()

public void setis_hot(string is_hot)

public string getcid()

public void setcid(string cid)

}

service層中

public listfindproductbycondition(condition condition) throws sqlexception

dao層中

public listfindproductbycondition(condition condition) throws sqlexception 

if (condition.getis_hot()!=null&&!condition.getis_hot().trim().equals(""))

if (condition.getcid()!=null&&!condition.getcid().trim().equals(""))

listproducts = qrunner.query(sql.tostring(), new beanlisthandler(product.class), parms.toarray());

return products;

}

WEB開發中實現會話跟蹤實現

會話跟蹤是一種靈活 輕便的機制,它使web上的狀態程式設計變為可能。有四種方法可以實現會話跟蹤技術 url重寫 隱藏表單域 cookie session。1 隱藏表單域 非常適合步需要大量資料儲存的會話應用。2 url 重寫 url 可以在後面附加引數,和伺服器的請求一起傳送,這些引數為名字 值對。...

web開發中實現會話跟蹤

1.cookie 結合session使用 可以使用 cookie 儲存購物會話的 id 在後續連線中,取出當前的會話 id,並使用這個 id 從伺服器上的查詢表 lookup table 中提取出會話的相關資訊。以這種方式使用 cookie 是一種絕佳的解決方案,也是在處理會話時最常使用的方式。但是...

django中如何實現多條件查詢

一 使用字典儲存查詢條件 獲取查詢條件 start date request.post.get start date end date request.post.get end date order type request.post.get order type order nature requ...