I have a question about JSP,I put some Java code into JSP,it like follows:

<%@page language="java"%>
<%@page import="java.io.*" %>

<html>
<head>
  <title>test</title>
</head>
<body background="images/send.jpg" text="FF0000">
   <%
     String value[]=new String[2];
     String str;
     value[0]="8";
     try
     {

         InputStream is = this.getClass().getResourceAsStream("version.data");
         BufferedReader input = new BufferedReader(new InputStreamReader(is));
         str=input.readLine();
     }
     catch(IOException e)
     {
        System.out.println("read file error");
     }
   %>

   ....
</body>
</html>

when I run it,it raise errors:
Description:
   The server encountered an internal error (Internal Server Error) that prevented it 
from fulfilling this request

exception:
java.lang.NullPointerException
 at java.io.Reader.(Reader.java:61)
 at java.io.InputStreamReader.(InputStreamReader.java:55)
 at org.apache.jsp.start_0005fsend$jsp._jspService(start_0005fsend$jsp.java:75)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)

Then I extract my Java code,and put it into Java file,like follows:

import java.io.*;
public class test8
{
   public static void main(String args[])
   {
       test8 ss=new test8();
       ss.pp();
   }
   public void pp()
   {
       String value[]=new String[2];
       String str;
       value[0]="8";
       try
       {
          InputStream is = this.getClass().getResourceAsStream("version.data");
          BufferedReader input = new BufferedReader(new InputStreamReader(is));
          str=input.readLine();
          System.out.println(str);
       }
       catch(IOException e)
       {
          System.out.println("read file error");
       }
  }
}

It run ok.Why my code can't run in JSP and can run in Java? How to correct to make my 
Java code run in JSP?

Thanks in advance!
Edward

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to