Solved

how to write include in new file in server

Posted on 2003-11-18
3
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

717 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