Exception when trying to forward to different url in Tapestry 3 - exception

I've this tapestry application, I've a html and a backend java class, the html part:
<html>
<head>
<title>Starter Page</title>
</head>
<body>
<span jwcid="#Insert" value="ognl: errorMessage" />
<form jwcid="#Form" method="POST" listener="ognl:listeners.filterContracts">
<table style="width: 100%;" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<label jwcid='#vitech:Label' element="span" labelOverride="Choose Criteria"/>
</td>
<td>
<select jwcid="criteriaSelect#Select">
<foreach jwcid="#Foreach" source="ognl: criterias" value="ognl:currentCriteria" index="ognl:currentCriteriaIndex">
<option jwcid="#Option" selected="ognl:selection[currentCriteriaIndex]" label="ognl:currentCriteria"/>
</foreach>
</select>
</td>
</tr>
<tr>
<td>
<label jwcid='#vitech:Label' element="span" labelOverride="Criteria Value"/>
</td>
<td>
<input jwcid="#TextField" value='ognl: criteriaValue' />
</td>
</tr>
<tr>
<td>
<label jwcid='#vitech:Label' element="span" labelOverride="Username"/>
</td>
<td>
<input jwcid="#TextField" value='ognl: username' />
</td>
</tr>
<tr>
<td>
<input type="submit" jwcid="getcontract#Submit" label="ognl: 'Get Contracts'" />
</td>
</tr>
</table>
</form>
</body>
the event listener filterContracts in the java class:
public void filterContracts(IRequestCycle cycle) {
if(cycle.isRewinding()) {
try {
errorMessage = "";
String selectedCriteriaString = cycle.getRequestContext().getRequest().getParameter("criteriaSelect");
MetlinkVisit metlinkVisit = (MetlinkVisit)getEmployerVisit();
int selectedCriteria = Integer.parseInt(selectedCriteriaString);
List<MemberContract> allMemberContractsWithEmployer = loadEmployerBySecurityUser(username);
if(allMemberContractsWithEmployer != null && allMemberContractsWithEmployer.size() > 0) {
FilterMembersContractsByCriteria filter;
List<MemberContract> filteredMembersContractsWithEmployer;
switch(selectedCriteria) {
case 0:
filter = new FilterMembersContractsBySSN();
break;
case 1:
filter = new FilterMembersContractsByLastName();
break;
case 2:
filter = new FilterMembersContractsByGAB();
break;
case 3:
filter = new FilterMembersContractsByCertificate();
break;
default:
filter = new FilterMembersContractsBySSN();
break;
}
filteredMembersContractsWithEmployer = filter.filterAllMembersContractsWithEmployerUsingCriteria(allMemberContractsWithEmployer, criteriaValue);
if(filteredMembersContractsWithEmployer != null && filteredMembersContractsWithEmployer.size() > 0) {
metlinkVisit.setFilteredContracts(filteredMembersContractsWithEmployer);
HttpServletRequest request = cycle.getRequestContext().getRequest();
HttpServletResponse response = cycle.getRequestContext().getResponse();
String uri = request.getRequestURI();
String url = uri + "?un=" + username + "&service=external/Metlink:SummaryPage";
request.getRequestDispatcher(url).forward(request, response);
} else {
errorMessage = "Criteria doesn't match any record, try different criteria";
}
}
}catch (Exception e) {
errorMessage = e.getMessage();
}
}
}
but I'm getting this exception when I forward to Metlink Summary page, and this page is loading fine:
Exceptions:
java.io.IOException: Closed
org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:140)
org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:86)
org.apache.tapestry.request.ResponseOutputStream.innerWrite(ResponseOutputStream.java:246)
org.apache.tapestry.request.ResponseOutputStream.open(ResponseOutputStream.java:186)
org.apache.tapestry.request.ResponseOutputStream.forceFlush(ResponseOutputStream.java:144)
org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:928)
org.apache.tapestry.ApplicationServlet.doService(ApplicationServlet.java:197)
com.vitechinc.core.VitechApplicationServlet.doService(VitechApplicationServlet.java:310)
org.apache.tapestry.ApplicationServlet.doPost(ApplicationServlet.java:326)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:527)
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1216)
org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1187)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1187)
com.vitechinc.v3.core.connectionmanagement.ConnectionSettingsFilter.doFilter(ConnectionSettingsFilter.java:79)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1187)
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:421)
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:493)
org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:930)
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:358)
org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:866)
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
org.eclipse.jetty.server.Server.handle(Server.java:351)
org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:594)
org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1058)
org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:764)
org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:217)
org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:424)
org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:489)
org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:436)
java.lang.Thread.run(Thread.java:662)
I guess that something is wrong in the rewinding cycle

Related

How do I display the content fetched from database(using the jsp file) on my html page using ajax?

I have a HTML file named Track.html, it contains a text box. We enter a 10 digit number and click the button to search. After validation an AJAX function is called, which sends the number to a jsp file and the input number is searched in the database, if the value is found in the database, the output should be displayed in another text box on the same HTML page(without changing the URL). But the problem is that it is not working.
To check that my jsp file is working properly, I did the following:
I'm using a form tag so in its action attribute I mentioned the jsp file and not calling the AJAX function, so after searching the input number it redirects to a new page and displays the corresponding content fetched from the database, but I want the content to be displayed on the same page.
Here is the HTML part:
<fieldset>
<form method="post">
<table cellpadding="10" cellspacing="10">
<tr>
<td><strong>Consignment Number</strong></td>
<td><input type="text" id="cons" name="cons" autofocus="true"
placeholder="Enter the 10 digit Consignment Number"
</td>
</tr>
<tr>
<td align="center"><button onclick="search()
<span>Search</span></button></td>
<td><span><input type="reset"></span></td>
</tr>
</table>
</form>
</fieldset>
<br>
<fieldset>
<table cellpadding="10" cellspacing="10">
<tr>
<td><strong>Your Package is at:</strong></td>
<td><input type="text" id="result"></td>
</tr>
</table>
</fieldset>
Here is the AJAX function:
function search() {
if (validate()) {
var cnum = document.getElementById('cons').value;
var obj1 = new XMLHttpRequest();
obj1.onreadystatechange = function () {
if ((obj1.readyState == 4) && (obj1.status == 200)) {
document.getElementById("result").value = obj1.responseText;
}
}
obj1.open("get", "Trace.jsp?cn=" + cnum, true);
obj1.send();
}
Here is the jsp code:
<%#page import="java.sql.*"%>
<%
try
{
int conum=Integer.valueOf(request.getParameter("cn"));
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/postal_info","root","*******");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from trace;");
while(rs.next())
{
int c=rs.getInt(3);
if(conum==c)
{
out.println(rs.getString(6));
}
}
}
catch(Exception e)
{
out.println(e);
}
%>

How to get data from DB dynamically based on textbox input using JSP?

I am using JSP as my backend for my HTML and I want to get the customer name when I start entering the customer contact number.
HTML:
<html>
<body>
<script>
function evaluation() {
var myBox1 = document.getElementById('milk').value;
var result = document.getElementById('result');
var myResult = myBox1 * 35;
result.value = myResult;
}
</script>
<form action="BillValid.jsp" method="post">
<table width="70%" cellspacing="30" color="#FFFFFF">
<tr>
<th>ENTER THE DETAILS</th>
</tr>
<tr>
<td><font color="#800000">Customercontact</font></td>
<td><input name="cus_contact" type="text" id="contact"></td>
</tr>
<tr>
<td><fontcolor="#800000">CustomerName</font></td>
<td><input type="text" name="cus_name"></td>
</tr>
<tr>
<td> </td>
<td></td>
</tr>
<tr>
<td><font color="#800000">DayConsumption</font></td>
<td><input id="milk" type="text" name="days_con"
oninput="evaluation()"></td>
</tr>
<tr>
<td><font color="#800000">SumInRs</font></td>
<td><input id="result" name="total"</td>
</tr>
<tr>
<td> </td>
<td></td>
</tr>
</table>
<input type="submit" name="Register"><input type="reset"
name="reset">
</form>
</body>
</html>
JSP:
try{
String DBuser="root";
String DBpassword="qwerty";
String Connection="jdbc:mysql://localhost:3306/online";
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection conn=DriverManager.getConnection(Connection,DBuser, DBpassword);
out.println("Database Succesfully connected");
String CustomerName=request.getParameter("cus_name");
String contact=request.getParameter("cus_contact");
long customerCon=Long.parseLong(contact);
String dayCons=request.getParameter("days_con");
int Consumtion=Integer.parseInt(dayCons);
String total =request.getParameter("total");
int totalConsume=Integer.parseInt(total);
String sql = "select (CustomerName) from customer where CustomerContact='"+ customerCon+"'";
java.sql.PreparedStatement st=conn.prepareStatement(sql);
java.sql.PreparedStatement pst=conn.prepareStatement("insert into invoice (CustomerContact ,CustomerName ,LitresConsumed ,TotalSum) values (?,?,?,?)");
pst.setLong(1, customerCon);
pst.setString(2, CustomerName);
pst.setInt(3, Consumtion);
pst.setInt(4, totalConsume);
int i=pst.executeUpdate();
if(i>0){
response.sendRedirect("BillData.jsp");
}else{
response.sendRedirect("addcustomer.jsp");
}
}catch(Exception e){
out.println(e);
e.getMessage();
}
Welcome to SO, I've got some points for you.
I shall very thank full to you if you could send me the code of that function as I don't have any idea about AJAX.
1) That's not how this site works. Please read How do I ask a good question?.
We'll help you to resolve your issues, before that you go to try something from your end.
2) JSP is not the right place to code Java. Please check How to avoid Java code in JSP files?
You should keep your Java code in servlet. When ajax calls a request point it to sevlet and do Java code over there and return expected output.
JSP should be used to render the output.
package com.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 MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String customerContact = request.getParameter("myValue");
String customerName = "Your_Response_From_DB";
response.setContentType("text/plain");
response.getWriter().write(customerName);
}
}
And in your web.xml file,
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
Few corrections in your HTML,
Add ID to Customer Name (Use meaningful names).
<tr>
<td><font color="#800000">Customercontact</font></td>
<td><input name="customer_contact" type="text" id="customer_contact"></td>
</tr>
<tr>
<td><fontcolor="#800000">CustomerName</font></td>
<td><input type="text" name="customer_name" id="customer_name"></td>
</tr>
If you want to return back the same page use jQuery ajax,
download the jQuery plugin add it in your JSP page.
$("#customer_contact").blur(function(e){
var contact = $(this).val();
$.ajax({
type : 'post',
url : 'MyServlet',
data: { myValue: contact},
success : function(data) {
console.log(data);
$("#customer_name").val(data);
}
});
});
Let me know if this helps.
Cheers..!

Image is not getting uploaded in directory using JSP

I just wanted to upload the image using form in JSP, for that I have written a code, as per below code, it is not inserting in while loop. resultant Image is not getting uploaded in directory.
Can you please help to figure out the problem?
html code
<html>
<head><title>Upload page</title></head></p> <p><body>
<form action="upload_jsp.jsp" method="post" enctype="multipart/form-data" name="form1" id="form1">
<center>
<table border="2">
<tr>
<td align="center"><b>Multipale file Uploade</td>
</tr>
<tr>
<td>
Specify file: <input name="file" type="file" id="file">
<td>
</tr>
<tr>
<td>
Specify file:<input name="file" type="file" id="file">
</td>
<tr>
<td>
Specify file:<input name="file" type="file" id="file">
</td>
</tr>
<tr>
<td align="center">
<input type="submit" name="Submit" value="Submit files"/>
</td>
</tr>
</table>
<center>
</form>
</body>
</html>
jsp code
<%# page import="java.util.List"%>
<%# page import="java.util.Iterator"%>
<%# page import="java.util.ResourceBundle" %>
<%# page import="java.io.File"%>
<%# page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%# page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%# page import="org.apache.commons.fileupload.*"%>
<%
String path= "C:\\Users\\gur29175\\Desktop" ;
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart) {
} else {
String directory="";
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = null;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
e.printStackTrace();
}
Iterator itr = items.iterator();
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
if (item.isFormField()) {
} else {
try {
String itemName = item.getName();
File savedFile = new File(path+itemName);
//File savedFile = new File("C:\\Users\\sagar\\Desktop\\JAVA Training\\code(1)\\test\\WebContent\\WEB-INF\\uploads\\"+itemName);
//File savedFile = new File(config.getServletContext ().getRealPath("/")+"uploadedFiles/"+itemName);
item.write(savedFile);
//out.println("<tr><td><b>Your file has been saved at the loaction:</b></td></tr><tr><td><b>"+config.getServletContext().getRealPath
//("/")+"uploadedFiles"+"\\"+itemName+"</td></tr>");
out.println("<tr><td><b>Your file has been saved at the loaction:</b></td></tr><tr><td><b>"+path+
("/")+"uploadedFiles"+"\\"+itemName+"</td></tr>");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
%>
This is the line of code that might be problematic, as item.getName() will return the full path where the source file is located. This might result to a malformed file path.
Try replacing:
String itemName = item.getName();
with:
String itemName = FilenameUtils.getName(item.getName());
Make sure FilenameUtils is imported:
<%# page import="org.apache.commons.io.FilenameUtils" %>
and you have commons-io.jar in your Web app libraries.

Get row when checking checkbox in html table

I have a HTML table with a checkbox in one of the columns. I want to know how I could get the row data when the user clicks on the checkbox with javascript (without jquery)? Can anyone please help me with this?
Thanks
HTML DOM solves your problem
<script type="text/javascript">
function getRow(n) {
var row = n.parentNode.parentNode;
var cols = row.getElementsByTagName("td");
var i=0;
while (i < cols.length) {
alert(cols[i].textContent);
i++;
}
}
</script>
<table>
<tr>
<td><input type="checkbox" onclick="getRow(this)" /></td>
<td>aaa</td>
<td>bbb</td>
</tr>
<tr>
<td><input type="checkbox" onclick="getRow(this)" /></td>
<td>ccc</td>
<td>ddd</td>
</tr>
<tr>
<td><input type="checkbox" onclick="getRow(this)" /></td>
<td>eee</td>
<td>fff</td>
</tr>
</table>
EDIT:
this script will help you more, I think:
function getRow(n) {
var row = n.parentNode.parentNode;
var cols = row.getElementsByTagName("td");
var i = 0;
while (i < cols.length) {
var val = cols[i].childNodes[0].nodeValue;
if (val != null) {
alert(val);
}
i++;
}
}
You could try something like this:
HTML:
<table>
<thead>
<tr><th></th><th>Row Text</th></tr>
</thead>
<tr>
<td><input type="checkbox" /></td>
<td>Test</td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td>Test 2</td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td>Test 3</td>
</tr>
</table>
JavaScript:
checkboxes = document.getElementsByTagName("input");
for (var i = 0; i < checkboxes.length; i++) {
var checkbox = checkboxes[i];
checkbox.onclick = function() {
var currentRow = this.parentNode.parentNode;
var secondColumn = currentRow.getElementsByTagName("td")[1];
alert("My text is: " + secondColumn.textContent );
};
}
JSFiddle: http://jsfiddle.net/markwylde/wzPHF/1/
if your select is in td directly, try the following:
sel.onclick = function(){
row = this.parentNode.parentNode
//then what you need
}
Note that first you have to find sel with either document.getElementById() or document.getElementsByTagName()
Also you may need to handle onchange event instead of onclick
This will give you content of row directly(all td in tr)
HTML:
<table>
<tr id="tr1">
<td>
<input type="checkbox" value="chkbox1" id="chk1">
</td>
<td>
Lorem ipsum text
</td>
</tr>
<tr id="tr2">
<td>
<input type="checkbox" value="chkbox2" id="chk2">
</td>
<td>
Lorem ipsum text
</td>
</tr>
</table>
Jquery:
$(document).ready(function(){
$('#chk1, #chk2').on('change',function(){
if($('#chk1').prop('checked') || $('#chk2').prop('checked'))
{
var ids=$(this).parent().parent().html();
alert(ids);
}
else
{
}
});
})
if you're new :
onChange EVENT of the checkbox will call the function that i named "checking"
it will send "This.checked", which means, will send True or false to the function "checking", Then i go in the function get that True or False that was sent, and put it in a variable i called "temp".
HTML: onchange="checking(this.checked)" <--- sending out : "This.checked" ( This = the object that creates the Event onchange, and .checked, is the propriety)
you could even send multiple info like this : onchange="checking(this.checked,this.id)" and so on.
JAVASCRIPT :function checking(temp) <--- this is how it gets the "this.checked" in HTML, and put it in the variable temp.
to receive multiple infos : function checking(temp,temp2) and so on.(name it like you want)
then i run a 'IF' with the variable "temp" and if the value of it = true, then do alert.
Hope it helps, think about it and work it so it fits what you need !
HTML :
<table>
<tr>
<td>
<input type="checkbox" value=""onchange="checking(this.checked)">
</td>
<td>
<label>Something Here</label>
</td>
</tr>
</table>
JAVASCRIPT :
function checking(temp)
{
if(temp == true)
{
alert("Checkbox is checked");
}
else
{
alert("Checkbox is NOT checked");
}
}

How to export JSP table to EXCEL (XLSX Format)

<%# page language="java" contentType="application/vnd.ms-excel"%>
<% response.setHeader("Content-Disposition:","attachment;filename=Sample.xls"); %>
<TABLE>
<TR><TD>2</TD></TR>
<TR><TD>3</TD></TR>
<TR><TD>5</TD></TR>
</TABLE>
How to export the JSP table in XLSX format and how to suppress the following exception
The file you are trying to open, name.ext, is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
use this
html code
<!DOCTYPE html>
<html>
<head>
<title>tableToExcel Demo</title>
<script>
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})()
</script>
</head>
<body>
<h1>tableToExcel Demo</h1>
<p>Exporting the W3C Example Table</p>
<input type="button" onclick="tableToExcel('testTable', 'W3C Example Table')" value="Export to Excel">
<table id="testTable" summary="Code page support in different versions of MS Windows." rules="groups" frame="hsides" border="2"><caption>CODE-PAGE SUPPORT IN MICROSOFT WINDOWS</caption><colgroup align="center"></colgroup><colgroup align="left"></colgroup><colgroup span="2" align="center"></colgroup><colgroup span="3" align="center"></colgroup><thead valign="top"><tr><th>Code-Page<br>ID</th><th>Name</th><th>ACP</th><th>OEMCP</th><th>Windows<br>NT 3.1</th><th>Windows<br>NT 3.51</th><th>Windows<br>95</th></tr></thead><tbody><tr><td>1200</td><td style="background-color: #00f; color: #fff">Unicode (BMP of ISO/IEC-10646)</td><td></td><td></td><td>X</td><td>X</td><td>*</td></tr><tr><td>1250</td><td style="font-weight: bold">Windows 3.1 Eastern European</td><td>X</td><td></td><td>X</td><td>X</td><td>X</td></tr><tr><td>1251</td><td>Windows 3.1 Cyrillic</td><td>X</td><td></td><td>X</td><td>X</td><td>X</td></tr><tr><td>1252</td><td>Windows 3.1 US (ANSI)</td><td>X</td><td></td><td>X</td><td>X</td><td>X</td></tr><tr><td>1253</td><td>Windows 3.1 Greek</td><td>X</td><td></td><td>X</td><td>X</td><td>X</td></tr><tr><td>1254</td><td>Windows 3.1 Turkish</td><td>X</td><td></td><td>X</td><td>X</td><td>X</td></tr><tr><td>1255</td><td>Hebrew</td><td>X</td><td></td><td></td><td></td><td>X</td></tr><tr><td>1256</td><td>Arabic</td><td>X</td><td></td><td></td><td></td><td>X</td></tr><tr><td>1257</td><td>Baltic</td><td>X</td><td></td><td></td><td></td><td>X</td></tr><tr><td>1361</td><td>Korean (Johab)</td><td>X</td><td></td><td></td><td>**</td><td>X</td></tr></tbody><tbody><tr><td>437</td><td>MS-DOS United States</td><td></td><td>X</td><td>X</td><td>X</td><td>X</td></tr><tr><td>708</td><td>Arabic (ASMO 708)</td><td></td><td>X</td><td></td><td></td><td>X</td></tr><tr><td>709</td><td>Arabic (ASMO 449+, BCON V4)</td><td></td><td>X</td><td></td><td></td><td>X</td></tr><tr><td>710</td><td>Arabic (Transparent Arabic)</td><td></td><td>X</td><td></td><td></td><td>X</td></tr><tr><td>720</td><td>Arabic (Transparent ASMO)</td><td></td><td>X</td><td></td><td></td><td>X</td></tr></tbody></table>
</body>
</html>
Use this way:
<%# page import="java.sql.* " %>
<%
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=SimDetails.xls");
Connection con = null;
PreparedStatement ps=null;
ResultSet rs = null;
%>
<%# include file="directconnection.jsp"%>
<%
int simid=0;
int net=0;
String sim="";
String mob="";
String contnum="";
String couridate="";
String sendaddr="";
String networkName="";
String contpe="";
try{
%>
<table>
<tr>
<th width="5%">SNo</th>
<th width="30%;">Network</th>
<th width="30%;">Sim Number</th>
<th width="30%;">Mobile Number</th>
<th width="30%;">Sender Address</th>
<th width="30%;">Contact Person Number</th>
<th width="30%;">Contact Person Name</th>
</tr>
<%
String strSimExportQuery=" SELECT SM_SIM_ID,SM_PROVIDER_ID,SM_SIM_NUMBER,SM_MOBILE_NUMBER,"+
" SM_SENDER_ADDRESS,SM_CONTACT_PERSON_NO,SM_CONTACT_PERSON FROM RS_SIM_MASTER ";
ps=con.prepareStatement(strSimExportQuery);
rs=ps.executeQuery();
while(rs.next()){
simid++;
net=rs.getInt("SM_PROVIDER_ID");
if(net==1){
networkName="Vodafone";
}
sim=rs.getString("SM_SIM_NUMBER");
mob=rs.getString("SM_MOBILE_NUMBER");
sendaddr=rs.getString("SM_SENDER_ADDRESS");
contnum=rs.getString("SM_CONTACT_PERSON_NO");
contpe=rs.getString("SM_CONTACT_PERSON");
%>
<tr>
<td><%=simid%></td>
<td><%=networkName%></td>
<td><%=sim%></td>
<td><%=mob%></td>
<td><%=sendaddr%></td>
<td><%=contnum%></td>
<td><%=contpe%></td>
</tr>
<%}%>
</table>
<%
}catch(Exception e){
out.println(e);
}
finally {
if (rs!= null){ rs.close(); rs=null;}
if(ps!=null){ps.close();ps=null;}
if (con != null) {con.close();con = null;}
}
%>