Wenas, pues yo una vez tuve que hacer algo parecido en Struts 1.x,
en mi jsp ponia
codigo javascript
Código PHP:
jQuery('a[name=exportar]').click(function (){
jQuery('#forma').attr("action",'<%=request.getContextPath()%>/repLevels.do?vinculo=exportarExcel');
jQuery( "#dialogGraficas").dialog( "close" );
jQuery( '#forma').submit();
});
en mi jsp tenia
Código PHP:
<div class=" contSinTab "></div>
<div class="right controles">
<a class="boton-rojo" name="exportar" id="exportar"><bean:message key='sistema.createGraphic' /></a>
</div>
Y en el action
Código PHP:
public ActionForward exportarExcel(ActionMapping mapping, ActionForm forma,
HttpServletRequest request, HttpServletResponse response) {
........
try {
ArrayList exportList=(ArrayList)request.getSession().getAttribute("nivelesList");
.................//mas codigo
report = new RepLevelsExcel();
report.process(request,response, tipograf, exportList,formtemp);
actionForward = "success";
} catch (Exception e) {
actionForward = "error";
} finally {
return (mapping.findForward(actionForward));
}
}
Y para el excel yo use plantillas
Código PHP:
..........//mas codigo
/** Excel file used as template */
public static final String EXCEL_FILE_LEVELS = "/plantilla_reportes/ReporteNivelesService.xls";
public RepLevelsExcel() {
}
/**Processes requests for both HTTP GET and POST methods.
* @param request servlet request
* @param response servlet response
*/
public void process(HttpServletRequest request, HttpServletResponse response, String graficas, ArrayList lista, BeanForm form) throws ServletException, IOException {
String[] abc = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
HttpSession session = request.getSession();
ServletContext context = session.getServletContext();
String pathreal = context.getRealPath(EXCEL_FILE_LEVELS);
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(pathreal));
HSSFWorkbook libro = new HSSFWorkbook(fs);
HSSFCell cel = null;
hoja = libro.getSheetAt(0);
hoja = libro.getSheetAt(3);
for (int i= 1;i<=3;i++){
cel = setCell(abc[1] + i, form.getFechaSinIni()+" al "+form.getFechaSinFin());
}
hoja = libro.getSheetAt(2);
...............//mas codigo
response.setContentType("application/xls");
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy_HH:mm:ss");
response.setHeader("Content-disposition", "attachment;filename=Services_"+sdf.format(cal.getTime())+".xls");
libro.write(response.getOutputStream());
Saludos, espero te ayude esto