0

Hello I have this..
I have a Scrip with name MiScript.jsp and code....

<%@ include file="Func.jsp" %>
<jsp:include page="Func.jsp"/>
<%
      String Mipath = "C:\\";
      String Mifile = "File.Ext";
      if(mifuncion(Mipath , Mifile )) {
        out.println("OK!!!");
      } else{
        out.println("ERROR!");
      }
%>

And I have the other Script Func.jsp with a Method....

<%@ page import="java.lang.*" %>
<%@ page import="java.io.*" %>
<%@ page language="java" %>
<%!  boolean mifuncion(String Arg1, String Arg2){
    try {
      FileOutputStream fileOut = new FileOutputStream(Arg1+Arg2);
      fileOut.write("hola");
      fileOut.flush();
      fileOut.close();
      return true;
    } catch (FileNotFoundException fnfe) {
        out.write(fnfe.toString());
    } catch (EOFException eofe) {
        out.println(eofe.toString());
    } catch (IOException ioe) {
        out.println(ioe.toString());
    }
    return false;
%>

I have error using out.write and/Or out.println

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by parry_kulk
0

Implicit objects are only visible within the system generated _jspService() method. They are not visible within methods you define yourself in declarations. So you are getting errors with out.write and/Or out.println. We have to pass them to our own method if we wish to use them locally in those functions.

Here's your code modified to give some idea on this point

<%@ include file="Func.jsp" %>
<jsp:include page="Func.jsp"/>
<%
      String Mipath = "C:\\";
      String Mifile = "File.Ext";
      //pass the out implicit object as a parameter
      if(mifuncion(Mipath , Mifile, out )) {
        out.println("OK!!!");
      } else{
        out.println("ERROR!");
      }
%>

and

<%@ page import="java.lang.*" %>
<%@ page import="java.io.*" %>
<%@ page language="java" %>
<%!  boolean mifuncion(String Arg1, String Arg2, javax.servlet.jsp.JspWriter out) throws IOException{
    try {
      FileOutputStream fileOut = new FileOutputStream(Arg1+Arg2);
      fileOut.write(1); //Cant use string here
      fileOut.flush();
      fileOut.close();
      return true;
    } catch (FileNotFoundException fnfe) {
        out.write(fnfe.toString());
    } catch (EOFException eofe) {
        out.println(eofe.toString());
    } catch (IOException ioe) {
        out.println(ioe.toString());
    }
    return false;
}
%>

Edited by parry_kulk: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.