Solved

how to write include in new file in server

Posted on 2003-11-18
3
346 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

758 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

24 Experts available now in Live!

Get 1:1 Help Now