June 15, 2009 at 11:24 AM
Hi
I am using 3 jsp files.Here is my code.
Browsefile.jsp:
<%@page language="java" import="java.sql.*"%>
<html>
<body bgcolor=#EFF1FB>
<form name="browsetable">
<script type="text/javascript">
var xmlHttp,table,xmlHttp1,optr,i=1,j=1,query,path,filepath;
function showxlsFileTable(str)
{
path=str;
//alert(str);
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="GetxlsFileTable.jsp";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged1;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
// alert("Im in function="+str);
}
function showxlsFileColumn(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="GetxlsFileColumn.jsp";
//url=url+"?q="+str;
url=url+"?q="+str+ "&q1=" +path;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
// alert("Im in function="+str);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}
function stateChanged1()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint1").innerHTML=xmlHttp.responseText;
}
}
function stateChanged2()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint2").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
//alert("Your browser broke!");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function showTableValue(str)
{
//alert("2 "+filepath);
filetable=str;
fpath=filepath.substring(filepath.length-3,filepath.length);
if(fpath=="xls")
showxlsFileColumn(str)
//alert(document.addmytbl.datafile.value);
}
function readFile(fileBrowser)
{
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert('Unable to access local files due to browser security settings. To overcome this, follow these steps: (1) Enter "about:config" in the URL field; (2) Right click and select New->Boolean; (3) Enter "signed.applets.codebase_principal_support" (without the quotes) as a new preference name; (4) Click OK and try loading the file again.');
return;
}
filepath=fileBrowser.value;
fpath=filepath.substring(filepath.length-3,filepath.length);
// alert(filepath);
if(fpath=="xls")
showxlsFileTable(filepath)
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
try
{
// Back slashes for windows
file.initWithPath( fileName.replace(/\//g, "\\\\") );
}
catch(e)
{
if (e.result!=Components.results.NS_ERROR_FILE_UNRECOGNIZED_PATH) throw e;
alert("File '" + fileName + "' cannot be loaded: relative paths are not allowed. Please provide an absolute path to this file.");
return;
}
if ( file.exists() == false ) {
alert("File '" + fileName + "' not found.");
return;
}
}
</script>
<br><br>
Browse to select a file <input type="file" name="fileBrowser" size="40" onchange="readFile(this)">
<p><div id="txtHint1"><b></b></div></p>
<p><div id="txtHint"><b></b></div></p>
<p><div id="txtHint2"><b></b></div></p>
</form>
</body>
</html>
_________________________________________________________________________
For Getting the tablenames am using next file.
GetxlsFileTable.jsp:
<%@page language="java" import="java.sql.*"%>
<html>
<%
String filepath=request.getParameter("q");
Connection cn;
ResultSet rs;
Statement st;
String tableName="";
//out.println("<br><br><table width=400 border><td>Table Column Name</td>");
%>
<h4>Select Table:                     <select name=sheet2 onchange='showTableValue(this.value)'></h4>
<option value="-">-
<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException se)
{
se.printStackTrace();
}
try
{
String database = "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ="+filepath.trim();
//System.out.println("tableName:"+tableName);
cn = DriverManager.getConnection(database,"","");
DatabaseMetaData dbmd = cn.getMetaData();
// String[] types = {"TABLE"};
rs = dbmd.getTables(null, null, "%", null);
while (rs.next())
{
tableName = rs.getString(3);
//System.out.println("tableName1111:"+tableName);
if(tableName.endsWith("$"))
{
tableName=tableName.substring(0,tableName.length()-1);
// tableName.addElement(tableName);
}
System.out.println("tableName:"+tableName);
%>
<option value<%=tableName%>><%=tableName%></option>
<%
}
%>
</select>
<%
}
catch (SQLException e)
{
}
%>
</html>
_______________________________________________________________________
For getting the table columns, am using this file.
GetxlsFileColumn.jsp:
<%@page language="java" import="java.sql.*"%>
<html>
<%
String sel1=request.getParameter("q");
//System.out.println("sel1=:"+sel1);
String filepath=request.getParameter("q1");
//System.out.println("filepath:"+filepath);
Connection cn;
ResultSet rs;
Statement st;
String columnName="";
//out.println("<br><br><table width=400 border><td>Table Column Name</td>");
%>
<h4>Column in importing table:<select name=sheet2 size=4 onchange='showValue1(this.value)'></h4>
<!--<option value="-">-->
<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException se)
{
se.printStackTrace();
}
try
{
//String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
// database+= filepath.trim() + ";";
String database = "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ="+filepath.trim();
cn = DriverManager.getConnection(database,"","");
DatabaseMetaData dbmd = cn.getMetaData();
rs = dbmd.getColumns(null, null, sel1+"$", null);
while (rs.next())
{
columnName = rs.getString("COLUMN_NAME");
//System.out.println("columnName:"+columnName);
%>
<option value<%=columnName%>><%=columnName%></option>
<%
}
%>
</select>
<%
}
catch (SQLException e)
{
}
%>
</html>
_________________________________________________________________________
Related Tutorials/Questions & Answers:
Browse Excel File Problem - Development processBrowse Excel File Problem I am using a web application,in which i have to
browse an
excel file columns.
It is working in my system. But if i access... displayed when i
browse the
file. What is the
problem? Hi Friend
Advertisements
Java file browseJava
file browse
In this section, you will learn how to
browse a
file and allows the user to
choose a
file.
Description of code
GUI provide
File choosers for navigating the
file system, and then provide
the utility to choose either
jsp - excel generating problem - JSP-Servlet and download it.After saving the
file.
Then view
excel file.The view image on this page is result
excel file.
If you have more
problem then give details...jsp -
excel generating problem Hi,
I worked with the creating
importing excel fileimporting
excel file Hi All
I am developing a java application whre we upload a
excel file in to database and
all
excel value should import...
it is not showing real
excel sheet value.
please suggest good way to solve this
problem Reading an excel file into arrayReading an
excel file into array Hi,
I'm trying to read in an
excel file, search a column for containing key words (entered by a user) and then displaying the matching rows in a table. I'm fairly new to JavaScript. Can anyone
Excel file Handling in JavaExcel file Handling in Java Hello Sir,
I am new to Java, I have Started Java Core by myself. I want to make a project which include 3-4
Excel file to handle.Please explain how to read and write
Excel file in Java.Is it tough
excel file using JDBC java.?excel file using JDBC java.? hey, i am a telecomm. engineer , and i am try to develop a tool which reads from a
excel file and then appends the same
excel file as required. i am writing my code on notepad and have successfully
Excel file wriring using javaExcel file wriring using java i have one predefined bill format in
excel
i want to append values in it using java apche POI or Jexcel
i tried it but it overwrites
file and lost previous contents what can i do
Reading and querying an Excel file in JavaScriptReading and querying an
Excel file in JavaScript Hi,
I'm trying to read in an
excel file, search a column for containing key words (entered by a user) and then displaying the matching rows in a table. I'm fairly new
write excel file into the oracle databasewrite
excel file into the oracle database dear sir,
i need the jsp code that reads the
excel file and stores it into the oracle database table..and also i need the code to connect oracle database?
thank u in advance
Problem reading word fileProblem reading word file Deepak you provide me code for extarcting equation from a word
file and also to write in a word file.But when I again want to read preveously created word
file(created by your code) it gives an error
File Uploading ProblemFile Uploading Problem I have a
file uploading code but it create
problem
$(document).ready(function(){
$('#upload').click(function(){
var... it gives the
problem
org.apache.commons.fileupload.FileUploadException
File Uploading ProblemFile Uploading Problem I have a
file uploading code but it create
problem
$(document).ready(function(){
$('#upload').click(function(){
var... it gives the
problem
org.apache.commons.fileupload.FileUploadException
Linking an Excel File with the Application toolLinking an
Excel File with the Application tool I have to link an
excel file with a application software which I am developing.I have this code... on the questions that are in the
excel file like extracting the questions from the
excel file application context file problemapplication context
file problem how to configure junit application context
file with struts........?
it is not finding sessionfactory method
struts jar file problemstruts jar
file problem hi..
I'm using struts-core-1.3.9.jar.
it works well if am using ma application with internet
but
it shows me an error while initializing ActionServlet when i disconnected to Internet
The error stack trace
reading data from excel file and plotting graphreading data from
excel file and plotting graph I am doing a project using NetBeans in which i have to take input an
excel file and then using the data in
excel file, i have to plot graphs based on CELL ID selected. please help
JavaScript get excel file data
JavaScript get
excel file data...;
By the use of JavaScript we can get the
excel file data as well. Here is the
example which gets the data from the
excel file with the cell and row index
insert values from excel file into databaseinsert values from
excel file into database hi i want to insert values from
Excel file into database.Whatever field and contents are there in
excel... the following link:
Insert values from
excel file to database
Linking excel file with a application tool using swingLinking
excel file with a application tool using swing I have to link an
excel file with my application software using java swing.As soon as i click on the link button a window should open for selecting the
excel file(just like
problem while reading .csv fileproblem while reading .csv file I have a
problem here.....
i am reading a .csv extention
file which has some value....but the
problem is der is an amount column which contains , in between (eg) 3,899.00
which inturns creates
read excel file from Java - Java Beginnersread
excel file from Java How we read
excel file data with the help of java? Hi friend,
For read more information on Java POI visit to :
http://www.roseindia.net/java/poi/
Thanks
PHP Open Excel File in browser - PHPPHP Open
Excel File in browser How we can open an
excel file using PHP code. I don?t want to let the user to download it rather I would like to get it open in the web browser. Any help would be great.
Thank you very much
downloading excel file using Java and springsdownloading
excel file using Java and springs I need to find out how to download an
excel file using the spring framework in java. Please help me out as I am new to springs and its urgent
To read & write a excel file using the core javaTo read & write a
excel file using the core java Hai,
I'm new to JavaProgram.But now i need java program to read & write a
excel file so, can anyone help me to learn the above mentioned topic(link for the portion
Problem in getting file path in jsProblem in getting
file path in js hi,
I am using ofbiz framework , How i can get the
file path in javascript for input type = "
file" and i am using only firefox not other browser. so please help me it is very important for me
Exception when opening a excel file in JFrameException when opening a
excel file in JFrame Hello,
I have a
problem when trying to display a
Excel file in a Jframe. The exception is like this: com.jniwrapper.LibraryNotFoundException.
here is my code
public jexcelTest1
how to display the excel file content in the jsphow to display the
excel file content in the jsp How to present the content of the newly created
excel file in the following jsp to the web browser...="application/vnd.ms-
excel" %>
<%@ page import="java.io.*" %>
<
Problem with appending data to the end of fileProblem with appending data to the end of file MY JSP CODE... successfully</h1>");
%>
</body>
</html>
JAVA CLASS
FILE CODE...
{
public static void add(String name,String mail,String path) throws IOException
{
File retrieving of value from excel file - JSP-Servletretrieving of value from
excel file Dear sir,
Thanks for sending... this message to all the employees when i upload a
file then it fetch a data from that
excel sheet i.e this matter will take a para meter values from the
excel retrieving of value from excel file - JSP-Servletretrieving of value from
excel file Dear sir,
Thanks for sending... this message to all the employees when i upload a
file then it fetch a data from that
excel sheet i.e this matter will take a para meter values from the
excel