java - Cannot get the passing values from jsp to servlet -
if run jsp, while exporting contents excel, not getting values in downloaded excel file. empty. here tried..
how pass table values servlet?
excel.jsp
<%@ page language="java" contenttype="text/html; charset=iso-8859-1" pageencoding="iso-8859-1"%> <%@ page import ="javax.swing.joptionpane"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>export excel - demo</title> </head> <body> <table align="left" border="2"> <thead> <tr bgcolor="lightgreen"> <th>sr. no.</th> <th>text data</th> <th>number data</th> </tr> </thead> <tbody> <% (int = 0; < 10; i++) { %> <tr bgcolor="lightblue"> <td align="center"><%=i + 1%></td> <td align="center">this text data <%=i%></td> <td align="center"><%=i * i%></td> </tr> <% } %> </tbody> </table> <a href="sample?exporttoexcel=yes">export excel</a> </body> </html>
sample.java (servlet)
import java.io.ioexception; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; public class sample extends httpservlet { private static final long serialversionuid = 1l; public sample() { super(); } protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { string exporttoexcel = request.getparameter("exporttoexcel"); if (exporttoexcel != null && exporttoexcel.tostring().equalsignorecase("yes")) { response.setcontenttype("application/vnd.ms-excel"); response.setheader("content-disposition", "inline; filename=" + "excel.xls"); } } protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // todo auto-generated method stub } }
if trying export
table (or web page) excel
file need write download (response) code inside same .jsp
in case.
add following in excel.jsp
file.
<%//use scriptlet if (exporttoexcel != null && exporttoexcel.tostring().equalsignorecase("yes")) { response.setcontenttype("application/vnd.ms-excel"); response.setheader("content-disposition", "inline; filename=" + "excel.xls"); } %> //in short copy whole code servlet's method , paste in scriplet
so here apparently calling own .jsp
, handling request , exporttoexcel
equal yes
give file content on .jsp
.
Comments
Post a Comment