gpt4 book ai didi

java - 在java web应用程序中找不到对象的实例化(响应、请求、应用程序)

转载 作者:行者123 更新时间:2023-12-01 11:14:00 24 4
gpt4 key购买 nike

我必须开发一个别人做过的java web应用程序。由于我是 java web 开发的新手,我扫描了一些代码并偶然发现了一些实例化对象,在这些对象中我找不到对其实例化位置的引用,即在 .jsp 页面中

    ...some includes
UserFactory uf=null;

if (application.getAttribute("userFactory") == null){
...
strUser=request.getParameter("user");
pw=request.getParameter("pw");
...

(通知应用程序、请求、响应)

现在我意识到它可能已在某些包含中声明,并且我确实浏览了所有内容但找不到声明(尽管我确实监督了它)。现在的问题是:这些对象是否以某种方式由 tomcat 全局实例化(如果是,我在哪里可以找到),如果不是这种情况,如何在一个相当大的项目中找到它们(顺便说一句,我正在使用 Eclipse JUNO)(即像Eclipse 的功能来查找实例化),最好不要手动查看每个单独的包含。

最佳答案

在 JSP 中,这些变量称为“隐式对象”。在此处查找 JSP 中可用的所有隐式对象:http://docs.oracle.com/javaee/5/tutorial/doc/bnahq.html#bnaij :

Implicit Objects

The JSP expression language defines a set of implicit objects:

  • pageContext: The context for the JSP page. Provides access to various objects including:
    • servletContext: The context for the JSP page’s servlet and any web components contained in the same application. See Accessing the Web Context.
    • session: The session object for the client. See Maintaining Client State.
    • request: The request triggering the execution of the JSP page. See Getting Information from Requests.
    • response: The response returned by the JSP page. See Constructing Responses.

In addition, several implicit objects are available that allow easy access to the following objects:

  • param: Maps a request parameter name to a single value
  • paramValues: Maps a request parameter name to an array of values
  • header: Maps a request header name to a single value
  • headerValues: Maps a request header name to an array of values
  • cookie: Maps a cookie name to a single cookie
  • initParam: Maps a context initialization parameter name to a single value

Finally, there are objects that allow access to the various scoped variables described in Using Scope Objects.

  • pageScope: Maps page-scoped variable names to their values
  • requestScope: Maps request-scoped variable names to their values
  • sessionScope: Maps session-scoped variable names to their values
  • applicationScope: Maps application-scoped variable names to their values

关于java - 在java web应用程序中找不到对象的实例化(响应、请求、应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32047452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com