我想通过href从我的jsp传递一个字符串到servlet。我用这个
getParameter在servlet中返回null
<a href="MyServlet?select=title1"> Title1 </a>
然后在servlet我想获得选择的值与此
String s = request.getParameter("select");
但它返回null
。这是为什么?谢谢!
编辑我张贴的servlet代码
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String userOption = request.getAttribute("select");
System.out.println("Select is:" + userOption);
//in the console i get: Select is:null
您的servlet已执行d? –
您的servlet是否正确调用?请显示网址格式和您的servlet方法 –
您确定已将此代码放入您的doGet方法中吗?因为任何链接都会导致doGet方法调用 –