I am using the below code to get the data to an excel sheet. But unfortunately nothing is working for me. I am not getting any dialogbox upon clicking on the anchor links to save the output to .xlsx or doc format.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
It seems that you're under the impression that by setting a content type header you can make a JSP page emit a Word or Excel document. That's not the case - you need to use a library like Apache POI which can create both those file types.
I don't understand at all what you're trying to do with the File object you're creating, but since the whole approach won't work as is, that's probably a moot point.