2013-08-07 72 views
3

我想通过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 
+0

您的servlet已执行d? –

+0

您的servlet是否正确调用?请显示网址格式和您的servlet方法 –

+0

您确定已将此代码放入您的doGet方法中吗?因为任何链接都会导致doGet方法调用 –

回答

0

这不应该是String userOption = request.getAttribute("select");

请理解属性不是参数

应该String userOption = request.getParameter("select");

+0

确定这是非常愚蠢的我..我把getAttribute(),但我想我已经把getParameter().. thx无论如何! – yaylitzis

+0

不用担心......发生在我身上:) –