'include' directive within servlets

Hi all.
I'm trying to build a servlet containing a header wich is
repeated serveral times, so I would like to use the same
directive as in JSP:
<jsp:include page="header.jsp"/>
Is it possible within a servlet?
Best regards.

Thank you for answering.
If try it:
getServletConfig().getServletContext().getRequestDispatcher("/includes/test.html").include(request,response);
I get this error when compiling:
cannot resolve symbol
include (request,response);
^

Similar Messages

  • Can you place a include directive within an if statement?

    I am attempting to include one jsp file if one criteria is met and another jsp file otherwise. Does this work? I can't get it to. My code is below....
    <%@ page import="control.ScreenNames, control.ScreenFlowManager, java.util.*" %>
    <% ScreenFlowManager screenManager = new ScreenFlowManager();
    int screenNum = screenManager.getCurrentScreen(request);
    if (screenNum < 46) {
         System.out.println("< 46");
    %>
         <%@ include file="ScreenDefinitions1.jsp" %>
    <% } else {
         System.out.println("46 or >");
    %>
         <%@ include file="ScreenDefinitions2.jsp" %>
    <% }
         System.out.println("after if");
         request.getSession().setAttribute("screenNum", String.valueOf(screenNum));
    %>

    There are no error messages in the log.
    My main jsp code is as follows:
    <%@ page import="control.ScreenNames, control.ScreenFlowManager, java.util.*" %>
    <%@ taglib uri="WEB-INF/tlds/taglib.tld" prefix="j2ee" %>
    <% ScreenFlowManager screenManager = new ScreenFlowManager();
    int screenNum = screenManager.getCurrentScreen(request);
    request.getSession().setAttribute("screenNum", String.valueOf(screenNum));
    if (screenNum < 46) {
         System.out.println("< 46");
    %>
         <jsp:include page="ScreenDefinitions1.jsp" flush="true" />
    <% } else {
         System.out.println("46 or >");
    %>
         <jsp:include page="ScreenDefinitions2.jsp" flush="true" />
    <% }
         System.out.println("after if");
    %>
    <%@ include file="WEB-INF/window.js" %>
    <html>
    <table border=0 cellPadding=0 cellSpacing=0 height="10%" width="100%">
    <tr align="center">
    <td width="100%"><j2ee:insert template="template" parameter="HtmlTopIndex" /></td></tr></table>
    <table border=0 cellPadding=0 cellSpacing=0 height="80%" width="100%">
    <tr align="center">
    <td width="100%"><j2ee:insert template="template" parameter="HtmlBody" /></td></tr></table>
    <table border=0 cellPadding=0 cellSpacing=0 height="10%" width="100%">
    <tr align="center" valign="bottom">
    <td width="100%"><j2ee:insert template="template" parameter="HtmlFooter" /></td></tr></table></html>
    The included file code is as follows:
    <%@ page import="control.ScreenNames" %>
    <%@ page import="control.ScreenFlowManager" %>
    <% String str_screen = (String)request.getSession().getAttribute("screenNum");
    System.out.println("screen str = " + str_screen);
    int screen = Integer.parseInt(str_screen);
    System.out.println("screen int = " + screen);
    %>
    <j2ee:CreateTemplate template="template" screen="<%=screen%>">
    <j2ee:Screen screen="<%=ScreenNames.SUPPORT_LOGIN_SCREEN%>">
    <j2ee:Parameter parameter="HtmlTitle" value="eMoneyMail Support Sign In" direct="true"/>
    <j2ee:Parameter parameter="HtmlTopIndex" value="/login.jsp" direct="false"/>
    </j2ee:Screen>
    <j2ee:Screen screen="<%=ScreenNames.SUPPORT_MAIN_SCREEN%>">
    <j2ee:Parameter parameter="HtmlTitle" value="Welcome to eMoneyMail Support!" direct="true"/>
    <j2ee:Parameter parameter="HtmlTopIndex" value="/head.jsp" direct="false"/>
    <j2ee:Parameter parameter="HtmlBody" value="/SupportMain.jsp" direct="false"/>
    <j2ee:Parameter parameter="HtmlFooter" value="/foot.jsp" direct="false"/>
    </j2ee:Screen>
    My log file is as follows:
    < 46
    screen str = 1
    screen int = 1
    after if
    Thanks.

  • 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

  • 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?

  • 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

  • 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

  • Creation of PD Profiles directly within Production environment.

    The company I work for has recently upgraded all SAP environments, including where HR resides.  Prior to the upgrade, we were able to create PD profiles directly within PRD, but now we are no longer since upgrading via OOSP which updates some of the T77* tables.   
    Does anyone know what type of config setting changes are required to allow us to return to being able to config PD profiles with PRD again?   
    Thanks in advance!
    HIMASON

    I had the same problem and this is the solution I was given.
    To make the OOSP table maintainable in production, in the production system go into the IMG path: Personnel Management> Personnel Development > Basic Settings > Authorization Management > Structural Authorizations the position cursor on the text ‘Maintain Structural Authorization Profiles’
    Then go to ‘Edit’ on the menu then ‘Display IMG Activity’.
    Click on the tab ‘Maint.Objects’
    Double click on the T77PQ
    The Current Settings box needs to be ticked.
    But first it looks like the system has to be set to modifiable (this is in table T000) OR do it in DEV and transport it through, - you need a developers key to do this.

  • Include directive to include a JSP file from a JAR file

    I have an Eclipse project in which I have placed a JSP file in the package structure with the rest of my code. This is in fact only a code snippet page, not a full blown JSP file.
    I have a second project that is a Dynamic Web Project in Eclipse that incorporates the first project as a JAR in the /WEB-INF/lib directory.
    In this project I have a JSP file and I want to include the JSP file embedded in that JAR file.
    How do I do that?
    I'm thinking the only real solution is to rewrite the snippet portion as a custom tag.

    The JSP fragment page in question is actually a HTML form page. It is a form to be used specifically by a particular servlet. That is why they are "bundled" together in the same project, in the same package structure.
    I have multiple web applications that I want to include that form/servlet, so it gets added to these projects in the /WEB-INF/lib folder as a JAR library. But I don't want to recreate the form over and over again for each application. It would be nice if I could write a JSP page that wraps the fragment using an include directive to bring that fragment into the new page.
    So to do that with any other fragment I would write:
    <%@ include file="/WEB-INF/jsp/SOME_FORM.jsp" %>
    which works great if my fragment page is in the /WEB-INF/jsp subfolder. But if I want to access the JSP fragment as it is bundled in a JAR file, this:
    <%@ include file="/WEB-INF/lib/FORM.jar/SOME_FORM.jsp" %>
    doesn't work so good. It's just all wrong.
    I was wondering how I could just write one include statement to get what I need. There are work-arounds galore, but I thought if I could get this working it would be the simplest solution overall.

  • WEB.SHOW_DOCUMENT . Publish reports character mode directly within browser!

    hello!
    I'm having the problem.
    When I want to publish reports character mode directly within browser!
    The code is as follows!
    SET_REPORT_OBJECT_PROPERTY(repid, REPORT_EXECUTION_MODE, RUNTIME);
      SET_REPORT_OBJECT_PROPERTY(repid, REPORT_COMM_MODE, SYNCHRONOUS);
      SET_REPORT_OBJECT_PROPERTY(repid, REPORT_DESTYPE,  FILE);
      SET_REPORT_OBJECT_PROPERTY(repid, REPORT_DESFORMAT, '');
      SET_REPORT_OBJECT_PROPERTY(repid, REPORT_SERVER, server );
      v_rep := RUN_REPORT_OBJECT(reportFile,mparamlist_id);
      rep_status := REPORT_OBJECT_STATUS(v_rep);
         if rep_status = 'FINISHED' then
            vjob_id :=substr(v_rep,length(server)+2,length(v_rep));
      WEB.SHOW_DOCUMENT('../reports/rwservlet/getjobid'||vjob_id||'?server='||server,'_blank');
         else
      message('Fail to create Report!');
         end if;
    The report is generated,
    But it does not open directly in browser!
    The browser will download a file without extension / format, with the name 'getjobid38'!
    When I change the code to 'TXT'
    WEB.SHOW_DOCUMENT('../reports/rwservlet/getjobid'||vjob_id||'.txt?server='||servidor,'_blank');
    The following error is returned:
    rep-50003 the command line is invalid: getjobid38.txt
    Already grateful!

    working with forms 11gR2 (11.1.2.1)

  • 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.

  • View remarks of an approver directly within the "Messages / Alerts" window.

    Hi,
    Here is a need from some customers.  It makes snes to ask for this functionality... It works from one side (requestor side) but not for the other (approver side)...  Could this enhancement be implemented in future patches / versions ?
    Thanks,
    Luce
    Version: 2005-SP1-PL36
    Description of requirements (Please provide a detailed description) :
    Be able to view the remarks of an approver directly within the u201CMessages / alertsu201D overview.  Identical behavior as it is for the approver when he receives a request for approval.
    Valid as of Date that this legal requirement is applicable) :
    Business needs (Please describe the impact on your business, if the functionality is not realized):
    With no view of the remarks coming from the approver, we can miss important information from the approver. ..  And to have to open a u201Cdecision report u201C in order to view the remarks that the approver has written, that makes no sense and in addition, Itu2019s time consuming ! 
    Examples (Please describe a typical example, how the functionality should work):
    Sophie wants to create a sales order, but she needs an approval to do it.  So, when pressing the u201CAddu201D button in the Sales order window, the system launches the approval process.  She writes in the REMARKS field u201CNeed your approval ASAP pleaseu201D.
    Bill will be the approver of the sales order, so he receives the request for document approval in his u201CMessages / Alerts overviewu201D window. 
    Bill clicks on the u201CRequest for document approvalu201D in the u201CMessages / Alerts Overviewu201D window.  By doing that, he sees in the middle part of the u201CMessages / Alerts Overviewu201D window that Sophie wrote a remark as this :`u201CNeed your approval ASAP pleaseu201D.   By knowing this, Bill will open the approval window and will take his decision immediately.
    He writes a remark to Sophie as this : u201CPlease, donu2019t create any sales order for this customer before next week because we donu2019t know if they will pay us soon enoughu201D, he selects u201CApproveu201D and sends his approval to Sophie.
    Sophie can see that Bill has approved her sales order in the u201CMessages / Alerts Overviewu201D window. 
    By clicking on the u201CDocument generation approvedu201D, Sophie can see very quickly, in the middle part of the u201CMessages / Alerts Overviewu201D window, that Bill gave her the instruction to avoid sales order creation for this customer in the upcoming week.  So she wonu2019t try to create any sales order anymore for this partner.
    Current Workaround (Please describe the workarounds you are using at the moment):
    Open the u201CApproval decision reportu201D and filter to find the appropriate document approval, in order to view the remarks of the approver.   This is a big time consumingu2026
    Proposed solution (Please suggest how the new functionality should work):
    Itu2019s simple !!  Why couldnu2019t you just simply standardize the way things work and do as it works for the approver side ?  The approver can see / read the remarks coming from the requestor in the u201CMessages / Alerts overviewu201D window !   It would be so easy to do the same thing on requestor side !  It would be nice to be able to see / read the remarks coming from the approver in the u201CMessages / Alerts overviewu201D window !

    I don't know if someone will take care of this... And I have to close a question since I want to post a new thread... So I have no choice, I must close one of my questions...

  • 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.

  • 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.

Maybe you are looking for

  • Unusual problem in 5800 while sending a message to...

    hi recently i found a strange problem in my phone 5800 xpress music.Whenever i send a message through groups or if i select and send it to like 10 ppl ,suddenly a error message pops up saying messaging already in use.It happens till the message is se

  • Where is the "Tools" Menu item in FF Beta 4?

    I am trying to set my home page and specify which pages open when I start Firefox. I dislike that the pages I had open last time automatically open up. Sometimes I close FF to get rid of unwanted pages and it annoys me that they all open back up when

  • External hierarchy from R/3 table

    Hi, We need to have a hierarchy in BW from R/3 but it does not have a standard extractor. i need more details regarding how to create External Hierarchy in BW , how to pull the data from R/3 table , Should i download to Flatfild and then upload ?? Th

  • 10g DBA OCP requirements

    Dear All, please give me an advice in the following thread: Oracle 10g OCP DBA Hands-on Course ? (People having OCP certification can help for sure.) Thank You! Franky

  • ACR 4.3  xmp problem

    Sorry to repeat this request but its very important to me and I've had no replies on this topic. Am I to assume its just me and everyone thinks I should be aware of this situation or is it a problem no one has encountered? It would be very simple for