Dynamic include file in JSP page

<span class="value">Hi
i have index.jsp , this page can include jsp
pages dynamically by passing the name of the page to be included to the
index page with out .jsp , so if i want to include page "code.jsp" i
put: .../index.jsp?page=code , this have to include code.jsp page
i made the following code , but it did not find the file
so can any one help plz ?
        String pg=request.getParameter("page");
        if( pg!= null && ! "".equals(pg)){
                File f=new File(request.getParameter("page")+".jsp");
                if(f.exists()){
                        out.print("file exist");
                        %>
                        <jsp:include page="<%=request.getParameter("page")+".jsp" %>" />
        <%
                }else{
                        out.print("file not exist");
     

What does the file existing or not really have to do with it?
You can try it like this:
String pg=request.getParameter("page");
        if( pg!= null && ! "".equals(pg)){
                String webPath = pg + " .jsp";
                String realPath = request.getRealPath(webPath);
                File f=new File(realPath);
                if(f.exists()){
                        out.print("file exist");
                        %>
                        <jsp:include page="<%= webPath %>" />
        <%
                }else{
                        out.print("file not exist");
        }Alternatively you could try using a request dispatcher:
RequestDispatcher rd = request.getRequestDispatcher(webPath);
if (rd == null){
  // doesn't exist
}

Similar Messages

  • How can i render a dynamic html file in jsp page

    Hi everybody,
    i am trying to render a dynamic html file in jsp page with the result of querying a database.
    The response of the query is a xml document. And i have a stylesheet to transfer it to html.
    How can i render the html in a jsp file?

    I am using below code for HTML files
    private var appFile:String="index.html";
    if (StageWebView.isSupported)
                        currentState = "normal";
                        webView.stage = stage;
                        webView.viewPort = new Rectangle( 10, 130, (stage.stageWidth)-20, 750 );
                        var fPath:String = new File(new File("app:/assets/html/aboutus/"+ appFile).nativePath).url; 
                        webView.loadURL(fPath);
                        addEventListener(ViewNavigatorEvent.REMOVING,onRemove);
                    else {
                        currentState = "unsupported";
                        lblSupport.text = "StageWebView feature not supported";
    above code is working fine for me.

  • Include file in jsp not working

    Hi ,
    I have an include file statement in my jsp file which is not working. Not getting any error message either only the page is displayed without the jsp file included.
    My include code looks like this :
    <%@ include file ="Includes/hello.jsp" %>Also i tried including an html file or an image in the same place neither of the two displayed.
    <!--#include virtual="includes/footer.html" -->
    My jsp file is hosted on IIS

    nb123 wrote:My jsp file is hosted on IIS
    Hi ,
    I have an include file statement in my jsp file which is not working. Not getting any error message either only the page is displayed without the jsp file included.
    My include code looks like this :
    <%@ include file ="Includes/hello.jsp" %>Also i tried including an html file or an image in the same place neither of the two displayed.
    <!--#include virtual="includes/footer.html" -->
    My jsp file is hosted on IIS
    Check the path you've specified. It may well be;
    <%@include file="hello.jsp" %>or
    <%@include file="/Includes/hello.jsp" %>

  • How can i call java class file in jsp page

    Hai,
    i wants to call .class file in jsp page.
    my class file is in C:\jsdk\bin.
    Thanks

    I'm not entirely sure what you mean by "calling a class file", but I'm going to assume that you want to do something like the following in your page:
    <%
    MyClass myClass = new MyClass();
    myClass.someMethod();
    %>etc
    If that's the case, then all you have to do is make sure that the class is in the servlet engine's classpath. You'll probably also need to include an appropriate import statement at the top of the page.
    Hope that helps.

  • Error when using %@ include file="/test.jsp"%&

    UsingNitrox version 2.1 M3 (build 419 06022005):
    with jdk version: 1.5.0_03 and Tomcat 5.5.9
    This is the error :cry: when using <%@ include file="/test.jsp"%> in jsp:
    Severity     2
    The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files (test.jsp)
    It used to work in previuos version of Nitrox. I can't use struts tiles because the tiles content is dynamic (run time) and I need it to be static (at compile time).
    Have you encountered this problem? What is the fix? Nitrox bug?
    I need your help please,
    Alberto

    M7,
    I found the problem :wink: . In the java Build path having the default (ALL) is not picking up the content of the package. I had to use add multiple and include all the folders and subfolders (many L) in my packages. After that I added *.java and *.properties to select all the java files. Now it is working. I assume this is a bug in Nitrox. The default ALL should include the all the files in the path.
    Thanks,
    Alberto

  • Pls tell me use %@ include file="myfile.jsp"% with endcoding UTF-8??

    My jsp pages use some endcoding as UTF-8.
              When I use <%@ include file="myfile.jsp"%> endcoding lose format UTF-8. But
              if I use <jsp:forward page="myfile.jsp"/> it work fine.
              Pls tell me use <%@include %>
              (I use Jbuilder 6 and weblogic server 6.1)
              Thanks .
              

    From http://java.sun.com/products/jsp/tags/12/syntaxref1214.html#8828 (emphasis mine):
    page="{ relativeURL | <%= expression %> }"
    The relative URL that locates the resource to be included, or an expression that evaluates to a String equivalent to the relative URL.
    The relative URL looks like a pathname--it cannot contain a protocol name, port number, or domain name. The URL can be absolute or relative to the current JSP page. If it is absolute (beginning with a /), the pathname is resolved by your web or application server.
    You could use a servlet in your "path" attribute and have that servlet read and return the page from a different server; there are ways to do what you want, but <jsp:include> isn't one of them.

  • Forwarding to an xml file from jsp page

    hi
    i am subhash. i have problem in forwarding an xml file from jsp page.
    i have a jsp page in which i have a button. upon click, its form method is triggered and the action is set to "serverpage.jsp". In that jsp page i have to move to an xml file. I would like u to send a sample code also for the same.
    Thank You,
    Subhash..

    Refer to the Generating XML from JSP section.
    http://java.sun.com/developer/technicalArticles/xml/WebAppDev2/

  • Urgent: Including a dynamically creted file in JSP

    Hi all,
    My problem structure is like this
    In my JSP page i am haiving one String which contains a source code of the other JSP. When i use out.println to print the code it works fine for all the HTML tags, but the JSP tags don't get processed. The reason behind this could be that the string is being printed after JSP translation phase. Now my requirement is the same String which contains some JSP code should work like normal JSP.
    I tried following solution, which is not working
    1.In the same JSP file i created a temparory xyz.jsp file with that String contents
    2.And i am trying to include that file using <jsp:include page="xyz.jsp/>
    3.I am using Weblogic 7.0, So in order to deploy the application i have to create .ear file and then proceed.
    4.The temperory file xyz.jsp is being creted in the domain folder of the server. which is out of the web context
    5.Now i am not able to access that temperory file, since it is not in the context.
    I am confused about the approch itself, because it involves IO and could make the application slow.
    Is there any other way to solve this problem ??
    Thanks in advance
    --Bhupendra Mahajan

    I know that this is the "New To Java Technology" forum, so my suggestion may be more than you want to tackle, but how about custom JSP tags?
    http://java.sun.com/developer/Books/javaserverpages/cservletsjsp/chapter14.pdf
    They allow their body content to be manipulated / evaluated. I don't know if they're appropriate in this case, since I haven't seen your code and don't know specifically what you're trying to evaluate, but I thought it would be worth it to suggest them.

  • Include xml file in jsp page

    hi,
    i just would like to include an xml file and his xsl file in a jsp page.
    i know we can do it in asp like that :
    <%
    //load the xml file
    var source = Server.CreateObjetc("Microsoft.XMLDOM");
    source.load(Server.MapPath("toto.xml"));
    //load the associated xsl file
    var style = Server.CreateObject("Microsoft.XMLDOM");
    style.load(Server.MapPath("toto.xsl"));
    //transform the source document
    var result = source.transformNode(style);
    Response.Write(result);
    %>
    i want exactly do the same in jsp
    does anyone know how to do?

    where is the big deal? there are many posts answering this in the forum.
    here is a possibility:
    <%@page contentType="text/html;charset=utf-8"%>
    <%@page import="javax.xml.transform.*,javax.xml.transform.stream.*" %><%
    Templates myTemplates = TransformerFactory.newInstance().newTemplates(new StreamSource(new File("whatever.xsl")));
    Transformer transformer = myTemplates.newTransformer();
    StringWriter sw = new StringWriter();
    transformer.transform(new StreamSource(new File("whatever.xsl")), new StreamResult(sw));
    out.print(sw.toString());
    %>

  • How to include external js file in jsp page??

    Hiii...i am new bie in jdeveloper....
    and trying to add external js file to a jsp page...
    the adress of javascript file is [ Web Content/WEB-INF/jsp/script/test.js ]
    adress of jsp page is [ Web Content/WEB-INF/jsp/WelcomePage.jsp ]
    so what source address of js file i have to give in jsp page.....

    Hi,
    In order for the jsp page to get the js file, it has to be accessible via an http request, and files in WEB-INF aren't. You'll have to put the js file in a different location or provide another way to get the file, such as via a servlet request.
    This is the way to do it. I don't see a use case in that adding a JS file to WEB-IF provids any benefit as the sources could be looked up from the browser anyway. So if your intention is to secure the JS sources, this wont work.
    Frank

  • CHART BUILDER ERROR WHEN TRYING TO GENERATE DYNAMIC CHARTS ON A JSP PAGE

    I'm working with J Develop 9.03 on Windows 2000 Professional Edition.
    I'm using the JSP demo files provided with Oracle Chart Builder to generate
    dynamic charts. The user specifies the query parameters, including the date
    range and the query results are returned by means of a line chart (with date on
    the x axis and values on the y axis).
    When trying to compile the project I get the following error messages:
    Error(165,2): class FileOutputStream not found in class _graph
    Error(170,5): class File not found in class _graph
    Error(176,4): exception java.io.IOException is never thrown in the
    corresponding try block
    I checked to see that the chartbuilder library (chartbuilder.jar) files are
    loaded into the project library. It's unusual that the class is not being
    found. I don't understand why. I developed my project using the following steps:
    1. Unzipped Chart Builder installation files into c:\Oraclechartbuilder
    2. Loaded chartbuilder class library
    c:\Oraclechartbuilder\chartbuilder\lib\chartbuilder.jar into J Developer class
    path (by selecting <Project Settings> <Paths> and browsing to the
    chartbuilder.jar file).
    3. Created a new JSP page in J Developer (graph.jsp)
    4. Copied JSP code syntax from the Word Pad demo file and pasted into graph.jsp
    5. Changed the DB connection parameters and static directory location on the
    JSP page.
    6. Compiled the project and received the above errors.
    I would like to know why the classes are not being found and how to fix the problem. Thanks, Jaafar

    Hi mshah101,
    This can happen if the applet is compiled using an higher version of java and the browser is pointing to an older version (even if minor version number is higher)

  • Problem in opening pdf  or fdf  File in JSP page through firefox in Linux

    Hi,
    In my Webapplication , i have given link to FDF document available in server in a JSP page on click of which the corresponding FDF document should open in a new browser.
    Consider the location of FDF file in my server is
    ServerIP/MS/RDTEST/RDTEST-D-08-10245.fdf
    In my JSP link to FDF file is provided as follows.
    newpath="smb://"+username+":"+password+"@"+serverip+"/MS/RDTEST/RDTEST-D-08-10245.fdf" ;
    <a class ="one1" href="<%=newpath%>" target="dynamic" > RDTEST-D-08-10245 </a>My Requirement is When i click on the link it should open the corresponding fdf file in the browser by following the link provided.
    But it is not working if i try in this way.
    Can anybody suggest how to proceed with this issue.
    Any other ways are there to open fdf file exisitng in server in Firefox in A Linux machine.
    What settings to be made in firefox to support FDF or PDF features.
    What prerequisites needed in Linux to enable FDF or PDF features.
    I have Adobe Acrobat professional 5.0 installed in my Linux machine.
    Thanks in advance.

    Is your problem
    -. That a new browser window doesn't open?
    Solution: [Lookup the 'target' attribute|http://www.w3schools.com/HTML/html_links.asp]
    - That your file content isn't streaming to the browser?
    Solution: Your code assumes the browser understands and supports samba. This isn't always the case (IE for example). And you're providing a direct link to your file with the username and password - security concerns as well as possible portability issues. You'd be better off writing a [file servlet to download your files|http://www.google.com/search?q=file+download+servlet]

  • How to embad a movie file in jsp page.

    I want to run a movie file in my jsp page.
    please provide the code how to do this.
    thanks
    uttam

    Hi,
    so what source address of js file i have to give in jsp page.....in your case you can use below include command
    <jsp:include page="script/test.js" /> // here test.js is your .js file nameGenerally we need to place all jsp and js files under "jdevhome\jdev\myhtml\OA_HTML". In this case you can use
    <jsp:include page="test.js" /> // here test.js is your .js file nameor
    <%@include file="test.js" %>  // here test.js is your .js file nameregards,
    Anand

  • JAR file an JSP pages

    How do i include a JAR file in my JSP page?

    How do i include a JAR file in my JSP page?depends on what you are trying to do. If you want to access the class files in the jars for use in the jsp, just put the jar in the server's classpath. In tomcat, that would be <INSTALL_HOME>\common\lib.
    Cheers,
    ram.

  • Dynamic  include file question

    I need to use dynamically generated file names in my <%@ include file="" %> directive.
    I am using objects (such as database connection) in the files included which I created in my base JSP file. For this reason, I cannot use the jsp:include tag (since these objects are not defined in these files, the servlet doesn't compile).
    Are there any ways of using these dynamic names in this directive?

    If you are dymically generating the file, then store it in a string and then include it?
    String dynamicallyGeneratedFileName = (however you are generating the file name);
    <%@ include file="<%=dynamicallyGeneratedFileName%>" %>

Maybe you are looking for

  • How to select multiple iphoto card design under one shipment?

    Hi All, I have designed 4 different invitation cards. I wonder if i can multiple select 4 of these design under one shipment, so i can save a lot of shipping cost. Please share your experiences. Thanks. Regards, Wymond

  • Freezing cursor problem

    I have a Waveform Chart with a moving cursor where the x-axis is time and the y-axis represents various analyzer readings. At random times, the cursor leaves a marker at a specific point but also continues its regular movement across the chart. This

  • ITunes 10 is a massive resource hog

    After updating to iTunes 10, I noticed that my computer was running considerably slower than usual. iTunes 9 used about 2% system resources when playing music and minimized to the dock. So after checking Activity Monitor, I discovered that iTunes 10,

  • CAREER / SUCCESSION PLANNING

    Hi Everyone, Can Any Body Help Me How to Start and Work with Career / Succession Planning Module NEED MORE DETAILS/ GUIDANCE LIKE: <b>  - what to be taken care while preparing blue print (for Career / Succession Planning)   - Configuration details /

  • How to execute a function periodically

    Hi , I have been working on a multithreaded application where i require that a function is called periodically after every 10 seconds. Please suggest. Thanks