You are here: Articles > Computers & Technology > jsp

 See more articles about "jsp "

JSP and JSTL Tutorials - Tutorial Addendum - Authoritative HTTP Acknowledgment Attack Curve



 31 December 18:00   

    



    



    

(Continued from antecedent part...)

    



    

Generating Non-HTML Article Body

    



    

Sometimes, you may wish to forward aback advice in the article physique that are

    

not in the HTML format, for example, a PDF document, or a MS Chat Document. In this

    

case, we accept to set Content-Type, Content-Length and additional attack curve carefully

    

to accommodate actual advice about the article physique for the applicant program.

    

Here is a sample PHP Software to appearance you how to set attack curve for altered types

    

of data in the article body.

    

 

    

<?php #GetFile.php

    

# Absorb (c) 2005 by Dr. Yang, http://www.yang.com/

    

#

    

$ok = array_key_exists( QUERY_STRING , $_SERVER);

    

if ($ok) {

    

$p = $_SERVER[ QUERY_STRING ];

    

$ok = strlen($p)>0 && file_exists($p);

    

}

    

if ($ok) {

    

if (strpos($p,".html")!=false) {

    

header("Content-Type: text/html");

    

} abroad if (strpos($p,".gif")!=false) {

    

header("Content-Type: image/gif");

    

} abroad if (strpos($p,".pdf")!=false) {

    

header("Content-Type: application/pdf");

    

} abroad if (strpos($p,".doc")!=false) {

    

header("Content-Type: application/msword");

    

} abroad {

    

$ok = false;

    

}

    

}

    

if ($ok) {

    

header("Content-Length: ".filesize($p));

    

readfile($p);

    

} abroad {

    

print("<html><body>Bad request.</body></html>");

    

}

    

?>

    



    



    

Ideas acclimated in this script:

    



        

  • The cold is to forward aback the agreeable of the requested file

        

    in article body, and set the Content-Type and Content-Length attack curve correctly.



  •     

  • The requested book name is accustomed in the concern cord of the HTTP request.

        

    array_key_exists() is acclimated to create abiding the concern cord is provided to abstain arrangement basis error.



  •     

  • The addendum of the requested book name is arrested to actuate the Content-Type

        

    header line. strpos() is acclimated as a Boolean amount to analysis the book name extension.



  •     

  • Then the requested book admeasurement is arrested to set the Content-Length attack line.


  •     

  • Then the requested book is outputted to the HTTP acknowledgment with a individual action readfile().

        

    This action name is a little bit misleading, but the action is actual useful.

        



  •     

  • If any affair goes wrong, a HTML article is alternate with an absurdity message. A Boolean capricious $ok

        

    is acclimated to adviser the absurdity condition.



  •     



    



    

Now let s see how this page works. Bold I accept GetFile.php, hello.html, dot.gif, hello.pdf,

    

and hello.doc affected to c:inetpubwwwroot directory. Of course, my IIS is configured to the PHP engine.

    



    

1. Use IE (Internet Explorer) to request: http://localhost/GetFile.php?hello.html,

    

you should see the accost bulletin appropriately displayed as a HTML document.

    



    

2. Use IE to request: http://localhost/GetFile.php?dot.gif,

    

you should see a tiny dot displayed as an image.

    



    

3. Use IE to request: http://localhost/GetFile.php?hello.pdf,

    

you should see IE calling Adobe Clairvoyant to affectation the accost bulletin as a PDF document.

    



    

4. Use IE to request: http://localhost/GetFile.php?hello.doc,

    

you should see IE calling MS Chat to affectation the accost bulletin as a MS Chat document.

    



    

5. Use IE to request: http://localhost/GetFile.php?any.file,

    

you should see IE announcement an absurdity message. The reason, of course, is that

    

the requested book doesn t exist.

    



    

6. Use IE to request: http://localhost/GetFile.php

    

you should see IE announcement an absurdity message. The cause is that there is no concern string

    

in the HTTP request.

    

(Continued on next part...)

    



    < src="_200x90.js">

    



    



 


 content, header, request, getfile, requested, message, localhost, entity, strpos, false, lines, query, error, document, string, length, function, exists, array, response, , getfile php, request http, content type, http localhost, localhost getfile, requested file, header content, header lines, php hello, entity body, content length, query string, error message, file name, http response, http localhost getfile, request http localhost, header content type, content type application, content length header, php hello html, requested file name, response header lines, tutorial notes controlling, tutorials tutorial notes, notes controlling http, controlling http response, http response header, jstl tutorials tutorial,

Share JSP and JSTL Tutorials - Tutorial Addendum - Authoritative HTTP Acknowledgment Attack Curve:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

JSP and JSTL Tutorials - Tutorial Addendum - Authoritative HTTP Acknowledgment Attack Curve
i(Continued from antecedent part...)/iSending Files for DownloadingIn the antecedent section, the requested book is delivered to the browser for aperture immediately. p

JSP and JSTL Tutorials - Tutorial Addendum - JSP Sessions and Debugging
This affiliate describes:What is a session.How use affair in a PHP script.A affair analysis with 3 scripts.How affair ID can be managed after

JSP and JSTL Tutorials - Tutorial Addendum - JSP Sessions and Debugging
i(Continued from antecedent part...)/iSessionPage2.php: <?php SessionPage2.php Absorb (c) 2002 by Dr. Yang session_start(); $quantity = $_SESSION; $pr

JSP and JSTL Tutorials - Tutorial Addendum - JSP Sessions and Debugging
i(Continued from antecedent part...)/iHere is my sample Perl program, reg_client.pl, advised to plan with my antecedent JSP allotment application: reg_client.pl Absorb (c) 20

JSP and JSTL Tutorials - Tutorial Addendum - JSP Custom Tag
What is a Custom Tag?Custom Tag is an activity tag authentic by the user through the JSP tag addendum facility. It can be acclimated to move JSP page assembly logics and advi

JSP and JSTL Tutorials - Tutorial Addendum - JSP Custom Tag
i(Continued from antecedent part...)/i3. Autograph the tag library descriptor (tld) file. Now, I charge to ascertain a tag in a tag librarydescriptor book to use the tag class. Actuality is my first tld file, HyT

JSP and JSTL Tutorials - Tutorial Addendum - JSP Tag Aspect Administration
Tag Aspect Setter MethodThe JSP tag addendum ability maps anniversary aspect encountered in a customtag to an acreage of the aforementioned name of the tag object. So if you wish b

JSP and JSTL Tutorials - Tutorial Addendum - JSP Tag Aspect Administration
i(Continued from antecedent part...)/iTag Aspect Amount Blazon ConversionIn my antecedent example, the aspect amount is anesthetized to the tag item propertyas a cord

JSP and JSTL Tutorials - Tutorial Addendum - JSP Tag Aspect Administration
i(Continued from antecedent part...)/iThe JSP file: <?xml version="1.0"?<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jstl/core"

JSP and JSTL Tutorials - Tutorial Addendum - JSP Tag Aspect Administration
i(Continued from antecedent part...)/iTag Aspect Amount Announcement Archetype AttObjectTag.javaThe tag class: /** * AttObjectTag.java