Quoting Spencer Christensen <[EMAIL PROTECTED]>:
> Hello Bal,
>
> If you want to display the entire page as text/plain, then there are a
> few
> things you should change. First of all, you should add error checking
> to your
> open statement (this is just good programming practice). Second, you
> try to set
> the header for the page by $q->header('text/plain'), but this won't
> work.
> Instead you should set it by $self->header_props(-type=>'text/plain').
> And
> third, if you want the whole page to be plain text, don't start and end
> the page
> with HTML (this will just show up as extra text). Here is my version of
> your
> code:
>
> sub showdetails {
> my $self = shift;
> #Get CGI query object
> my $q = $self->query();
> my $app = $q->param("app") || '';
> my $tdir =$q->param("tdir") || '';
> my $yrs =$q->param("yrs") || '';
> my $dts =$q->param("dts") || '';
> my $rep = $tdir. "\\\\" . $app . "\\\\" . $yrs . "\\\\" . $dts;
>
> open(FH, $rep) or return "Cannot open $ref: $!"; # Error checking
> my $output = join('', <FH>); # Put entire file into one string
> close(FH);
> $self->header_props(-type => 'text/plain'); # Set page as plain text
> return $output;
> }
It's kind of wierd to reply to your own message, but I just felt I should add a
note about error checking. The error checking I added to your open statement is
ok while you are coding and debugging, but is not really suitable for
use in production. In a production application, you should have a more
ellaborate error checking system which provides understandable error messages
for the users and doesn't give the appearance of a "crash". I use a log file
for all of my error messages (and also for debugging) and have a template for
error messages for the users. This system works pretty well for me (I have a
CGI::App base class with logfile() and error_page() methods). I'm sure there
are other ways of handling errors out there. I'd be interested to hear what
others have developed.
-spencer christensen
[EMAIL PROTECTED]
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]