Set focus in next control on enter in PHP,ASP.NET,JSP,SERVLETS.
Download latest jQuery and apply listed below code in your web page.
<script language="javascript" src="../js/jquery-1.6.js" type="text/javascript"></script>
<input type="text" name="t1" id="t1" onkeyup="javascript: if(setFocusNext(event)) $('#t2').focus();" />
<br/>
<input type="text" name="t2" id="t2" onkeyup="javascript: if(setFocusNext(event)) $('#t3').focus();" />
<br/>
<input type="text" name="t3" id="t3" />
<script type="text/javascript">
function setFocusNext(e){
var cd=0;
if(window.event) {
cd = e.keyCode;
} else if(e.which) {
cd = e.which;
}
if(cd==13) {
return true;
} else {
return false;
}
}
</script>
Find interesting stuff in Java, PHP and Dot Net.
Stop writing good code; Start writing Innovative code.
This site is from FUTURE. Science is powerful, but it cannot explain everything.
This site is for smart Primates & ROBOTS only (oh and A L I E N S).
Pages
- Home
- Send problem from my FaceBook Page
- Your FB bio/friends
- Auto Resume Broken File Uploader
- Screen Recorder
- Facebook App
- Screencast with Audio Capture
- Web Page Screen Capture As Image
- Add Watermark In Video
- Unique Code
- PDF Merger
- Unique Software
- Latest Posts
- Arbitrary Text in PDF
- MY ANDROID APP
- Torch in Android
Search This Blog
Top Ads
Showing posts with label JSP. Show all posts
Showing posts with label JSP. Show all posts
Monday, June 6, 2011
Tuesday, September 14, 2010
Download database records as csv format in jsp
Download database records as csv format in jsp
<%@page contentType="application/octet-stream"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.*" %>
<%@ page import="java.io.*" %>
<%
String userName = "root",password = "root",url = "jdbc:mysql://localhost:3306/test",driver = "com.mysql.jdbc.Driver";
String siteUrl="http://localhost:9090/Test/";
Connection conn=null;
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url, userName,password);
}catch(Exception ee) {
out.print("There are some problems");
out.print(ee.toString());
}
String sSql="select *from transaction order by id";
String datas=new String("");
PreparedStatement pstTrans = conn.prepareStatement(sSql);
ResultSet rsTrans=pstTrans.executeQuery();
response.reset();
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename=transaction .csv");
while (rsTrans.next()){
datas=rsTrans.getString("user_num")+","+rsTrans.getString("user_id")+","+rsTrans.getString("email")+"\r\n";
byte datasBytes[] = datas.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(datasBytes);
byte[] buff = new byte[1024];
int len;
while ((len = bais.read(buff)) > 0)
response.getOutputStream().write(buff, 0, len);
bais.close();
}
rsTrans.close();
rsTrans=null;
pstTrans.close();
pstTrans=null;
conn.close();
conn=null;
response.getOutputStream().flush();
%>
<%@page contentType="application/octet-stream"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.*" %>
<%@ page import="java.io.*" %>
<%
String userName = "root",password = "root",url = "jdbc:mysql://localhost:3306/test",driver = "com.mysql.jdbc.Driver";
String siteUrl="http://localhost:9090/Test/";
Connection conn=null;
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url, userName,password);
}catch(Exception ee) {
out.print("There are some problems");
out.print(ee.toString());
}
String sSql="select *from transaction order by id";
String datas=new String("");
PreparedStatement pstTrans = conn.prepareStatement(sSql);
ResultSet rsTrans=pstTrans.executeQuery();
response.reset();
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename=transaction .csv");
while (rsTrans.next()){
datas=rsTrans.getString("user_num")+","+rsTrans.getString("user_id")+","+rsTrans.getString("email")+"\r\n";
byte datasBytes[] = datas.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(datasBytes);
byte[] buff = new byte[1024];
int len;
while ((len = bais.read(buff)) > 0)
response.getOutputStream().write(buff, 0, len);
bais.close();
}
rsTrans.close();
rsTrans=null;
pstTrans.close();
pstTrans=null;
conn.close();
conn=null;
response.getOutputStream().flush();
%>
Subscribe to:
Posts (Atom)