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,
- create an instance of
Search
- 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
精彩评论