How To Make Void That Prints Something In JSP

hi Everyone I'm Very New To Java & JSP I'm Expert In PHP , Anyway . .

I want A Code like The Following Print Something Out :

<%@ pageimport ="java.io.*"%>

<%!

publicvoid str_repeat(String str2,int num){

int i;String FINAL="";

for(i=0;i<num;i++)FINAL=FINAL+str2;

System.out.print(FINAL);

}

%>

<%

str_repeat("SOMETHING",2);

%>

And Please I don't Want Anyone to Come UP with A Function That Makes The String Repeat (( I Wan To Learn How To Make A Void That Outputs Something )) And Not A Function . .

notice : The Above Code Gives Nothing At All And When I Use

out.print

Instead Of System.out.print

It Gives Error

[1081 byte] By [shehabica] at [2007-11-27 3:46:17]
# 1

The method str_repeat does not have access to the implicit variable "out" and as such can not do output all on its own.

One solution would be pass the JSPWriter to the method to let it do output.

ie

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

<%!

public void str_repeat(String str2,int num, JSPWriter out){

int i;String FINAL="";

for(i=0;i<num;i++)FINAL=FINAL+str2;

out.print(FINAL);

}

%>

<%

str_repeat("SOMETHING",2, out);

%>

Cheers,

evnafets

evnafetsa at 2007-7-12 8:50:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

My Code Now Is As Follows :

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

<%!

public void str_repeat(String str2,int num, JspWriter out){

int i;String FINAL="";

for(i=0;i<num;i++)FINAL=FINAL+str2;

out.print(FINAL);

}

%>

<%

str_repeat("SOMETHING",2, out);

%>

and it gives the following error :

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 17 in the jsp file: /index.jsp

Unhandled exception type IOException

14: public void str_repeat(String str2,int num, JspWriter out){

15: int i;String FINAL="";

16: for(i=0;i<num;i++)FINAL=FINAL+str2;

17: out.print(FINAL);

18: }

>

shehabic1a at 2007-7-12 8:50:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Ok Added The Following And It Worked Thanks For Your Help Anyways . . throws java.io.IOException
shehabic1a at 2007-7-12 8:50:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
hmm I Couldn't Delete This Post ... I'm Sorry . .Message was edited by: shehabic1
shehabic1a at 2007-7-12 8:50:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...