在跟着视频在学习, 这里出现了问题
就是URL中?后面的Attribute在Servlet中读取不到, 实在想不出是为什么
index页面中:
<a href="/10JSP_Project/servlet/CollectionServlet?type=list">进入</a>
CollectionServlet中:
save和list是另外两个方法, 我想通过一个type属性来决定执行哪个方法.
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String type = (String) request.getAttribute("type");
System.out.println(type); //为什么输出值为null?
if(type!=null && type.equals("save")){
save(request, response);
}else if(type!=null && type.equals("list")){
list(request, response);
}else {
}
}
------解决方案--------------------
String type = request.getParameter("type");
------解决方案--------------------
getParameter,方法用错了,getAttribute只能取得setAttribute的值