Solved

how to write include in new file in server

Posted on 2003-11-18
3
347 Views
Last Modified: 2013-11-18
hello all,

how can i write an include file in my page..???
the script is like this

String mycode ="<%@ include file= ../../../usr/local/tomcat4/webapps/myfolder/myfile.jsp%>";

File aFile = new File(dir,"index.php");
FileWriter fw=new FileWriter(aFile);
PrintWriter pw=new PrintWriter(fw);

pw.print(mycode);
pw.close();


when i open file index.php it will call include file myfile.jsp.
right now i've got errors on the mycode.
how can i resolve it??
0
Comment
Question by:eg4
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
vk33 earned 50 total points
ID: 9777402
no, no... "include" is a directive to the JSP-processing engine. It puts the contents of the specified file instead. And you cannot insert a JSP-directive into your java-code. This is ok:
<%@ include file= ../../../usr/local/tomcat4/webapps/myfolder/myfile.jsp%>
<%
   // your code here
%>

To read the contents of a file do the following:

StringBuffer mycode = new StringBuffer();
BufferedReader fi = new BufferedReader(new FileReader("/usr/local/tomcat4/webapps/myfolder/myfile.jsp"));
String tmp = null;
while ((tmp = fi.readLine()) != null)
   mycode.append(tmp);
fi.close();
File aFile = new File(dir,"index.php");
FileWriter fw=new FileWriter(aFile);
PrintWriter pw=new PrintWriter(fw);

pw.print(mycode.toString());
pw.close();

Good luck!
0
 

Author Comment

by:eg4
ID: 9784145
thanx vk33.
I'm really appreciated your help. the code went perfect for my application.
thanx once again...:)
u deserve the points!!!
0
 
LVL 4

Expert Comment

by:vk33
ID: 9785329
Always welcome! ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now