调用链的潜在问题
在下面的代码片段中,我使用一个类来获取对 BookList 实例的引用。此类有一个 getBook() 方法,该方法从表示 isbn 代码的字符串返回 Book 的实例。该指令在 HttpServlet 的 doGet() 方法中运行。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Book book = GlobalVar.bookList.getBook( request.getParameter("isbn") );
//
}
您认为在这种情况下使用速记符号有哪些潜在问题?
PS:Global 类将被 ServletContext 取代。
In the snippet of code below, I'm using a class to get a reference to an instance of BookList. This class has a getBook() method which returns an instance of a Book from a String representing an isbn code. The instruction is run in the doGet() method of a HttpServlet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Book book = GlobalVar.bookList.getBook( request.getParameter("isbn") );
//
}
What potential problems do you see in using shorthand notation in this context ?
P.S: The Global class is going to be replaced with a ServletContext.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会说NullPointerExceptions。如果执行 HTTP GET 请求的客户端没有名为“isbn”的参数,会发生什么情况。 getBook 的实现方式是否支持 null 作为参数?
I would say NullPointerExceptions. What happends if the client, doing the HTTP GET request, has no paramated named "isbn". Is the getBook implemented in way that it supports null as an argument?
该请求可能没有参数“isbn”。
The request may not have a parameter "isbn".