![](/img/trans.png)
[英]Is there any better way to pass the value from jsp to the servlet using <a href>
[英]pass value from jsp to servlet using <a href>
我有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()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.