本文整理汇总了C++中HttpServletRequest::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpServletRequest::setAttribute方法的具体用法?C++ HttpServletRequest::setAttribute怎么用?C++ HttpServletRequest::setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest::setAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
void Products::process(HttpServletRequest& request, HttpServletResponse &response) {
map<string,string> params;
params["category_id"]=request.getParameter("category_id");
params["s_keyword"]=request.getParameter("s_keyword");
params["price_from"]=request.getParameter("price_from");
params["price_to"]=request.getParameter("price_to");
const string WHERE = where_part(params) ;
string query = "SELECT * FROM store_products"
+ WHERE
+ order_part(request.getParameter("productsOrder"), request.getParameter("productsDir"))
+ limit_part(request.getParameter("productsPageSize"), request.getParameter("productsPage"));
products_t products = fetch(query);
request.setAttribute("products", products);
query = "SELECT COUNT(*) FROM store_products" + WHERE;
int ResultsFound = count(query);
request.setAttribute("ResultsFound", ResultsFound);
int pageSize = getPageSize(request.getParameter("productsPageSize"));
int pageCount = static_cast<int>( ceilf(static_cast<float>(ResultsFound)/pageSize) );
request.setAttribute("pageCount", pageCount);
int currentPage = 1;
string s_currentPage = request.getParameter("productsPage");
if(!s_currentPage.empty())
currentPage = lexical_cast<int>(s_currentPage);
request.setAttribute("currentPage", currentPage);
request.setAttribute("naviLink",make_naviLink(request));
}
示例2: doGet
void Products::doGet(HttpServletRequest& request, HttpServletResponse &response) {
try{
request.setAttribute("categories", fetch_categories());
process(request, response);
}catch(const exception& ex) {
request.setAttribute<string>("error",ex.what());
request.setAttribute("ResultsFound", 0);
request.setAttribute("products", products_t());
request.setAttribute("naviLink",string());
request.setAttribute("currentPage", 0);
}
request.getRequestDispatcher("ProductsView.csp")->forward(request,response);
}
示例3: show_product
void ProductDetails::show_product(HttpServletRequest& request, HttpServletResponse &response) {
string id = request.getParameter("product_id");
if(id.empty())
throw runtime_error("ProductDetails: product_id parameter not supplyed");
Product product = fetch(id);
request.setAttribute("product", product);
request.getRequestDispatcher("ProductDetailsView.csp")->forward(request,response);
}
示例4: doGet
void ProductDetails::doGet(HttpServletRequest& request, HttpServletResponse &response) {
try{
request.getSession(true); //start session
show_product(request, response);
}catch(const exception& ex) {
request.setAttribute<string>("error",ex.what());
request.setAttribute("product",Product());
request.getRequestDispatcher("ProductDetailsView.csp")->forward(request,response);
}
}
示例5: doPost
void ProductDetails::doPost(HttpServletRequest& request, HttpServletResponse &response) {
try{
try{
add_to_cart(request, response);
}catch(const exception& ex) {
request.setAttribute<string>("error",ex.what());
show_product(request, response);
}
}catch(const exception& ex) {
request.setAttribute<string>("error",ex.what());
request.setAttribute("product",Product());
request.getRequestDispatcher("ProductDetailsView.csp")->forward(request,response);
}
}