Creating a file download link on jsp

I have the following on my jsp. The code worked fine until I tried to use it in a new html design page.
<code>
//page name is index.jsp
try //DISPLAY THE CONTENTS OF THE DATA DIRECTORY
File dirname = new File(PATH); // create an instance of the File class
if (dirname.exists()&&dirname.isDirectory())//check to see if File class dirname exists and is valid
String [] allfiles = dirname.list();//create an array of files in the dirname File class
          for (int i=0; i< allfiles.length; i+=2)//loop through allfiles[] and print out file links
out.println("<br><table border='1' cellspacing='1' width='99%'>");
               out.println("<tr><td width='50%' class='pageFont'><input type='checkbox' name='cb' value='"+allfiles[i]+"'>"+allfiles[i]+"      ");
%>
<a class="a" href="index.jsp?downfile=C:\\data\\<%=allfiles[i+1]%>">DOWNLOAD</a></td>
<% if(i+1 < allfiles.length)//PRINTS OUT THE SECOND TD SO THAT WE HAVE 2 COLUMNS OF LINKS
out.println("<td width='50%' class='pageFont'><input type='checkbox' name='cb' value='"+allfiles[i+1]+"'>"+allfiles[i+1]+"      ");
%>
<a class="a" href="index.jsp?downfile=C:\\data\\<%=allfiles[i+1]%>">DOWNLOAD</a></td></tr>
<%
out.println("</form></font></table>");
catch (IOException excep)
     out.println("An IO exception has occured.");
</code>
Then when clicked this code is run:
<code>
try{
//CHECK TO SEE IF THE FILE HAS BEEN CLICKED TO DOWNLOAD SINGLE FILE
if (request.getParameter("downfile") != null)
String filePath = request.getParameter("downfile");
File f = new File(filePath);//CREATE AN INSTANCE OF THE FILE CLASS AND POINT IT TO THE LOCATION OF THE DIRECTORY CONTAINING THE FILES
if (f.exists() && f.canRead())
response.setContentType ("application/octet-stream");
response.setHeader ("Content-Disposition", "attachment;filename=\""+f.getName()+"\"");
response.setContentLength((int) f.length());
BufferedInputStream fileInputStream = new BufferedInputStream(new FileInputStream(f));
int i;
out.clearBuffer();
while ((i = fileInputStream.read()) != -1) out.write(i);
fileInputStream.close();
out.flush();
</code>
When I click on this link I get the download dialog box. If I open it I get the following open up in notepad(the files I am trying to give download links are .txt files)
Below is what is displayed in notepad ALL on 1 line:
<html>
<head>
<LINK rel="stylesheet" ty
That is displayed in all of the links that I click on. It is the first few lines of html code for index.jsp.
I know this code is probably not a good way of doing what I need but I got it to work fine until the change.
I am sure there is an easier way to code the download link without resubmitting the page.
Thanks in advance!!

Well all was fine with this jsp until I moved it to ApacheJServ. Now the problem has resurfaced(although it is a little different now)
I had moved the following code to the top of my page:
//CHECK TO SEE IF EITHER DOWNFILE OR ZIPFILE VARIABLE EXIST, AND IF THEY DO SET CONTENT TYPE BEFORE SENDING ANY HTML CODE TO THE BROWSER
try{
//CHECK TO SEE IF THE FILE HAS BEEN CLICKED TO DOWNLOAD SINGLE FILE
    if (request.getParameter("downfile") != null)
            String filePath = request.getParameter("downfile");
            File f = new File(filePath);//CREATE AN INSTANCE OF THE FILE CLASS AND POINT IT TO THE LOCATION OF THE DIRECTORY CONTAINING THE FILES
                if (f.exists() && f.canRead())
                    response.setContentType ("application/octet-stream");
                    response.setHeader ("Content-Disposition", "attachment;filename=\""+f.getName()+"\"");
                    response.setContentLength((int) f.length());
                    BufferedInputStream fileInputStream = new BufferedInputStream(new FileInputStream(f));
                    int i;
                    out.clearBuffer();
                    while ((i = fileInputStream.read()) != -1) out.write(i);
                        fileInputStream.close();
                        out.flush();
                        response.flushBuffer();
catch (Exception e){}
//This is where the java code ends and the javascript/html code begins.Then further into the page I create the file download links like so:
                        <a class="a" href="main.jsp?downfile=C:\\data\\<%=allfiles[i+1]%>">DOWNLOAD</a>I know this isnt a secure way of doing this but I am on a intranet.
The problem I am having now is that when I click on one of the links and download the file and then open it, I get the contents of the file plus concatenated to the end of it is the first few HTML lines of the actual jsp that I downloaded the file from. Before I was just getting the first few lines of html from the jsp, not the actual contents of the downloaded file.
This is an example of what I am getting:
This is the contents of the file that I downloaded.//This is where the file contents ends.
<html>
<head>
<LINK rel="stylesheet" type="text/css" href="default.css">
<script language="JavaScript1.2">
//function that allows user to select all checkboxes
function doIt(v)
for(var i=0;i<document.form1.cb.length;i++)
   document.form1.cb.checked=eval(v);
function swap(imageName,image)
imageName.src = "templateImages/"+image;
function imageOver(imageSrc, imageName)
     changeImage = new Image();
     changeImage.src = imageSrc;
     document.images[imageName].src = changeImage.src;
var hide = true;
function hideShow( ) /
Any morre ideas?
TIA!
BTW, I went to ApacheJServ because they wont let me use tomcat :(

Similar Messages

  • Creating a File object in a JSP page

    Hi,
    I am trying to create a File object in my JSP page by passing it a relative path. The jsp page is in 'website/testfolder/index.jsp' and the File is in 'website/photos/1.jpg'. In my jsp page i do the following:
    <% File f = new File("../photos/1.jpg");
    boolean test = f.isFile(); %>
    The value returned is false. I am trying to figure out why it can't locate the file.
    Thanks

    You have to use absolute paths. You can get the absolute path for the given relative path by ServletContext#getRealPath().

  • Website image and zip file download links not working in Dreamweaver Air application

    Hi
    I have successfully created and AIR app for an existing business website using the Dreamweaver AIR Extension. The site works very well in all respects except for the part where we have high resolution images and zip files available for download. The download links refuse to do anything, and right-click (PC) / ctl-click (Mac) does nto work either.
    I suspect this may be an AIR sandbox/security issue but am I correct and what can I do to fix it?
    Thanks in advance for any assistance you may be able to give.
    Martin

    I am now facing the same problem. I wrote a servlet .
    code like this
             response = (HttpServletResponse) faces.getExternalContext().getResponse();
             response.setContentType("application/x-download");
             String agent = request.getHeader("USER-AGENT");
             boolean isIE=false;            
            if (null != agent && agent.indexOf("MSIE")!=-1) { 
                isIE=true;
            if (isIE) {
                fileName = URLEncoder.encode(fileName, "UTF-8");
            } else {
                fileName = new String(fileName.getBytes("utf-8"), "ISO-8859-1");
            response.setHeader("Content-Disposition","attachment;filename="+fileName);
            ServletOutputStream os = response.getOutputStream();
            byte b[]=new byte[1024];
            int n;
            while((n=in.read(b))!=-1){
                os.write(b,0,n);
           in.close();
           os.close();
    and i open a new window refer to above jsp ,also i set a breakPoint at os.close(),the program has passed through,but nothing happened in the window.
    If i use IE or FF ,the browser will open a small window to allow me select whether open or  save the file.So can anybody give me some advice.Is it because air using webkit engine and the engine does not do this kind of job?
            Thanks.

  • Windows Vista, 7 and 8 ISO / Image file Download Links

    Series: How to Re-Install Windows when you don't have the Recovery Discs
    Intro: What is an ISO? Why is it used? 
    Step 1 - Get the ISO - ISO Download Links
    Step 2 - Burn the ISO to a DVD or USB   
    Step 3 - What to do with the ISO DVD/USB? Change the Boot Order  
    Step 4 - What to do After Windows is Installed? How to Get HP Drivers?    
    Step 1 - Get the ISO - ISO Download Links
    First, look at the Product Key label on the bottom of the computer and make sure you can still read it, before proceeding.
    How is this legal?   As long as you have the Product Key (from the bottom of a computer you paid for) for the corresponding version of Windows you download, it is perfectly legitimate and legal.
    The ISO Links: 
    Windows Vista SP1  32 & 64-bit
    *****With that link, you will have to combine the three files into an Image file (aka ISO) first (How to create an image file from files/folders) , using a program like ImgBurn.*****
    Windows 7 32 & 64-bit
    Windows 8 32 & 64-bit
    See Step 2 - Burn the ISO to a DVD or USB
    If you have any questions, create a new post (How to Create a New Post - Video), copy and paste it's link into a private message to me, and I will respond on your thread

    You shouldn't need to edit any of the files. The Windows 7 ISO is a retail, untouched version. It doesn't have a Product Key embedded into it.
    You should be able to use a Windows 7 Product Key from the label on the bottom of the computer with no issues. The installation will ask you for a Windows 7 Product Key. The only exception would be if the Product Key were in use on a different computer. From my understanding, as long as it is not already in use, it should activate.
    Please let me know if you have any questions on that

  • Securing file download links

    As per the File upload/download How-to at http://download-west.oracle.com/docs/cd/B19306_01/appdev.102/b14377/up_dn_files.htm#sthref153
    downloading a file involves writing a stored procedure and invoking it directly using the DAD and mod_plsql. For example, /pls/htmldb/owner.procedure?p_file_id=1234
    This link bypasses the Apex show engine so even if I have all the security in the world in Apex using authentication schemes, authorization schemes, etc, a authenticated user in Apex can just right click on the Download link, shoot it off to someone else who can download the file without even logging in to my application!
    How can these "download links" be secured so that only authenticated users can access them only from an Apex session?
    Thanks

    Thank you Vikas.
    The reason I ask is I get a compilation error in my procedure.
    I am no PL/SQL expert so I am sure my syntax or logic is wrong.
    I am using APEX version 2.0
    Error(7,19): PLS-00103: Encountered the symbol "." when expecting one of the following: constant exception <an identifier> <a double-quoted delimited-identifier> table LONG_ double ref char time timestamp interval date binary national character nchar The symbol "<an identifier>" was substituted for "." to continue.
    CREATE OR REPLACE PROCEDURE download_my_file(p_file in number) AS
            v_mime  VARCHAR2(48);
            v_length  NUMBER;
            v_file_name VARCHAR2(2000);
            Lob_loc  BLOB;
            APEX_APPLICATION.G_FLOW_ID := 100;
    BEGIN
    --testing security
    IF NOT wwv_flow_custom_auth_std.is_session_valid then
        -- display this message or a custom message.
    htp.p('Unauthorized access - file will not be retrieved.');
        -- You can do whatever else you need to here to log the
        --     unauthorized access attempt, get the requestor's
        --     IP address, send email, etc.
        RETURN;
    END IF;
            SELECT MIME_TYPE, BLOB_CONTENT, name,DBMS_LOB.GETLENGTH(blob_content)
                    INTO v_mime,lob_loc,v_file_name,v_length
                    FROM file_subjects
                    WHERE id = p_file;
                  -- set up HTTP header
                        -- use an NVL around the mime type and
                        -- if it is a null set it to application/octect
                        -- application/octect may launch a download window from windows
                        owa_util.mime_header( nvl(v_mime,'application/octet'), FALSE );
                    -- set the size so the browser knows how much to download
                    htp.p('Content-length: ' || v_length);
                    -- the filename will be used by the browser if the users does a save as
                    htp.p('Content-Disposition:  attachment; filename="'||replace(replace(substr(v_file_name,instr(v_file_name,'/')+1),chr(10),null),chr(13),null)|| '"');
                    -- close the headers           
                    owa_util.http_header_close;
                    -- download the BLOB
                    wpg_docload.download_file( Lob_loc );
    end download_my_file;
    /Thanks
    VC

  • OrcDocDomain File Download Link - (BC4J/ADF) - How to?

    I am able to produce an Upload File in my web application - it works really nicely - , but I am lost on how to produce a download link for those files, once they are stored in the database.
    I am creating an application that deals with document files for my company's intranet. I am using BC4J, ADF, the Oracle Database, and JDeveloper 10.1.3.2
    The files are stored in the oracle database as OrcDocDomain columns.
    As I mentioned at the beginning, I do am able to have my users to upload the files:
    I use the af:inputFile tag to upload the file into the desired jbo View Row. BC4J commits the file storage into the database the way I want it later:
    <af:inputFile value="#{bindings.WorkingDocumentsView1NewDocument.inputValue}"
    label="#{bindings.WorkingDocumentsView1NewDocument.label}"
    required="true"
    binding="#{backing_app_Working_Document.inputText3}"
    id="inputText3"
    inlineStyle="font-size:x-small;" />
    Sweet...
    However, my question now is that, I want my users to be able to download the same file...but I am lost trying to put together a solution for it.
    I have tried with <af:objectMedia source="#{bindings.DocOrd.Source}"/> but it does not work at all. (Please note that I can see that that there is a file in the binding variable DocOrd, because I can display it's mime type in the same web page).
    I have also seen a documentation reference to the class "DownloadFile" of JHeadStart. I think that this class does what I should pretend to do: to render a link/call to the Intermedia Servlet that would produce the download.
    However, I am not using JHeadStart to create my application.
    Does someone know how could I generate this link/call without JHeadStart?
    Thanks by anticipate.
    Rafael.

    Hi.
    I was wondering if anyone has any thoughts or suggestions on above issue please?

  • Why I have 3 empty ligns in the file downloaded with a JSP

    Hello,
    When a user select some data (extracted from an Oracle database), he could save the data in a flat file. To do this functionnality, I use a JSP which creates a file with the result of the query, and I download to the browser the file by using :
    response.setHeader("Cache-Control","no-store");
    response.setDateHeader("Expires",1000);
    response.setContentType("application/x_msdownload");
    response.setHeader("Content-Disposition","attachement;filename=" + outputFile);
    I could save or open the file.
    BUT I have 3 empty ligns at the begining of the downloaded file.
    Do you know why?
    Next, is it my code of the JSP used to create the file on the server, download it to the browser and delete it:
    <%
    currentReport.load(currentConnection, reportNm, whereCond, inputFile);
    response.setHeader("Cache-Control","no-store");
    response.setDateHeader("Expires",1000);
    response.setContentType("application/x_msdownload");
    response.setHeader("Content-Disposition","attachement;filename=" + outputFile);
    File fin = new File( inputFile);
    if (! (fin.canRead() || fin.isFile()))
    SecurityException se = new SecurityException( inputFile);
    throw se;
    BufferedReader br = new BufferedReader(new FileReader(fin));
    while ((currentLine = br.readLine()) != null)
    out.println( currentLine);
    br.close();
    currentReport.deleteReport();
    response.flushBuffer();
    %>

    I wouldn't use JSP for this, I'd use servlets...
    But the reason is cuz you have 3 lines before the data is written, say like this:
    <@page import="..." >[newline]
    <@page import="..." >[newline]
    <%
    response.setHeader...
    %>[newline]
    <%
    code to get the file...
    %>

  • How to create a File Save link inside a flash animation

    I have a .swf file the ends with " View or Download Catalog " - I need to know how to prompt the user to Choose a location to save the file locally. Your help is greatly appreciated.

    This is the Acrobat Scripting forum, not ActionScript. Acrobat is a desktop publishing tool to create PDF files and has nothing to do with Flash or ActionScript. Please post your question in a forum related to Flash or ActionScript.

  • Automatic created Java file error when compile JSP file

    I got the following error message when i try to load the JSP file given below (FlightSearch.jsp). Given also below the JAVA files (flightsearch$jsp.java) created by the compiler.
    Thanks for your help
    Susan
    Error message
    org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
    C:\jakarta-tomcat\work\client\localhost\client\client\flightsearch$jsp.java:320: 'catch' without 'try'.
    } catch (Throwable t) {
    ^
    C:\jakarta-tomcat\work\client\localhost\client\client\flightsearch$jsp.java:328: 'try' without 'catch' or 'finally'.
    ^
    C:\jakarta-tomcat\work\client\localhost\client\client\flightsearch$jsp.java:328: '}' expected.
    ^
    3 errors, 1 warning
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:285)
    at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:548)
    at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:176)
    at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:188)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
    at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
    at java.lang.Thread.run(Thread.java:536)
    FlightSearch.jsp
    <%@page import="java.util.*" errorPage="ErrorHandler.jsp"%>
    <%@page import="com.client.entity.Flight"%>
    <%@page import="com.client.wsclient.FlightServiceClient"%>
    <H3>Available Flight List</H3>
    <br>We have found the following Available flight(s) : </br>
    <table border="0" cellpadding="0" cellspacing="0" width="100">
    <tr>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Flight Company</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Flight Number</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Depart From<font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Arrive</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Departure Date</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Departure Time</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Arrival Date</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Arrival Time</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Adult Fare</font></b></td>
    <td width="10%" bgcolor="#808080"><b><font color="#FFFFFF">Child Fare</font></b></td>
    </tr>
    <%
    //Get the search information
    String des = request.getParameter("DFrom");
    String arr = request.getParameter("DTo");
    String fy = request.getParameter(FYear.value);
    String fm = request.getParameter(FMonth.value);
    String fd = request.getParameter(FDay.value);
    String f1 = fy + "-" + fm;
    String FDat = f1 + "-" + fd;
    String ty = request.getParameter(TYear.value);
    String tm = request.getParameter(TMonth.value);
    String td = request.getParameter(TDay.value);
    String t1 = ty + "-" + tm;
    String TDat = t1 + "-" + td;
    String type;
    if( request.getParameter(type[0].checked))
    type = "Return";
    else
    { type = "OneWay";
    String clas;
    if(request.getParameter(clas[0].checked))
    {clas = "ECO";
    else
    {clas = "BUSS";}
    String adult = request.getParameter(Adult.value);
    String child = request.getParameter(Child.value);
    //Get the server Flight Search Service URL
    // ServerFlightSearchBO SFSBO = new ServerFlightSearchBO();
    // ServerFlightSearch FlightSearch = SFSBO.getFlightSearchURL();
    // FlightSearchServiceClient FSearchServiceClient = new FlightSearchServiceClient
    String ServerFlightServiceURL = "http://localhost:7080/AServer/services/FlightService";
    //Find available Flight
    FlightServiceClient client = new FlightServiceClient(ServerFlightServiceURL);
    ArrayList list = client.getFlight(des, arr, FDat, TDat, type, clas, adult, child);
    Iterator it = list.iterator();
    while (it.hasNext()){
    Flight flt = (Flight)it.next();
    %>
    <tr>
    <td width= "10%"><%=flt.getFlightComp()%></td>
    <td width= "10%"><%=flt.getFlightNum()%></td>
    <td width= "10%"><%=flt.getDestination()%></td>
    <td width= "10%"><%=flt.getArrive()%></td>
    <td width= "10%"><%=flt.getFrDate()%></td>
    <td width= "10%"><%=flt.getFlightDptTm()%></td>
    <td width= "10%"><%=flt.getToDate()%></td>
    <td width= "10%"><%=flt.getFlightArrTm()%></td>
    <%
    int adt, chld;
    int far_A, tot_A, far_C, tot_C;
    adt = Integer.parseInt(adult);
    far_A = flt.getAdultFr();
    tot_A = adt * far_A;
    chld = Integer.parseInt(child);
    far_C = flt.getChildFr();
    tot_C = chld * far_C;
    %>
    <td width= "10%"><%=tot_A%></td>
    <td width= "10%"><%=tot_C%></td>
    </tr>
    <%
    if(type = "Return")
    FlightServiceClient client = new FlightServiceClient(ServerFlightServiceURL);
    ArrayList list = client.getFlight(arr, des, FDat, TDat, type, clas, adult, child);
    Iterator it = list.iterator();
    while (it.hasNext()){
    Flight flt = (Flight)it.next();
    %>
    <tr>
    <td width= "10%"><%=flt.getFlightComp()%></td>
    <td width= "10%"><%=flt.getFlightNum()%></td>
    <td width= "10%"><%=flt.getFlightDpt()%></td>
    <td width= "10%"><%=flt.getFlightArr()%></td>
    <td width= "10%"><%=flt.getFlightDptDt()%></td>
    <td width= "10%"><%=flt.getFlightDptTm()%></td>
    <td width= "10%"><%=flt.getFlightArrDt()%></td>
    <td width= "10%"><%=flt.getFlightArrTm()%></td>
    <%
    int adlt, chd;
    int fare_A, totA, fare_C, totC;
    adlt = Integer.parseInt(adult);
    fare_A = flt.getAdultFr();
    totA = adlt * fare_A;
    chd = Integer.parseInt(child);
    fare_C = flt.getChildFr();
    totC = chd * fare_C;
    %>
    <td width= "10%"><%=totA%></td>
    <td width= "10%"><%=totC%></td>
    </tr>
    <%
    %>
    </table>
    flightsearch$jsp.java
    package org.apache.jsp;
    import java.util.*;
    import com.client.entity.Flight;
    import com.client.wsclient.FlightServiceClient;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.jsp.*;
    import org.apache.jasper.runtime.*;
    public class flightsearch$jsp extends HttpJspBase {
    static {
    public flightsearch$jsp( ) {
    private static boolean jspxinited = false;
    public final void jspxinit() throws org.apache.jasper.runtime.JspException {
    public void _jspService(HttpServletRequest request, HttpServletResponse response)
    throws java.io.IOException, ServletException {
    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    String _value = null;
    try {
    if (_jspx_inited == false) {
    synchronized (this) {
    if (_jspx_inited == false) {
    jspxinit();
    jspxinited = true;
    _jspxFactory = JspFactory.getDefaultFactory();
    response.setContentType("text/html;ISO-8859-1");
    pageContext = _jspxFactory.getPageContext(this, request, response,
    "ErrorHandler.jsp", true, 8192, true);
    application = pageContext.getServletContext();
    config = pageContext.getServletConfig();
    session = pageContext.getSession();
    out = pageContext.getOut();
    // HTML // begin [file="/client/flightsearch.jsp";from=(0,59);to=(1,0)]
    out.write("\r\n");
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(1,43);to=(2,0)]
    out.write("\r\n");
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(2,58);to=(19,0)]
    out.write("\r\n\r\n<H3>Available Flight List</H3>\r\n<br>We have found the following Available flight(s) : </br>\r\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100\">\r\n <tr>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Flight Company</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Flight Number</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Depart From<font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Arrive</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Departure Date</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Departure Time</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Arrival Date</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Arrival Time</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Adult Fare</font></b></td>\r\n <td width=\"10%\" bgcolor=\"#808080\"><b><font color=\"#FFFFFF\">Child Fare</font></b></td>\r\n </tr>\r\n");
    // end
    // begin [file="/client/flightsearch.jsp";from=(19,2);to=(66,0)]
    //Get the search information
    String des = request.getParameter("DFrom");
    String arr = request.getParameter("DTo");
    String fy = request.getParameter(FYear.value);
    String fm = request.getParameter(FMonth.value);
    String fd = request.getParameter(FDay.value);
    String f1 = fy + "-" + fm;
    String FDat = f1 + "-" + fd;
    String ty = request.getParameter(TYear.value);
    String tm = request.getParameter(TMonth.value);
    String td = request.getParameter(TDay.value);
    String t1 = ty + "-" + tm;
    String TDat = t1 + "-" + td;
    String type;
    if( request.getParameter(type[0].checked))
    type = "Return";
    else
    { type = "OneWay";
    String clas;
    if(request.getParameter(clas[0].checked))
    {clas = "ECO";
    else
    {clas = "BUSS";}
    String adult = request.getParameter(Adult.value);
    String child = request.getParameter(Child.value);
    //Get the server Flight Search Service URL
    // ServerFlightSearchBO SFSBO = new ServerFlightSearchBO();
    // ServerFlightSearch FlightSearch = SFSBO.getFlightSearchURL();
    // FlightSearchServiceClient FSearchServiceClient = new FlightSearchServiceClient
    String ServerFlightServiceURL = "http://localhost:7080/AServer/services/FlightService";
    //Find available Flight
    FlightServiceClient client = new FlightServiceClient(ServerFlightServiceURL);
    ArrayList list = client.getFlight(des, arr, FDat, TDat, type, clas, adult, child);
    Iterator it = list.iterator();
    while (it.hasNext()){
    Flight flt = (Flight)it.next();
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(66,2);to=(68,18)]
    out.write("\r\n<tr>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(68,21);to=(68,40)]
    out.print(flt.getFlightComp());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(68,42);to=(69,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(69,21);to=(69,39)]
    out.print(flt.getFlightNum());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(69,41);to=(70,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(70,21);to=(70,41)]
    out.print(flt.getDestination());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(70,43);to=(71,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(71,21);to=(71,36)]
    out.print(flt.getArrive());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(71,38);to=(72,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(72,21);to=(72,36)]
    out.print(flt.getFrDate());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(72,38);to=(73,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(73,21);to=(73,41)]
    out.print(flt.getFlightDptTm());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(73,43);to=(74,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(74,21);to=(74,36)]
    out.print(flt.getToDate());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(74,38);to=(75,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(75,21);to=(75,41)]
    out.print(flt.getFlightArrTm());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(75,43);to=(76,1)]
    out.write("</td>\r\n ");
    // end
    // begin [file="/client/flightsearch.jsp";from=(76,3);to=(87,1)]
    int adt, chld;
    int far_A, tot_A, far_C, tot_C;
    adt = Integer.parseInt(adult);
    far_A = flt.getAdultFr();
    tot_A = adt * far_A;
    chld = Integer.parseInt(child);
    far_C = flt.getChildFr();
    tot_C = chld * far_C;
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(87,3);to=(88,18)]
    out.write("\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(88,21);to=(88,26)]
    out.print(tot_A);
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(88,28);to=(89,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(89,21);to=(89,26)]
    out.print(tot_C);
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(89,28);to=(91,0)]
    out.write("</td>\r\n</tr>\r\n");
    // end
    // begin [file="/client/flightsearch.jsp";from=(91,2);to=(100,0)]
    if(type = "Return")
    FlightServiceClient client = new FlightServiceClient(ServerFlightServiceURL);
    ArrayList list = client.getFlight(arr, des, FDat, TDat, type, clas, adult, child);
    Iterator it = list.iterator();
    while (it.hasNext()){
    Flight flt = (Flight)it.next();
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(100,2);to=(102,18)]
    out.write("\r\n<tr>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(102,21);to=(102,40)]
    out.print(flt.getFlightComp());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(102,42);to=(103,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(103,21);to=(103,39)]
    out.print(flt.getFlightNum());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(103,41);to=(104,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(104,21);to=(104,39)]
    out.print(flt.getFlightDpt());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(104,41);to=(105,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(105,21);to=(105,39)]
    out.print(flt.getFlightArr());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(105,41);to=(106,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(106,21);to=(106,41)]
    out.print(flt.getFlightDptDt());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(106,43);to=(107,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(107,21);to=(107,41)]
    out.print(flt.getFlightDptTm());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(107,43);to=(108,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(108,21);to=(108,41)]
    out.print(flt.getFlightArrDt());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(108,43);to=(109,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(109,21);to=(109,41)]
    out.print(flt.getFlightArrTm());
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(109,43);to=(110,1)]
    out.write("</td>\r\n ");
    // end
    // begin [file="/client/flightsearch.jsp";from=(110,3);to=(120,1)]
    int adlt, chd;
    int fare_A, totA, fare_C, totC;
    adlt = Integer.parseInt(adult);
    fare_A = flt.getAdultFr();
    totA = adlt * fare_A;
    chd = Integer.parseInt(child);
    fare_C = flt.getChildFr();
    totC = chd * fare_C;
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(120,3);to=(121,18)]
    out.write("\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(121,21);to=(121,25)]
    out.print(totA);
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(121,27);to=(122,18)]
    out.write("</td>\r\n <td width= \"10%\">");
    // end
    // begin [file="/client/flightsearch.jsp";from=(122,21);to=(122,25)]
    out.print(totC);
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(122,27);to=(124,0)]
    out.write("</td>\r\n</tr>\r\n");
    // end
    // begin [file="/client/flightsearch.jsp";from=(124,2);to=(126,0)]
    // end
    // HTML // begin [file="/client/flightsearch.jsp";from=(126,2);to=(127,8)]
    out.write("\r\n</table>");
    // end
    } catch (Throwable t) {
    if (out != null && out.getBufferSize() != 0)
    out.clearBuffer();
    if (pageContext != null) pageContext.handlePageException(t);
    } finally {
    if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);

    i am very glad and appreciate for your help, but i would like to know how to get the value of a radio button.
    like in another JSP file i have :
    <input type="radio" name="type" value="Return" checked>
    Return
    <input type="radio" name="type" value="OneWay">
    One Way
    and when i try to get the value which is checked, i put
    String type = request.getParameter(type.checked);
    but this doesn't work,
    i would be very appreciate for your help. Thank you

  • How to place download link on jsp page to download files eg. Download PDF

    Hi,
    I have made an appliaction in struts 2 which creates PDF,its working fine now i want to place a link on my jsp page from where i can click and download that PDF file which i have created and store on my local location. Also i want to to know can i place links on my jsp page to download other type of files if i want to give link on my page to download Images or songs how can i do that,
    Help plzzzzzzzzzzzz

    IF You are using jsf then simply <h:outputLink value="file:///D:/Me/Image000.jpg"/>. This generates HTML <a> tag and value attribute replacing with <a> tag's href attribute.If you are using other technologies try to find which tag generates HTML <a> tag.
    I think You also can simply place HTML <a> tag wherever You want

  • PDF File Download from a JSP

    I want to have a JSP that will be used to download/display files. I created
              a test.jsp page that tries to return a test.pdf page. Whenever I run it,
              the browser displays some characters and then hangs, but never displays the
              pdf file. If I browse directly to the pdf file it displays fine in the
              browser. What am I doing wrong in this JSP page:
              <%@ page import="java.io.*" %>
              <%
              String mimeType = "application/pdf";
              response.setContentType(mimeType);
              try
              FileInputStream fis = new
              FileInputStream("d:\\work\\internet\\appserver\\presentation\\rdoc\\test.pdf
              ServletOutputStream sos = response.getOutputStream();
              System.out.println("Begin...");
              int i = fis.read();
              while(i != -1)
              sos.write(i);
              i = fis.read();
              sos.flush();
              sos.close();
              fis.close();
              System.out.println("End...");
              catch(Exception e)
              System.out.println(e);
              %>
              

    The JSP will send new lines etc. to the output stream because you have new
              lines in your JSP.
              All right, since you asked, I will have to post my secret source:
              ----- Original Message -----
              From: "Erik Lindquist" <[email protected]>
              Newsgroups: weblogic.developer.interest.jsp
              Sent: Wednesday, June 28, 2000 6:20 PM
              Subject: How to dynamically display images in JSPs
              >
              > This took a little while to figure out so I thought I'd share. After
              > doing some research I was led to the following approach on how to load
              > images from an Oracle database into a JSP:
              >
              > The "main" JSP:
              >
              > <HTML>
              > <head>
              > <title>Image Test</title>
              > </head>
              > <body>
              > <center>
              > hello
              > <P>
              > <img border=0 src="getImage.jsp?filename=2cents.GIF">
              > <P>
              > <img border=0 src="getImage.jsp?filename=dollar.gif">
              > <P>
              > world
              > </body>
              > </HTML>
              >
              >
              > And this is the image getter:
              >
              > <% try {
              > response.setContentType("image/gif");
              > String filename = (String) request.getParameter("filename");
              > java.sql.Connection conn =
              > java.sql.DriverManager.getConnection("jdbc:weblogic:pool:orapool"); //
              > connect to db
              > java.sql.Statement stmt = conn.createStatement();
              > String sql = "select image from testimage where filename = '" +
              > filename + "'";
              > java.sql.ResultSet rs = stmt.executeQuery(sql);
              > if (rs.next()) {
              > byte [] image = rs.getBytes(1);
              > java.io.OutputStream os = response.getOutputStream();
              > os.write(image);
              > os.flush();
              > os.close();
              > }
              > conn.close();
              > }
              > catch (Exception x) { System.out.println(x); }
              > %>
              >
              >
              > The thing to note is that there are no <%@ page import="..." %> or <%@
              > page contentType="..." %> tags - just the single scriptlet. It
              > seems that for every "<%@" the weblogic compiler sees it puts
              > out.print("\r\n"); statements in the generated java source.(???) I
              > don't know much about how browsers work but I think that once it sees
              > flat ascii come at it it treats everything that follows as text/plain
              > which is incorrect for the binary stream that's being sent. Another
              > work around was to set out = null; but that's kind of ugly and might
              > produce server errors. The real fix is to write a bean to handle images
              > which I'll work on next (does anybody have any hints on how to do
              > that?)
              Peace.
              Cameron Purdy
              http://www.tangosol.com
              "Jesse E Tilly" <[email protected]> wrote in message
              news:[email protected]...
              > [email protected] (Cameron Purdy) wrote in
              > <[email protected]>:
              >
              > >Your import will always cause junk to be sent before the PDF. You
              > >should do this as a servlet, not a .jsp.
              >
              > Really? What's the difference between JSP and Servlet as far as writing
              to
              > the response object is concerned?
              >
              > Btw, I forgot to mention that the setContentType should be done as late as
              > possible. It begins the response.
              >
              > Jesse
              

  • Creating a jpg download link

    Is there a way to
    have a link download a photo jpg as opposed to displaying the photo in the browser?

    If you are using Apache as your web server, create a new text file and name it ".htaccess"
    Include this in that new text file:
    <FilesMatch "\.(?i:pdf|jpg|gif|txt|doc|exe|dmg|zip)$">
          ForceType
    application/octet-stream
          Header set Content-Disposition
    attachment
    </FilesMatch>
    Note that the first line includes all the filetypes that you want to force as downloads, separated by "|".
    Then create a new directory on your server to hold the downloadable files, such as http://www.yourdomain.com/downloads
    Save the .htaccess file to that new download directory. Do not save it to your web document root.
    Save your files that you want to download in that new download directory.
    Link to those files from your regular HTML pages.

  • How to make a file downloadable on my JSP page.......

    I want to make a file to be downloadable on my webpage. I have developed a simple lindk to the file. But internet explorer opens that file and don't show option to save it on hard disk. If any can mail me some Servlet solution or applet ( preferably servlet ) I will be very thankfull to him
    My mail address is
    [email protected]
    Please send it to me as soon as early as my M.Sc viva is going to held shortl and I have to add it before that viva.

    Hi,
    generally browsers will ask whether to save it to local drive or open it?, if you click on a link that has link to a file. This you need to set in the browser's options. check your browser's options and set the option to show the dailog box if you click a hyperlink.
    have fun!!
    --raj                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • File Download links on ADF pages

    Hi All, My requirement is to display no. of document links in pages. I am trying to use <af:fileDownloadActionListener> .
    I am getting list of files/document while loading the page from backing bean and looping through it using <af:forEach>..
    when i click on any link to download the document then fileDownloadBean.download function is called. So in backing function
    download how i know which document user has clicked to download ? Any idea ?
    <af:panelList id="pl1" clientComponent="true" >
    <af:forEach var="file" items="#{fileDownloadBean.listFiles}" >
    <af:commandLink text="#{file}" actionListener="#{fileDownloadBean.buttonClicked}" />
    <af:commandLink text="#{file}" visible="false" id="cl2" actionListener="#{fileDownloadBean.buttonClicked}">
    <af:fileDownloadActionListener filename="#{file}"
    contentType="application/msword"
    method="#{fileDownloadBean.download}" />
    </af:commandLink>
    </af:forEach>
    </af:panelList>

    Hi Tim, I tried to follow same step as mentioned in your blog..but getting y error no object found by id...
    function customHandler(event){ 
    var exportCmd = AdfPage.PAGE.findComponentByAbsoluteId("::cl2");
    alert('hello');
    var actionEvent = new AdfActionEvent(exportCmd);
    actionEvent.forceFullSubmit();
    actionEvent.noResponseExpected();
    actionEvent.queue();
    In my program commandlink is rendering by for each loop...i think in for each loop...iterating component does not assign proper ids...
    <af:panelList id="pl1" clientComponent="true" >
    <af:forEach var="file" items="#{fileDownloadBean.listFiles}" >
    <af:commandLink text="#{file}" clientComponent="true" partialSubmit="true" actionListener="#{fileDownloadBean.buttonClicked}" />
    <af:commandButton text="#{file}" id="cl2" visible="false" clientComponent="true" >
    <af:fileDownloadActionListener filename="#{file}"
    contentType="application/msword"
    method="#{fileDownloadBean.download}" />
    </af:commandButton>
    </af:forEach>
    </af:panelList>
    I appreciate your help..
    Thanks

  • Need Help creating a file download button

    Hello again,
    i am trying to make a button that when clicked will prompt
    the user to downalod a file to a target directory of the users
    choice. I have tried using URLRequest but it just opens the mp3 on
    another window with qiucktime which, i suspect, will happen with
    most users. is there a simple way to do this? i have no problem
    creating the button its just the function code for the button im
    lost on. thanks in advance
    Tim
    http://www.survivalsuit.org

    Check out the FileReference class... "The FileReference class
    provides a means to upload and download files between a user's
    computer and a server." (ActionScript 3.0 Language and Components
    Reference)
    At this moment, you know as much as I do about it, so I don't
    know if it's really what you need. But if it is, and you figure out
    the code, it'd be great if you put the coded solution here for the
    benefit of others (you know, pay it forward and all that).

Maybe you are looking for