Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how do i test ?

Reply
Thread Tools

how do i test ?

 
 
gk
Guest
Posts: n/a
 
      10-07-2006
<%@ include file

<jsp:include


I want to write a code which willl show me the difference of these
two.


i tried , settng a varable x =2 in a.jsp and tried calling this a.jsp
from b.jsp in both the way mentioned above....but it did not show up
any difference.


I am looking for a code snippet which will show up the differece in my
machine.

I am using Eclipse . i am ready to test it.
but not getting the propr to way to test it which will show up
thedifference btwen these two.

whats wrong in my code ?




Thanks

 
Reply With Quote
 
 
 
 
amodpandey@gmail.com
Guest
Posts: n/a
 
      10-07-2006
I believe with <%@ we can include any file, like tag libraries. With
<jsp:include we can include only jsp files, generally used for
templates.
I am not very sure of it.
Pls confirm once you check this.
Thanks

 
Reply With Quote
 
 
 
 
Manish Pandit
Guest
Posts: n/a
 
      10-07-2006
Hi,

You will never notice the difference at the browser level. The
difference is in the generated servlet code of your JSP. In case of the
directive, the included code goes in the calling JSP before it is
translated into a class file. In case of jsp:include, the code that
goes into the servlet is like a *runtime* link. So, if you remove the
incuded JSP after the servlet is generated, in case of directive, it
will work fine, but in case of <jsp:include> it will fail as the
servlet will not be able to find the JSP.

Take a peek at the _jspService() method of the generated servlets for
both cases - you will be able to figure it out right away.

-cheers,
Manish

 
Reply With Quote
 
gk
Guest
Posts: n/a
 
      10-08-2006

Manish Pandit wrote:
> Hi,
>
> You will never notice the difference at the browser level.


but i am getting browser level difference !!

The
> difference is in the generated servlet code of your JSP.


Yes



ok...here i have three files which i did experiment but still not
clear about the concept.

here are the jsp files.

A.jsp
======
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<%

int x = 2;

out.println("hai");



%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

</body>
</html>





B.jsp
======
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>



<%int x=3;

out.println(x);

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<include file="A.jsp"><%out.println(x);%>

</body>
</html>



C.jsp
======
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%int x=3;

out.println(x);

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<jsp:include page="A.jsp" />
</body>
</html>



then , i tried to open in browser

but i found the output as following ...

in I.E:

B.jsp===>outputs 3 3

C.jsp===> 3 hai





>In case of the
> directive, the included code goes in the calling JSP before it is
> translated into a class file.


what do you mean by this ?

well, i am copying the generated code under _jspService method for
the directive

B_jsp.java
-----------------

public void _jspService(HttpServletRequest request, HttpServletResponse
response)
throws java.io.IOException, ServletException {

JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
PageContext _jspx_page_context = null;


try {
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html; charset=ISO-8859-1");
pageContext = _jspxFactory.getPageContext(this, request,
response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;

out.write("\r\n");
out.write(" \r\n");
out.write(" ");
int x=3;
out.println(x);

out.write("\n");
out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01
Transitional//EN\">\n");
out.write("<html>\n");
out.write("<head>\n");
out.write("<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=ISO-8859-1\">\n");
out.write("<title>Insert title here</title>\n");
out.write("</head>\n");
out.write("<body>\n");
out.write("<include file=\"A.jsp\">");
out.println(x);
out.write("\r\n");
out.write("</body>\n");
out.write("</html>");
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (_jspx_page_context != null)
_jspx_page_context.handlePageException(t);
}
} finally {
if (_jspxFactory != null)
_jspxFactory.releasePageContext(_jspx_page_context );
}







In case of jsp:include, the code that
> goes into the servlet is like a *runtime* link.


link ? what link.....yea...i found something like below in the
generated code

org.apache.jasper.runtime.JspRuntimeLibrary.includ e(request, response,
"A.jsp", out, false);


is that you meant ?


here is the full _jspService method for this....

C_jsp.java
----------------
public void _jspService(HttpServletRequest request,
HttpServletResponse response)
throws java.io.IOException, ServletException {

JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
PageContext _jspx_page_context = null;


try {
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html; charset=ISO-8859-1");
pageContext = _jspxFactory.getPageContext(this, request,
response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;

out.write('\n');
int x=3;
out.println(x);

out.write("\r\n");
out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01
Transitional//EN\">\n");
out.write("<html>\n");
out.write("<head>\n");
out.write("<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=ISO-8859-1\">\n");
out.write("<title>Insert title here</title>\n");
out.write("</head>\n");
out.write("<body>\n");
org.apache.jasper.runtime.JspRuntimeLibrary.includ e(request,
response, "A.jsp", out, false);
out.write("\n");
out.write("</body>\n");
out.write("</html>");
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (_jspx_page_context != null)
_jspx_page_context.handlePageException(t);
}
} finally {
if (_jspxFactory != null)
_jspxFactory.releasePageContext(_jspx_page_context );
}


So, if you remove the
> incuded JSP after the servlet is generated, in case of directive, it
> will work fine,


what do you mean by this........its not at all including the jsp file
at all....because you see the print above ..............so there is no
meaning of removing it !

>but in case of <jsp:include> it will fail as the
> servlet will not be able to find the JSP.


thats true.


> Take a peek at the _jspService() method of the generated servlets for
> both cases - you will be able to figure it out right away.


yea.....i have posted it.

in the case of include:file , its not all including the file at all
!!!

and hence i could not verify your comment also .


confused now

> -cheers,
> Manish




thanks

 
Reply With Quote
 
Manish Pandit
Guest
Posts: n/a
 
      10-09-2006
Hi,

You're getting the browser level difference because you are using an
altogether different 'include'. You do realize that using <jsp:include>
rendered

org.apache.jasper.runtime.JspRuntimeLibrary.includ e(request, response,
"A.jsp", out, false);

in the generated code. What this means is, A.jsp is pulled at the run
time. If you'd have used the correct directive <@ include file=>,
instead of the line above, you'd have seen A.jsp copy-pasted in the
parent JSP's java code line by line.

Try using <@include file=> and not <include file=>.

<@ include file = ...> is a *directive* and <jsp:include file=...> is
an *action*.

-cheers,
Manish

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
TEST TEST Test...Blah Blah Blah generalbatguano@pacbell.net Computer Support 2 09-15-2006 03:47 AM
TEST TEST Test...Blah Blah Blah Generalbatguano@pacbell.net Computer Support 6 09-13-2006 01:53 AM
TEST TEST TEST Gazwad Computer Support 2 09-05-2003 07:32 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments