aspose file tools*
The moose likes JSP and the fly likes Include Directive return from a Function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Include Directive return from a Function" Watch "Include Directive return from a Function" New topic
Author

Include Directive return from a Function

sonu arora
Ranch Hand

Joined: Jul 25, 2002
Posts: 30
Hi all,

Source.jsp -----

<%@ page import="test.testing" %>
<%= testing.get() %>

testing.java -----

public static String get() {

return ("<jsp:include page='test.jsp' />");
}

The problem is i am not getting the content of test.jsp in Source.jsp.
it is only showing me the include directive in the string format.
any one can help.


try & try u ll surely win.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61201
    
  66

Cannot be done that way. What are you really trying to accomplish?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sonu arora
Ranch Hand

Joined: Jul 25, 2002
Posts: 30
Bear

I want to read a config file inside a java file and then this java file will return the include directive (from config) to the calling jsp file which shld include the content of that included jsp.
That config file may have 0 or n number of jsp's to be included.
Sachin Joshi
Ranch Hand

Joined: Mar 23, 2004
Posts: 43
Originally posted by sonu arora:
Bear

I want to read a config file inside a java file and then this java file will return the include directive (from config) to the calling jsp file which shld include the content of that included jsp.
That config file may have 0 or n number of jsp's to be included.



Hi sonu,

I will try to answer your query. See, slightly going in the details of Page Life Cycle of JSP page, you must be knowing that

*JSP file is translated into the servlet class.
* During the translation process, all the code written in the scriptlets (<%..%> and Expressions(<%= ..%>
is put in the _jspService() method as a Java statements.
*Once the translation process is complete, this java class is compiled, created a instance of it and the output
written to the JspWriter is displayed on the screen.

Now, taking your code,

*<%= testing.get() %> is a Expression type statement, so on translation it will put the following line in _jspService() method.

out.print(testing.get());

* So, during the runtime, it will write the output of get() method on the screen. Your get() method is returning
this "<jsp:include page='test.jsp' />" statement. Hence, it will print this STRING on the screen.

It is happening correctly as per what you have coded. But, you want something different.

You want this include statement to be executed by JSP Engine. Now, for this to happen, you should have
<jsp:include page='test.jsp' /> statament in your JSP file before the page is translated into the servlet. So that, during the translation process, JSP engine will translate your INCLUDE statement by actually putting the output of the said files in the output of your JSP file.


I Hope, it will help you.

Regards,
Sachin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Include Directive return from a Function