开发者

How to invoke a function in java file from a java file

开发者 https://www.devze.com 2023-02-19 04:02 出处:网络
I have开发者_开发知识库 two java files named Admin.java and Search.java in the same folder. I need to call the Search doGet Method. How do I do it?

I have开发者_开发知识库 two java files named Admin.java and Search.java in the same folder. I need to call the Search doGet Method. How do I do it?

I need to invoke

protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

present in the Search.java file.


Depends on the Search-ctor, and whether you have request/response objects already.

Search search = new Search (/*...*/);
search.doGet (request, response);


Technically spoken,

  1. create an instance of Search
  2. call the doGet() method on that instance

But we usually don't call doGet directly, so I'm strongy in doubt, if that's what you really want...

// in some method in Admin.java

Search search = new Search();
try {
   search.doGet(someRequest, someResponse);
} catch (ServletException e) {
   // TODO handle exception
} catch (IOException e) {
   // TODO handle exception
}


Since your Search.java looks like a Servlet, you'd have to invoke it by hitting a URL mapped to this Servlet. See more here

0

精彩评论

暂无评论...
验证码 换一张
取 消