Compiler Include Directive

Is there an equivalent to the include directive? I don't mean the import statement, I mean the include directive such as available in many other languages that will place the contents of a file inline with the java source.
Basically, just like the JSP include. I have a program of about 100 servlets and parts of the code is exactly the same in every servlet.
The code is too small to create a seperate class and call it from every servlet and I'd consider it needless overhead.
I've gotten most of the functionality by creating an interface and implementing and using final variables but I have blocks of code that I want inserted inline at different places within some methods. final is okay for variables but I need to insert lines of code, which final won't work for.
Thanks,
Bob

Why not just have all the servlets be subclasses of some servlet class that includes that common code as a method?

Similar Messages

  • Jsp:include directives compilation errors

    hi,
    we have lot of <%@ include file="" %> files in out jsp page. when we trying to change this to <jsp:include page="" %>. we r getting lot of comilation errors
    The file size is increasing more than 64mb.
    Can u tell how to contain them within 64mb .
    thank you.

    The stack trace isn't very indicative of whatever problem you may be having.
    However, there is a major difference between <%@ include %> and <jsp:include />. The include directive <%@ include %> slams the content of the included resource into your JSP at compilation time, it is "static". No individual evaluation of the included resource is done, it becomes a part of the JSP that included it.
    <jsp:include /> is a dynamic include--it is evaluated at run-time. The content of the included resource is accessed and written to the output stream with the JSP is accessed. If the included content is a JSP, it is compiled and accessed as a separate servlet.
    So, it looks like your included JSPs do not qualify as valid, standalone JSPs. Typically, this is because of some dependency on variables or beans declared in the including JSP.
    Good luck.
    -brian

  • A variable in the include directive

    Hello,
    I'm trying to store a part of the name of the file to include in a variable like this:
    <%@ include file=templatepath + "settings.jsp" %>
    but it doesn't work. Can someone tell me if there is a working way to do something similar
    Thanks,
    Store

    You can use the jsp:include tag to specify the page to include dynamically.
    <jsp:include page="templatepath + "settings.jsp" flush="true"/>You can't use the include directive to dynamically specify a page since the page is included at compile time, rather than run time.

  • JSP include directive not working with Tomcat 5.0

    Hi.
    I'm developing a small JSF webapp under Tomcat 5.0. My idea was to use the include directive to display a navigation panel on every JSP page.
    I took the code straight from the Java Web Services Tutorial; the resulting page looks like this:
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
           version="2.0">
    <jsp:directive.page contentType="text/html;charset=iso-8859-1"/>
    <%@ include file="/jsp/panelpage_header.inc" %>
         <h:outputText value="Welcome!"/>
    <%@ include file="/jsp/panelpage_footer.inc" %>
    </jsp:root>However, when I try to load the page, a compilation error occurrs:
    org.apache.jasper.JasperException: /trias/welcome2.jsp(11,2) The content of elements must consist of well-formed character data or markup.
         org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
    ...I checked the path to the included files, and it seems to be okay. The files themselves contain the JSF tags for the view, html-head, html-body etc. The compiler doesn't even care if the files exist or not because it aborts immediately when it reaches the first include-statement.
    Did anyone see this kind of error before?

    Ok, the solution with jsp:directive.include works,
    if header.inc and footer.inc themselves are well
    formed too. If I understood the concept right this is
    because header and footer are processed during
    request time and therefore interpreted as
    'standalone' pages.This isn't true. The include directive (<jsp:directive.include>) is run a Compile Time. The code is inserted directly into the surrounding JSP (unlike <jsp:include> which forwards the request at runtime). The finished JSP, after the include, is then processed and needs to be well-formed XML.
    >
    But: What can I do when these two files define a tag
    that should enclose my current page (for example,
    header opens a panelGrid-Tag, and footer closes it).
    For this case I thought the use of the
    @include-directive would be neccessary to combine the
    three pages during compilation. By this the resulting
    page would be well-formed although header and footer
    are not.It should be, as long as you are using <jsp:directive.include>, and the rest of the included pages are also well formed (no <% %> tags, nothing else out of place...).
    Honestly, I haven't done much work with JSP documents, so I haven't run into this problem. But I do believe everything I said is correct.
    What I would do is double check the correctness of the rest of the included pages and see if your error isn't something else.

  • Dynamic file parameter with include directive

    I would like to include the file path contained in a string variable with the include directive.
    I'm trying to do the following:
    <%
    String var_fileToInclude = "inc/topnav_" + var_sectionType + ".jsp";
    include file=var_fileToInclude;
    %>
    I get the following error:
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: Unable to compile class for JSP:
    An error occurred at line: 6 in the jsp file: /news/special_reports/climate/inc/topnav_includer.jsp
    include cannot be resolved to a type
    3: String var_fileToInclude = "inc/topnav_" + var_sectionType + ".jsp";
    4: out.println( "var_fileToInclude = " + var_fileToInclude );
    5:
    6: include file=var_fileToInclude;
    7:
    8: %>
    Stacktrace:
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
         org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    Any help is greatly appreciated.
    -- Ryan Chapin

    hello,
    Are you able to print the file name. if you are able to print the file name properly then try to include the file as below
    <jsp:include page="<%=filevariablenema%>" flush="true" />
    I hope this will help. Let me know on the same.
    Thanks
    Suresh

  • Include directive with dynamic attribute file

    Hello, currently I'm wrestling with the following problem. I want to include a certain file in a JSP and I'm receiving the filename to be included from the request as a parameter.
    This is my code so far.
    <%-- Include dynamical path settings --%>
    <% java.lang.String envJsp=request.getParameter("envJsp");%>
    <%@ include file="<%=envJsp%>" %>
    <%-- End Include dynamical path settings --%>
    This results in the following error:
    org.apache.jasper.JasperException: Bad file argument to include
         java.lang.Throwable(java.lang.String)
         java.lang.Exception(java.lang.String)
         javax.servlet.ServletException(java.lang.String)
         org.apache.jasper.JasperException(java.lang.String)
         void org.apache.jasper.compiler.JspParseEventListener.handleDirective(java.lang.String, org.apache.jasper.compiler.Mark, org.apache.jasper.compiler.Mark, java.util.Hashtable)
         void org.apache.jasper.compiler.DelegatingListener.handleDirective(java.lang.String, org.apache.jasper.compiler.Mark, org.apache.jasper.compiler.Mark, java.util.Hashtable)
         boolean org.apache.jasper.compiler.Parser$Directive.accept(org.apache.jasper.compiler.ParseEventListener, org.apache.jasper.compiler.JspReader, org.apache.jasper.compiler.Parser)
         void org.apache.jasper.compiler.Parser.parse(java.lang.String, java.lang.Class [])
         void org.apache.jasper.compiler.Parser.parse(java.lang.String)
         void org.apache.jasper.compiler.Parser.parse()
         boolean org.apache.jasper.compiler.Compiler.compile()
    Has anyone experience with this, or isn't it possible at all perhaps???
    All suggestions are more than welcome.
    Greetings, Johan

    try with requestDispatcher, e.g.
    RequestDispatcher requestDispatcher = request().getRequestDispatcher( request.getParameter("envJsp" );
    requestDispatcher.include(request,response);

  • The Include Directive (at Page Translation Time)

    Version: 5.1
              Service Pack: 6
              I am generating the following error when I attempt to manually compile a JSP
              file:
              [jspc] parsing /vobs/projects/public_html//test.jsp:
              WARNING: Failed to include file 'test.inc' in include directive of page
              /test.jsp
              I've attempted practically every permutation of full and relative path
              locations, and cannot get it to work. Weblogic's JSP documentation did not
              have much to say about this either.
              Is anyone aware of a bug in the jsp compiler that would cause such a
              problem?
              

    Really strange, I used absolute path and put it under docroot, and I didn't
              put that folder into my any of my classpaths, the wls can find it without
              any problem. I used wls5.1 and sp6, do I miss sth?
              Thanks.
              mreiche <[email protected]> wrote in message
              news:[email protected]...
              >
              > No, it's not useless to add the include directory to the classpath - due
              to a bug in WLS 5.1,
              > it looks in the classpath for include files that begin with '/'.
              >
              > He is using the absolute path. That's why WL does not find it.
              >
              > Mike.
              >
              > "Tao Zhang" <[email protected]> wrote:
              > >
              > >Anchal Jain <[email protected]> wrote in message
              > >news:[email protected]...
              > >>
              > >> I added the directory that contains the included files to the
              > >> classpath but I still get the error below.
              > >It's useless to add such directory to the classpath. Please remove it.
              > >In order to recompile it dynamically you have to set it up in
              > >weblogic.properties file.
              > >
              > >>
              > >> WARNING: Failed to include file 'authenticate.jsp' in include
              > >> directive of page /analyze.jsp
              > >>
              > >You should inlcude all these jsps under your docroot.
              > >
              > >Make sure the relative path of include directive is right. Or you can use
              > >the absolute path and try.
              > >
              > >> Do I have to compile the included files
              > >> individually and then compile the main jsp?
              > >>
              > >> Any suggestion will be greatly appreciated.
              > >>
              > >> Anchal
              > >>
              > >>
              > >> "Greg Panzer" <[email protected]> wrote:
              > >> >The Weblogic JSP compiler is looking in the classpath for the include
              > >files.
              > >> >
              > >> >When manually compiling the JSPs, put the docroot in the CLASSPATH.
              > >> >
              > >> >Greg Panzer <[email protected]> wrote in message
              > >> >news:[email protected]...
              > >> >> Version: 5.1
              > >> >> Service Pack: 6
              > >> >>
              > >> >> I am generating the following error when I attempt to manually
              compile
              > >a
              > >> >JSP
              > >> >> file:
              > >> >>
              > >> >> [jspc] parsing /vobs/projects/public_html//test.jsp:
              > >> >> WARNING: Failed to include file 'test.inc' in include directive
              of
              > >> >page
              > >> >> /test.jsp
              > >> >>
              > >> >> I've attempted practically every permutation of full and relative
              path
              > >> >> locations, and cannot get it to work. Weblogic's JSP documentation
              did
              > >> >not
              > >> >> have much to say about this either.
              > >> >>
              > >> >> Is anyone aware of a bug in the jsp compiler that would cause such a
              > >> >> problem?
              > >> >>
              > >> >>
              > >> >>
              > >> >>
              > >> >
              > >> >
              > >>
              > >
              > >
              >
              

  • "include directive or jsp:include "

    Hi,
    Which amongst <%@ include file="header.jsp" %> and
    <jsp:include page="header.jsp"/>to be used, when performance is taken into account.

    Code copy from serverside.com
    Is it the same as --> jsp:include and %@ include directive.
    Actually, <jsp:include> vs. <%@ include %> is a different story.
    <%@ include %> is a "compile-time" include. The included file is inserted into the JSP when the JSP compiles.
    <jsp:include> is a "run-time" include. If JSP-1 includes JSP-2, JSP-2 is invoked when JSP-1 executes, and the output of JSP-2 is inserted into the output stream of JSP-1.
    The run-time include runs a bit slowly, but can save a lot of system memory, so in general, the run-time include is preferable. Only use the compile-time include if the include code must be in the same page.
    For example, if you want to use an include that defines a bunch of tag libraries with the taglib directive, it will have to be a compile-time include. If you just want to insert a standard header and footer in your page, a run-time include will be more effecient.
    I hope its enough for you to get an clear cut idea,

  • What's the difference between include directive & include action tag?

    I no that the directive is used for including static content,
    while the action is also used for dynamic content.
    So the first one will include the content into the JSP only at compilation time. The second one will include the content every time you access the JSP.
    *<html>*
    *<body>*
    *<h1> Include Action test PAge</h1>*
    *<h2> Using the include directive</h2>*
    *<%@ include file="included2.html"%>*
    *<%@ include file="included2.jsp"%>*
    *<h2> Using the include action</h2>*
    *<jsp:include page="included2.html" flush="true"/>*
    *<jsp:include page="included2.jsp" flush="true"/>*
    *</body>*
    *</html>*    I tried withis code. But its giving the same result.I didn't modified the source. I modified in the included file.As I request for the JSP page I got the same result for both.
    so i just want to know that is thier any way or example by which i can see the difference between these two clearly..
    please help me out.
    thnx.

    As our almighty Google says: @include is compiletime and jsp:include is runtime.
    Install Google at your machine. It's really great. It has answers on almost all questions.

  • How to include servlet in JSP using Include Directive?

    Hi experts,
    am a beginner to JSP.. I want to know,
    is it possible to include a servlet in jsp using include directive? could any one explain me...

    No it is not possible.
    Include directive is like copying and pasting some text into a JSP file, and then translating/compiling it.
    So the only thing you can include with the <%@ include %> directive is a jsp fragment
    It is a static translation/compile time include and thus will always be the same
    By contrast <jsp:include> is a runtime include, and includes the result of running the imported url.
    That URL has to be a complete/standalone jsp/servlet/whatever. However as it is runtime, it can take parameters where the include directive can not.
    Does that answer your homework question?
    Cheers,
    evnafets

  • Problems with symlinks and include directives

    Any files that are included with an include directive from a file that is
              contained in a directory that is reached via a soft link do not work
              (resource not found error) if the link begins with "../".
              directory structure is like this:
              docroot/protected/symlinked_dir/subdir1a/subdir2a
              docroot/protected/symlinked_dir/subdir1b/subdir2b
              if a file in subdir2a tries to include a file in subdir2b then the resource
              is not found.
              however if I copy the symlinked directory over then it works.
              to avoid touching the symlink during the include I changed the structure to:
              docroot/protected/symlinked_dir/dummydir/subdir1a/subdir2a
              docroot/protected/symlinked_dir/dummydir/subdir1b/subdir2b
              The same problem remained. However includes in the same directory and in
              child directories work just fine.
              Is this a known bug in Weblogic or a misconfiguration of the treatment of
              symlinks?
              Thanks,
              Chris Eppstein
              

    Hi, Thanks for looking at the code.
    By messing up I mean the CSS seems to break down a bit.  The navigation moves down, the sidebar moves down and across to the right and the whole page moves across to the right side of the browser and the log in form on the top of the page breaks up and there are gaps on the page where they shouldn't be.
    It only does it in Explorer.
    Thanks again for you help.
    Ben.

  • JSP:Include directive - can I access data?

    Hi,
    I am using the 'include' directive (either jsp:include method or <%@ include.... /> ) to include another jsp page.
    I want the included file to access variables that have been set up in the main page (the one with the include directive in it). I've tried several things, including setting up a Bean class, but nothing seems to work
    Is this possible? I really appreciate any help with this.
    Thanks.

    You cannot use <%@ include ..%> because that is resolved at translation time. <jsp:include /> is resolved dynamically and should give you what you need. In the main page, store references to the bean or other data as request attributes and then retrieve them in the included page.

  • Include directive in iplanet 6.0SP1

    If I have a include directive
    <%@ page contentType="text/xml; charset=UTF-8" %>
    in jsp then it loads up fine in iplanet 6.0SP1 and shows Japanese characters.
    However when I have the same directive in some declare.jsp and include declare.jsp in another jsp file like:
    <%@ include file='/declare.jsp' %>
    then the webserver doesn't take the utf-8 encoding and doesn't process japanese characters correctly.
    Is this bug fixed in later versions of iplanet? Any help is appreciated.
    Thanks
    Ravi

    This doesn't seem to be an error. This is may be because the maximum characters they allow is 4096 and anything above it might be truncated. Check with Sun Support may be they have a better answer.

  • Does c_rt:import act like include directive or tag

    The include directive <%@ include ... will not recompile when the included file changes. The tag <jsp:inlcude will always re-fetch the included file so new content is picked up immediately.
    How do c:import and c_rt:import behave?
    Can someone point me to a good description of the difference between c and c_rt libraries. The short one or two sentence descriptions I've seen don't really say much.
    Thanks,
    -- Frank

    How do c:import and c_rt:import behave?The JSTL <c:import> tag acts like the <jsp:include> tag - it is evaluated at page runtime.
    It uses either a RequestDispatcher.forward (for local resources on the same application server) or the java.net classes to open a URL connection for remote resources.
    Can someone point me to a good description of the difference
    between c and c_rt libraries. The short one or two sentence
    descriptions I've seen don't really say much.The "c_rt" library is only included for historical reasons. If you are using JSTL and EL expressions, you should not be using the "c_rt" library.
    There is only one functional difference between the two, and it only applies to JSP1.2 containers (eg Tomcat 4).
    The "c" tags work only with el expressions: ${expr},
    The "c_rt" tags work only on standard runtime expressions ie <%= expr %>
    In a JSP2.0 containers (eg Tomcat 5), el expressions ARE runtime expressions, and you can use ${expr} or <%= expr %> interchangably with the JSTL1.1 "c" taglib.
    You should only be using the c_rt library if
    - you have a JSP1.2 container
    - you want to use <%= expr %> with one of the JSTL tags.
    Cheers,
    evnafets

  • Include directive with import tags how to

    I mostly the same classes throughout many of my jsp pages. If I use the include directive to import the classes - it doesn't work. What is the proper directive / way / tag to include those tags? Sorry if I am not wording this properly. Here's an example:
    most of my classes use the following classes so I use the @import tag:
    <%@page import="web.urls.DisplayUrls"%>
    <%@page import = "web.beanObjects.display.DisplayPage"%>
    <%@page import="web.db.admin.TypesDbHandler"%>
    <%@page import="web.db.admin.CategoryDbHandler"%>
    I would like to put all of those in one file and only have one line of code so I don't have to cut & paste into every jsp page whenever there's a change:
    <%@include file="/include/imports.jsp"%>
    Unfortunately this isn't working, it's not recognizing the classes...
    Thanks!

    hi,
    since both the files are located in the same folder, why don't you try the following:
    <%@ include file="hello.jsp" %>
    hope this helps

Maybe you are looking for

  • AI file to PDF using Distiller?

    Hello peeps, Easy question I think? Using Distiller [I've got Acrobat 8 Pro], I can create PDF's of EPS's I've created in AI, I can selected any number of files that I want and Distiller produces the PDF's one after another. I do this so I can send l

  • Ask the Expert: Global Site Selector Configuration and Troubleshooting

    Welcome to this Cisco Support Community Ask the Expert conversation. This is an opportunity to learn and ask questions about configuring and troubleshooting the Global Site Selector (GSS) with expert Swati Chopra. GSS devices represent the next gener

  • How to use class.forName

    I am trying to use Class.forName() from a string which is passed to me as argument. Class batchClass = Class.forName(args[1]); A jar file contains the class file for the string received above and I have this jar file in the manifest of my executable

  • Cam doen't work

    Hi i have a pavilion dv6 notebook pc. there is an built in cam and it worked fine in the beginning, now after i have re-installed windowns on my computer it does not work. when i open cyperlink youcam it says that no webcam is connected. i have tried

  • Darwin/BSD login screen?

    After trying to update my Powermac G3 to 10.4.8 (from 10.4.2) I got a message saying the hard drive is almost full and it couldn't install the update. The next time I turned the computer on, it took a long time to start up. When i tried to login in,