开发者

doubt in JSP:Include

I have added a code which will include child jsp using jsp:include. The problem i am facing is that the code present in child code开发者_如何学Python is not executing. Below is the code iam using it now

JSPF File:

       <jsp:include page="X.jsp" flush="true">
   </jsp:include>

the above code is present in a file named "A.jspf" which is included in another jsp file named "Parent.jsp".

X.jsp:

      <%@ page import="java.util.*" %>
      <%
         System.out.println("********Child JSP");
       %>

Whenever i execute the parent file "Parent.jsp", all the other contents given in Parent.jsp and A.jspf is displaying except the content present in X.jsp. No error is displaying. Both X.jsp and A.jspf are present in same folder only. Please help me to resolve this issue. Thanks in advance.


If you want the string to be displayed in the client's browser, you should use this instead :

<%@ page import="java.util.*" %>
<%
    out.println("********Child JSP");
%>

System.out.println() will output the string in your webserver's console, whereas out.println() will use the JSP's implicit "out" object that represents the http response's output stream - therefore correctly outputting the given String in the web page.


Try this in your child jsp:

<%="********Child JSP"%>

Use <%=..%> less verbose tag to print on your jsp.

Check this card for quick reference.


If you're modifying the child JSP, modify the parent JSP once and save it. It may be as trivial as adding/removing a space. This results in the servlet getting built again.

When you make changes in a static include, it does not reflect until the parent jsp is compiled again.


<%@ page import="java.util.*" %> <% System.out.println("Child JSP"); %>

If you run the above example you will notice the output from the "System.out.prinltn" on the server log.By itself a scriplet does not generate HTML.Using a scriplet if we want to generate HTML,then we can use a variable called "out".NO need to declare variable as it is declared already.Means it is already predefined for scriplets along with some other variables.

The following Example shows how to the scriplet generates HTML output.

<%@ page import="java.util.*" %> <% out.println("Child JSP"); %>

out is an reference pointing to an class object called javax.servlet.jsp.JSPWriter;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜