java - Couldn't get the 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> <p> fsfndfkdsfdkfjsfksfskfsfskfsfksfskf dfkdjfkfksfkkkkkkkkkjjjjjjjjj </p> <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; /** * servlet implementation class sample */ public class sample extends httpservlet { private static final long serialversionuid = 1l; /** * @see httpservlet#httpservlet() */ public sample() { super(); // todo auto-generated constructor stub } /** * @see httpservlet#doget(httpservletrequest request, httpservletresponse response) */ protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // todo auto-generated method stub 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"); } } /** * @see httpservlet#dopost(httpservletrequest request, httpservletresponse response) */ protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // todo auto-generated method stub } }
try this:
<%@ page language="java" contenttype="application/vnd.ms-excel" 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> <p> fsfndfkdsfdkfjsfksfskfsfskfsfksfskf dfkdjfkfksfkkkkkkkkkjjjjjjjjj </p> <a href="sample?exporttoexcel=yes">export excel</a>
Comments
Post a Comment