vicky
java using JSP
1 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners

View Answers

August 24, 2009 at 2:30 PM


Hi Friend,

Try the following code:

1)showExcel.jsp:

<a href="showDataInExcel.jsp">Show datas in Excel format</a>

2)showDataInExcel.jsp:

<%@page import="java.io.*"%>
<%@page import="java.sql.*"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFCell"%>

<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");
PreparedStatement psmnt = null;
Statement st=connection.createStatement();
ResultSet rs=st.executeQuery("Select * from student");

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Excel Sheet");
HSSFRow rowhead = sheet.createRow((short)0);
rowhead.createCell((short) 0).setCellValue("Roll No");
rowhead.createCell((short) 1).setCellValue("Name");
rowhead.createCell((short) 2).setCellValue("Marks");
rowhead.createCell((short) 3).setCellValue("Grade");

int index=1;
while(rs.next()){

HSSFRow row = sheet.createRow((short)index);
row.createCell((short)0).setCellValue(rs.getInt(1));
row.createCell((short)1).setCellValue(rs.getString(2));
row.createCell((short)2).setCellValue(rs.getInt(3));
row.createCell((short)3).setCellValue(rs.getString(4));
index++;
}
File file=new File("c:\\excelFile.xls");
FileOutputStream fileOut = new FileOutputStream(file);
wb.write(fileOut);
fileOut.close();
out.println("Data is saved in excel file.");

rs.close();
connection.close();
String filePath=file.getAbsolutePath();
Runtime rt = Runtime.getRuntime();
rt.exec("cmd.exe /C start C:\\excelFile.xls");
}
catch(Exception e){}
%>

Thanks









Related Pages:
A Java Program by using JSP
A Java Program by using JSP  how to draw lines by using JSP plz show me the solution by using program
JSP using java - Java Beginners
JSP using java  sir, In my jsp page contains 3 hyperlinks say (link1 link2 link3).I want to write some java code using servlet for each hyperlinks.how to forward JSP page to servlet.I m using 3 hyperlinks in my page.My
JSP using java - Hibernate
JSP using java  This is my part of Excal sheet code using jdbc connection. int index=1; while(rs.next... using hibernate.I am having function called displayIps() and displayvalues
java using JSP - Java Beginners
java using JSP  hi...i has been created one JSp page.in this page have one links name as "Show datas in Excel format".I want to create Excel file... using postgres DB.This DB have more than 4 Rows and Columns.  Hi Friend
JSP using java - Java Beginners
JSP using java  hi...i has been created one JSp page.in this page have one links name as "Show datas in PDF format".I want to create PDF file which containing datas(from database interaction) when i clicking that link...i m using
JSP using java - Java Beginners
JSP using java  hi, In my jsppage has Combo box(contains inpacks...). I have core java code for (inpacks,outpacks,system uptime etc... inpacks from combo box and clicking bar chart options concurrently in the jsp
JSP using java - Java Beginners
JSP using java  I want to generate chart in JSP page.My bar chart code contains the following function String series1 = "bars"; dataset.addValue(Integer.parseInt(values.get(i)),series1,(String)Values1.get(i
Java using Jsp - Java Beginners
Java using Jsp  hi sir, 1)showExcel.jsp: Show datas in Excel... and executed in netbeans 4.1. but not work in EclipseEE.i m using Tomcat server 6 .I m included JAR file also.After executing the jsp page shows
java using jsp - Java Beginners
java using jsp  i already included those jar file into my library in eclipse.i previously send my JSP code.But it shows error like. type... org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred
Java using Jsp - Java Beginners
Java using Jsp  hi sir, again i m getting error like. HSSFWorkbook cannot be resolved to a type. HSSFSheet cannot be resolved to a type. HSSFRow cannot be resolved to a type I included Maximum all jar file in eclipse
Jsp using mvc - JSP-Servlet
Jsp using mvc  hi I have written using mvc2 architecture, i have written logic in java ,i want to print a message on the form stating the the values are inserted successfully.So can you tell me how i have to write the code
Register page using servlets,jsp and java beans
Register page using servlets,jsp and java beans  i want code for register page using jsp,serlets and java beans.iam getting error for my code in java...://www.roseindia.net/jsp/user-registration-form-using-jsp.shtml Thanks
jsp using Beans
jsp using Beans  public class Empbean { int empno; String ename... need jsp program for above bean class   Hi Friend, Try the following...); RequestDispatcher rd = req.getRequestDispatcher("/jsp/beandata.jsp"); rd.forward
Uploading image using jsp
Uploading image using jsp  how to upload image using jsp. Already i... that image file ... I want know that solution using by u... Thanks, P.S.N.   Here is a jsp code that upload image and display it on the browser. 1
jsp
jsp  how to assign javascript varible to java method in jsp without using servlet
how to create using jsp
how to create using jsp  code 1: <%@ page language="java...;/body> </html> code 2: <%@ page language="java...;%@ page language="java" contentType="text/html; charset=ISO-8859-1
file upload using JSP
file upload using JSP  I have created a form to upload a file in a html page, now i want to get the path of the file in a jsp page so what code...="java" %> <HTML> <HEAD><TITLE>Display file upload form
create using jsp
create using jsp  code 1:``<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org
video uploading using jsp
video uploading using jsp  this is the code i hv written...="java">Java</option> <option value="os">...;/body> </html> facultyvideouload.jsp <%@ page language="java
Project on mailing system using Java/JSP
Project on mailing system using Java/JSP  I am making a project on mailing system in Java/JSP. How could I display the inbox messages on the home page of user? Please tell me about how to handle these messages in database
Ajax with java(using Dojo) - JSP-Servlet
Ajax with java (using Dojo)  Hi, In In place Edit Box,when I click "save" button how can I save the data in server side i.e JSP or how can I call.... Is there a possibility for tutorial on Scriptaculous. us,for Java programmers
deploy jsp using web logic - Java Beginners
deploy jsp using web logic  Hi all, I am new in Web logic server please tell me what is the steps of writing deployee the jsp using web logic. and steps also arrange the folder its urgent
reading data using struts and jsp java
reading data using struts and jsp java  how can i read data entered by user into a textbox (jsp page) into struts action class ex emp id,so that after reading emp_id it can be read into struts action class for retrieving other
JSP
JSP   My question is How to create referral hyperlink to the target websites using JSP/JAVA/HTMl...? for eg:assume gmail is the target website...take google as the base website...there are referral hyperlinks
Error in using java beans - JSP-Servlet
Error in using java beans  I am getting the following error when I run the jsp code. type Exception report message description The server...: Unable to load class for JSP
Could not able to run Java Applet in JSP using <jsp:plugin>
Could not able to run Java Applet in JSP using   I could not able to run the above example applet in the JSP. Getting class not found exception... the following links: http://www.roseindia.net/jsp/applet-jsp.shtml http
How to export data from jsp to excel sheet by using java
How to export data from jsp to excel sheet by using java   How to export data from jsp to excel sheet by using java
online test project on java using servlets and jsp
online test project on java using servlets and jsp  as i am doing online test project on java using jsp and servlets ,,,the problem is in the code of jsp file which i have sent,...,i used next and previous buttons and used two
jsp
am using Apache Tomcat/5.0.28 , jdk1.6 HTTP Status 500 - type Exception... api.jar file inside the lib folder. 4)Now create a jsp file:'hello.jsp' <%@page language="java"%> <%String st="Hello World"; %> Message is <%=st
SMS alert system using Java - JSP-Servlet
SMS alert system using Java  Respected Sir/Mam, I need to develop an SMS alert application. Scope of the application: Basically... recipients. This can be developed using any kind of componentsThanks
JSP
JSP   how to open and view a flat file in browser using java code in jsp?   Hi Friend, If you want to simply open a file then try the following code: <%@page import="java.util.*"%> <% Runtime rt
Doubt in using combination of JSP page and Java class. - JSP-Servlet
Doubt in using combination of JSP page and Java class.   I've got... be disabled from clicking. How to go about doing this in a "JSP Page using a Pure Java class"? The Database table looks like this: SeatCode
remote procedure call using java - JSP-Servlet
remote procedure call using java  what is the romote procedure call and related coding in java?  Hi Friend, The RPC (Remote Procedure...: 1. A java program invokes a method on a stub, 2. Stub invokes routines
Uploading Multiple Files Using Jsp
Uploading Multiple Files Using Jsp  ... to understand how you can upload multiple files by using the Jsp. We should avoid... logic, but at least we should know how we can use a java code inside the jsp page
Pagination in jsp using oracle and not sql
Pagination in jsp using oracle and not sql  I need the code for pagination in jsp using oracle. I already tried it with rownum between instead... Pagination using Mysql database <%@ page language="java" %> <%@ page
jsp
jsp  i am using java inside java script page. in that page i want to use two dropdown list. in first dropdown list i am getting data from sql server database. in second dropdown list i want to get data according to selection made
How to upload file using JSP?
How to upload file using JSP?   Hi all, I m the beginner in JSP, I want to upload file on server in specific folder.   1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display
How to display data in jsp from dao using java beans?
How to display data in jsp from dao using java beans?  Hi I need to display data in jsp pulling from dao using java beans, Please can anyone give me the sample application with above topics. Any help would be highly appreciated
Uploading a single file by using JSp
Uploading a single file by using JSp  u have said about submit button..but in program u have not used submit button..and where file will be stored...;%@ page language="java" %> <HTML> <FORM ENCTYPE="multipart/form-data
How to export web page to excel using java or jsp or servlets
How to export web page to excel using java or jsp or servlets  Hi I am trying to export web page(jsp page ) to excel using jsp or servlets. I am... errors. Please can anyone tell me how to do this using java or jsp or servlets
Defining and using custom tags - JSP-Servlet
java code used in a Java Server Page (JSP) file. A tag library is a collection...Defining and using custom tags  Hi Sir, I want to know...-defined JSP language element. When a JSP page containing a custom tag
java jsp
java jsp  please I want code to parse a web page using Dom parser, thanks
need a sample project using java technologies like jsp, servlets, struts
need a sample project using java technologies like jsp, servlets, struts  Hi everybody! I have learnt core java,jdbc,jsp,servlets & struts... other project with detailed explanation using the above technologies by which i
Retail Point Of sales (using jsp and servlet)
Retail Point Of sales (using jsp and servlet)  Hi, i want to know how to add products using search module, i have a database and created a product... module. I dont have any background in java and jsp, i dont have any idea where
jsp to cassandra datbase connection by using eclipse
jsp to cassandra datbase connection by using eclipse  sir i want to connect the apache cassandra datbase by using cql query language. i am success by using simple java application.now my task is to interact with cassandra
How to get the output of JSP program using Bean
How to get the output of JSP program using Bean  Hi Kindly go... visit the following link: http://www.roseindia.net/jsp/using-bean-counter.shtml... created in Java and compiled <%@ page language="java" import="beans" %>
Using Beans in JSP. A brief introduction to JSP and Java Beans.
USING BEANS IN JSP           Java Beans Java Beans are reusable components
JAVA,JSP,SERVELTS
JAVA,JSP,SERVELTS  plz Send me Login Page by using core java ,Jsp,Servelts
Using a user defined non-packaged servlet class in jsp. - JSP-Servlet
Using a user defined non-packaged servlet class in jsp.  i want know that how to use a user defined java servlet function's, variables and methods of a user defined java servlet in jsp.if possible plz try to explain with a simple
JAVA JSP and Servlet - JSP-Servlet
JAVA JSP and Servlet  for sending mail through lan without intenet and also chatting facility for online users using Java JSP & SERVLET code.  Hi Friend, Please visit the following links: http://www.roseindia.net

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.