Hi All, Can we have complete URLs instead of relative URLs in the include directive or forward tags i,e <%@include file="http://localhost/dir1/file1"> instead of the relative path of the file.
And also what should i do if I want to have many text strings throughout the application, something like tokens which I can replace at my html pages so that it is generic and is stored as one file. I am aware of the properties file , but is there any thing in JSP itself which would allow me to do this without writing lots of java code. Also is there any directive ot tag in JSP which would allow me to do some basic validation on the fields. Thanks for your help. Vijay
Joined: Nov 22, 2008
Can any body say something about the above issues. Thanks
Hi vijay, For the first question, No. We can't use with protocol,port,domain name etc. It is ALWAYS RELATIVE. I did check this with one of my web application. When we include the full path like "http://localhost:....." , the jsp DOES NOT include the contents. On the other hand when we say the relative url, it includes the contents of the 'relative url' file. To confirm this I went to Sun's site and refered to their JSP syntax reference. It also says this. This reference is really helpful and handy at needed times. Please check this Jsp Syntax reference list at Sun's site. --------------------------------------- http://java.sun.com/products/jsp/tags/11/tags11.html
The include tag reference is here --------------------------------------- http://java.sun.com/products/jsp/tags/11/syntaxref11.fm6.html It says this "The pathname to the included file, which is always a relative URL. Simply put, a relative URL is just the path segment of an URL, without a protocol, port, or domain name, like this: "error.jsp""/templates/onlinestore.html""/beans/calendar.jsp" For the second part I post it soon. regds maha anna
Joined: Nov 22, 2008
Hi Maha anna, Thanks for replying, Don't you think it would have been helpful if they had included provision of having complete URLs, some application would like to generate this URLs on fly, now they have to write a complicated code get the relative URLs. I don't think I like JSP, for the simple reason you have to write lots of Java code on the page. And also if you define a JavaBean you can't pass a parameter to the constructor. Whats the real use??? Regards Vijay
If you want to include something from a complete URL, then you should use the <jsp:include page="whatever"> tag. This is designed to connect to a local or remote URL, get its content, and include it in the JSP output stream. This is done at run time, so is suitable for including the output of frequently changing web pages, servlets, CGIs etc. The <%@include file="whatever" %> tag, on the other hand is designed to be used at compile-time to allow common areas of jsp text or code to be included by multiple JSPs. For this reason it makes sense to only provide access to files on the local system. If what you really want is a template system with lots of values filled in at run time, then you should probably be considering something like WebMacro ( http://www.webmacro.org/ ), rather than JSP.
Vijay, For the 2nd question of yours, To use a global var throughout the application I use this method. 1. Define an interface AllConstants.java 2. make all the vars as 'public static final' ones. For Example my AllConstants.java looks like this.
So in the .jsp file I grab the var AUTHOR and AUTHOR_EMAIL like this.