我有jsp页面-

<html>
<head>
</head>
<body>
      <a href="http://localhost:8080/MyProject/Servlet123?usrID=33333">Go to servlet</a>
</body>
</html>


和servlet-

@WebServlet("/Servlet123")
public class Servlet123 extends HttpServlet {
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // take the ID and retrive all his accounts..
        String usrID = request.getAttribute("usrID").toString();
          }

}


当我按一下jsp页面中的链接时,它会引发异常

java.lang.NullPointerException


在该行中-String usrID = request.getAttribute("usrID").toString();

其他详细信息-我使用Apache Tomcat 7.0 Tomcat7。

最佳答案

使用getParameter()代替getAttribute()

07-28 08:28