实现一个jsp页面一个servlet多种展示效果

在这里插入图片描述
在这里插入图片描述
  图一是商品的默认排序,URL地址栏:http://localhost:8080/onlineMall/ShowGoodsServlet.do?showType=orderByDefault
  图二是商品按价格降序,URL地址栏:
http://localhost:8080/onlineMall/ShowGoodsServlet.do?showType=orderByPriceDown
  都是请求到名为ShowGoodsServlet.do的servlet中,唯一变化的是参数showType值发生了变化。利用这个参数,后台通过request.getParameter(“showType”)可以判断应该返回什么样的数据。如果是orderByDefault是默认排序;如果是orderByPriceDown,则按价格降序。
  前端页面请求的时候,加上“?参数名=参数值”就行了。

	  <a href="ShowGoodsServlet.do?showType=orderByDefault">
		<div class="defaultSort">
			默认排序
		</div>
	  </a>

其它的以此类推,搜索功能也是利用了这个方法(如showType=searchByName)。

猜你喜欢

转载自blog.csdn.net/qq_47234534/article/details/107864436