'How to call servlet written inside another class in Java
My requirement is downloading an excel file from a web application by clicking a button named "Report" . The excel file is placed in server. I have written a servlet inside a main class for downloading Excel file in browser.
However, before downloading the file, I need to do some calculations and have to display in the excel file based on the key value(For eg. OrderNo) from the current screen.
The application maintains pagecontext and webbean variables for keeping track of pages. The code block looks like as follows.
public class MainClassA
{
if pageContext.getParameter("Report")!=null //Button click
{
string filePath="/server/someFile.xls";
DownloadFile(pagecontext,webBean,filePath);
}
public void DownloadFile(pagecontext,webBean,filePath)
{
//Excel calculation steps
//Here I tried to call servlet
}
public ExServlet extends HttpServlet
{
protected doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
System.out.println("Inside doGet"+request);
doPost(request, response);
System.out.println("Hello World");
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
//doPost code
}
}
}
Now the problem is, how to call the servlet inside the main class. I have included the servlet in web.xml file. When I run the code I'm not getting any errors on compiling. But when I click the button, nothing happens. Can anyone tell me where I'm missing?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
