URL中问号后的Attribute传值失败有什么原因?

J2EE 码拜 9年前 (2015-04-22) 1013次浏览 0个评论
 

在跟着视频在学习, 这里出现了问题
就是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 {

		}
	}
URL中问号后的Attribute传值失败有什么原因?
10分
String type = request.getParameter("type");
URL中问号后的Attribute传值失败有什么原因?
10分
getParameter,方法用错了,getAttribute只能取得setAttribute的值

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明URL中问号后的Attribute传值失败有什么原因?
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!