Wrong parameter values while exporting data from jsp to excel

Ads
 

Wrong parameter values while exporting data from jsp to excel

This is a jsp report. When i export the report data to an excel, the parameter values on the html report do not match those in the downloaded spreadsheet, specifically, if the parameter value is ALL, it gets translated to NO in excel.

This is the my jsp code -

<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page errorPage="errorPage.jsp" %>
<%@ page import="com.dab.dabuilderConstants"%>
<jsp:useBean id="paramForm" scope="application" class = "com.dab.dabFormParameter" />
<html>
<%
 dabuilderConstants cConstants = new dabuilderConstants();
%>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <STYLE type="text/css">
   .error{
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: red;
    font-weight: bold;
    text-align: left;
    }

.GG {BACKGROUND-COLOR:#FFFFCC;BORDER:1px solid #96965E;PADDING:5px;MARGIN-TOP:12px;MARGIN-BOTTOM:12px}

  </style>

    <title><%=cConstants.sHrrchyReport%></title>
    <script language="javascript">

      errorMessages = new Array();
      visibleFlag=false;
      i=0;

      function doSubmit(){   



            document.forms[0].submit();

     }     
      function addError(erMsg){
          errorMessages[i++] = erMsg;
        }

        function displayErrors(){
            var allMsgs = '';
            for(var j=0; j<errorMessages.length; j++){
                allMsgs += errorMessages[j];
            }
            document.getElementById("errorBody").style.visibility = 'visible';
            visibleFlag=true;
          document.getElementById("msgs").innerHTML=allMsgs;

        }

        function clearErrors(){
          if(visibleFlag==false){
          document.getElementById("errorBody").style.visibility='hidden';
          }
        }



            </script>

  </head>
  <body onload="javascript:clearErrors();">
  <span id="errorBody">
  <table width=80% border=0 align="center" cellspacing=0 cellpadding=0 class="GG">
  <tr bgcolor="#FFFFCC"><td></td></tr>
  <tr bgcolor="#FFFFCC">
    <td class="error"><span id="msgs"></span></td></tr>
  </table>
  </span>
  <%
    if(paramForm.getErrorMessage()!=null){
    String errs=paramForm.getErrorMessage();
  %>
  <script language="javascript">
    addError('<%=errs%>');
    displayErrors();
  </script>
<%
    }
        paramForm.setErrorMessage(null);
%> 

 <%
String permission=null;


  String path=session.getServletContext().getRealPath("/"); 
  if(request.getSession().getAttribute("eUserName")!=null){
   permission=request.getSession().getAttribute("eUserName")+"";
   paramForm.test(request.getSession().getAttribute("eUserName")+"",request.getSession().getAttribute("ePassword")+"");
   paramForm.loadObjects(request.getParameter("reportName")+"",path);

  }else{

  response.sendRedirect("check.jsp");

  }

%>


    <tr> 
       <td colspan="2"><br><label  title="Granted Functions">Display Granted Functions?? ? ? ? </label>
           <select id="gfns" tabindex="3" property="grantedFns" name="grantedFns">
              <option value="All" selected="selected">All</option>
              <option value="Yes">Yes</option>
              <option value="No">No</option>
           </select> 
           <label  title="Granted Menu">[Yes = Display only form functions granted to menus]? ? ? ? </label>
       </td>     
    </tr> 
    <tr> 
       <td colspan="2"><br><label  title="Query Functions">Display Query Only Functions?? ? ? </label>
           <select id="qfns" tabindex="3" property="QueryFns" name="QueryFns">
              <option value="All" selected="selected">All</option>
              <option value="Yes">Yes</option>
              <option value="No">No</option>

           </select> 
        <label  title="Query Function"> [Yes = Display only "Query Only" form functions]? ? ? ? </label><br>
       </td>    
    </tr> 
    <tr> 
       <td colspan="2"><br><label  title="Excluded Menus">Display Excluded Menus?? ? ? </label>
           <select id="exmns" tabindex="3" property="exMenus" name="exMenus">
              <option value="Yes">Yes</option>
              <option value="No">No</option>
              <option value="All" selected="selected">All</option>
           </select> 
       <label  title="Excluded Menus"> [Yes = Display only excluded menus and functions]? ? ? ? </label>
<br>
       </td>    
    </tr> 

    <tr align="right">
    <td>
     <button  onclick="javascript:doSubmit()"> 
    <LABEL>Submit Query</LABEL>
    </button>? ? 
    <button type="reset"> 
    <LABEL>Reset</LABEL>
    </button>
 <input type="HIDDEN" id="selectedValue" value="<%=cConstants.sHrrchyReport%>" name="reportName">
  </td>
  </tr>
 </table>
 </div>
 </form>
  </body>
</html>
View Answers

March 16, 2012 at 3:09 PM

1)form.jsp:

<html>
<body>
<form name="userform" method="post" action="excelFile.jsp">
<table>
<tr><td>Enter First Name:</td><td><input type="text" name="firstName"></td></tr>
<tr><td>Enter Last Name:</td><td><input type="text" name="lastName"></td></tr>
<tr><td>Enter User Name:</td><td><input type="text" name="userName"></td></tr>
<tr><td>Enter Address:</td><td><input type="text" name="address"></td></tr>
<tr><td>Enter Email ID:</td><td><input type="text" name="email"></td></tr>
<tr><td>Enter DOB:</td><td><input type="text" name="dob"></td></tr>
<tr><td><input type="submit" value="Export to excel"></td></tr>
</table>
</form>
</body>
</html>

2)excelFile.jsp

<%@page import="java.io.*"%>
<%@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"%>
<%
String value1=request.getParameter("firstName");
String value2=request.getParameter("lastName");
String value3=request.getParameter("userName");
String value4=request.getParameter("address");
String value5=request.getParameter("email");
String value6=request.getParameter("dob");
try{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Excel Sheet");
HSSFRow rowhead = sheet.createRow((short)0);
rowhead.createCell((short) 0).setCellValue("First Name");
rowhead.createCell((short) 1).setCellValue("Last Name");
rowhead.createCell((short) 2).setCellValue("User Name");
rowhead.createCell((short) 3).setCellValue("Address");
rowhead.createCell((short) 4).setCellValue("E-mail Id");
rowhead.createCell((short) 5).setCellValue("Date Of Birth");

HSSFRow row = sheet.createRow((short)1);
row.createCell((short)0).setCellValue(value1);
row.createCell((short)1).setCellValue(value2);
row.createCell((short)2).setCellValue(value3);
row.createCell((short)3).setCellValue(value4);
row.createCell((short)4).setCellValue(value5);
row.createCell((short)5).setCellValue(value6);
FileOutputStream fileOut = new FileOutputStream("c:\\File.xls");
wb.write(fileOut);
fileOut.close();
out.println("Data is saved in excel file.");
}catch ( Exception ex ){
}
%>

Ads









Related Tutorials/Questions & Answers:
Wrong parameter values while exporting data from jsp to excel
Wrong parameter values while exporting data from jsp to excel   This is a jsp report. When i export the report data to an excel, the parameter..., specifically, if the parameter value is ALL, it gets translated to NO in excel
Exporting data from mysql into csv using jsp
Exporting data from mysql into csv using jsp  Hi friends.... I want to export the data from mysql to csv file using... i am having 30 columns in my database.. Eg- text1,text2,text3,....,upto text30... i want to export this data
Advertisements
how to read values from excel sheet and compare with database using jsp
how to read values from excel sheet and compare with database using jsp  hi sir i am arun how to read values from excel sheet and compare with database using jsp coding i.e, if i have 6(assetid,assetname,serialno,cubical
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
How to Get The Data from Excel sheet into out jsp page???
How to Get The Data from Excel sheet into out jsp page???  How to Get The Data from excel sheet to out jsp page in webApp
url parameter using retrive data from database in jsp
url parameter using retrive data from database in jsp  The user can... clicks the Preview button, you have to create a dynamic jsp which should read the contents from the db based on the event id. But this jsp url should be a public url
url parameter using retrive data from database in jsp
url parameter using retrive data from database in jsp   the user can... clicks the Preview button, you have to create a dynamic jsp which should read the contents from the db based on the event id. But this jsp url should be a public
Read data from excel file and update database using jsp
Read data from excel file and update database using jsp  read data from excel file and update database using jsp Hi, I am using a MySQL database for scientific research analysis. My team members sends research data in excel file
how to get a column values from a excel file after attaching it - JSP-Servlet
how to get a column values from a excel file after attaching it  hi sir, How to get a column values from a excel file after attaching it while... and get a values from that store that value in To input box.Please help me sir
get values from Excel to database
get values from Excel to database   hi i want to insert values from Excel file into database.Whatever field and contents are there in excel file that should go to database which exists. am using SQL Server management studio
How to insert data from a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB:student; @table:stu_info; Combobox values:(class1,class2,class3); textbox1
Exporting data from mysql to csv file
Exporting data from mysql to csv file  Hi friends.... I want to export the data from mysql to csv file... i am having 30 columns in my database.. Eg... example that retrieves the data from the database and save it into csv file
read data from Excel sheet
read data from Excel sheet  Hi, How to read data from an excel sheet using JSP. Thank you
Passing Parameter Values to another jsp in Query Strings
Passing Parameter Values to another jsp in Query Strings  HI ALL, I m trying to pass a variable value to another JSP using query string... even though some values* stored in the variable loginid. Can any one suggest
getting int values from form and insert it in data base in jsp
getting int values from form and insert it in data base in jsp  how...; Hi, You can get the parameter from the request object: String s...=st.executeUpdate("insert into data(name,age, address) values('"+name+"',"+age
insert values from excel file into database
insert 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
Insert data in Excel File from Database using JSP
Insert data in Excel File from Database  using JSP ... developed a application to insert data  in excel file from database in JSP. We... the data from database, create an excel file and data insert into newly
Reading the Date and time values from excel sheet
Reading the Date and time values from excel sheet  hi guys , iam trying to read excel sheet data using apache poi api .my problem is i cant read the date(dd/mm/yy) and time(hh:mm:ss) values concurrently from two different cells
how to read data from excel file through browse and insert into oracle database using jsp or oracle???
how to read data from excel file through browse and insert into oracle database using jsp or oracle???  sir.. i have number of excel sheets which...://www.roseindia.net/answers/viewqa/JSP-Servlet/28123-write-excel-file-into-the-oracle
jsp with excel sheet data uploading into database
jsp with excel sheet data uploading into database  how to upload data in excel sheet with jsp into oracle 10g database
Exception during parsing a parameter from the form in JSP
Exception during parsing a parameter from the form in JSP  Exception during parsing params from a form? I get parameters from a html form. I parse the integer one in the JSP file, but I get exception. Is there anyway I can get
Retrieving specific data from excel
Retrieving specific data from excel  Hello everyone, i have written a simple code to retrieve data from excel sheet and working fine, the excel file... first sheet from the workbook HSSFSheet sheet = workbook.getSheetAt(0
query regarding exporting table from jsp page to pdf
query regarding exporting table from jsp page to pdf  hello i am displaying one table on my jsp page and i want to save that table in pdf file can u please help me??? please reply as soon as possible   1)createPDF.jsp
query regarding exporting table from jsp page to pdf
query regarding exporting table from jsp page to pdf  hello i am displaying one table on my jsp page and i want to save that table in pdf file can u please help me??? please reply as soon as possible   1)createPDF.jsp
query regarding exporting table from jsp page to pdf
query regarding exporting table from jsp page to pdf  hello i am displaying one table on my jsp page and i want to save that table in pdf file can u please help me??? please reply as soon as possible   1)createPDF.jsp
query regarding exporting table from jsp page to pdf
query regarding exporting table from jsp page to pdf  hello i am displaying one table on my jsp page and i want to save that table in pdf file can u please help me??? please reply as soon as possible   1)createPDF.jsp
query regarding exporting table from jsp page to pdf
query regarding exporting table from jsp page to pdf  hello i am displaying one table on my jsp page and i want to save that table in pdf file can u please help me??? please reply as soon as possible   1)createPDF.jsp
query regarding exporting table from jsp page to pdf
query regarding exporting table from jsp page to pdf  hello i am displaying one table on my jsp page and i want to save that table in pdf file can u please help me??? please reply as soon as possible   1)createPDF.jsp
query regarding exporting table from jsp page to pdf
query regarding exporting table from jsp page to pdf  hello i am displaying one table on my jsp page and i want to save that table in pdf file can u please help me??? please reply as soon as possible   1)createPDF.jsp
export data from database to excel sheet - JDBC
export data from database to excel sheet  I am facing a problem about exporting required data from database table to ms-excel sheet.i mean whenever I...("Data is saved in excel file."); rs.close(); connection.close(); } catch
query regarding exporting table from jsp page to pdf
query regarding exporting table from jsp page to pdf  hello i am displaying one table on my jsp page and i want to save that table in pdf file can u please help me??? please reply as soon as possible   1)createPDF.jsp

Ads