我试图通过href将一个字符串从我的jsp传递给servlet。我用这个
<a href="MyServlet?select=title1"> Title1 </a>
然后在servlet中我试图用这个
获取select的值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 :(得分:0)
那不应该是String userOption = request.getAttribute("select");
请理解属性不是参数
应为String userOption = request.getParameter("select");