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

Recommended Answers

All 2 Replies

What is the error that you are getting??

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;
}
%>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.