473,383 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Problem with jsp:include Tag

dmjpro
2,476 2GB
Expand|Select|Wrap|Line Numbers
  1. <jsp:include flush="true" page="test_include.jsp?a=<%=java_variable%>&b=debasis&c=jana" />
  2.  
But the value of Java variable is not getting passed to the include page.
If i pass plain hard coded value then it's getting passed.
What should i be doing?
Feb 10 '09 #1
4 3195
JosAH
11,448 Expert 8TB
@dmjpro
The several tags <% ... %> and <%= ... %> and <%@ ... %> and <%! ... %> don't nest properly in JSP; those tags don't change it a bit; imho that entire JSP syntax stinks. I find JSPs just a hack that got out of hand. You've just met one of its quircks.

kind regards,

Jos
Feb 10 '09 #2
dmjpro
2,476 2GB
Actually this thing can be achieved by using <jsp:param name="param_name" value="<%=expression%>"/>.
Feb 10 '09 #3
JosAH
11,448 Expert 8TB
@dmjpro
See? Another crappy solution because of that silly JSP syntax. Did you just find this hack?

kind regards,

Jos
Feb 10 '09 #4
chaarmann
785 Expert 512MB
There is a better solution. The jsp-tags aren't very flexible, and you can always do the same with pure Java. if you don't know how to do it in Java, just look at the corresponding java file that is the compiled jsp-file, placed in "work" directory of apache. There you can see how jasper translated your jsp-directives into java-code.

My problem was similar to yours. Here is my solution:
What for example if you want to have different menus on your webpages and the jsp-file for the menu (along with different parameters if needed) should be passed in runtime? Let's say I call "http://myServer/fullPage.jsp?topMenu=myTop.jsp"

here is fullPage.jsp:
Expand|Select|Wrap|Line Numbers
  1. <%!
  2. private boolean includeIfExisting(String pageName, PageContext pageContext)
  3. throws Exception
  4. {
  5.     HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
  6.     String url = request.getParameter(pageName);
  7.     if (url != null)
  8.     {
  9.         if (Log.isDebug()) Log.debug("before including " + pageName + " =" + url);
  10.         pageContext.include(url);
  11.         if (Log.isDebug()) Log.debug("after including " + pageName + " =" + url);
  12.  
  13.         return true;
  14.     }
  15.     return false;
  16. }
  17. %>
  18. ...
  19. <div id=menu>
  20. <%
  21.     includeIfExisting("topMenu", pageContext);
  22. %>
  23. </div>
  24. ...
Feb 12 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Muzzy | last post by:
Hello, I just have a problem with following: i have a .jsp file containing a static html menu and a table cell where i need to include a servlet call result. Servlet is called with the same...
1
by: Odd-R. | last post by:
I have a servlet that connects to a database, and gets some data that I want to present on a jsp page. The servlet is located in a folder called servlets, and works fine when invoced alone....
1
by: KS | last post by:
I write my html pages as .jsp files (java server pages). The final result when the page is rendered in the browser, and I do a view source, is nothing less the normal HTML codes. The problem is I...
7
by: for.fun | last post by:
Hi everybody, I have the following problem : B class need A::MyEnum type and A class need B::MyEnum type. In both case, the class type is incomplete so it is obvious that the ::MyEnum can not...
1
by: Pablo | last post by:
Dear all, I have a website where I need to fill its contents after retrieving some data from another system (not a DB, but you can think like it). I know the nature of the data, but the order...
1
by: sallawari | last post by:
i got error while import a jsp File (ie).. <jsp:include page="<%=ctxName%>/run?__report=/content/report<%=reportObj.getReport(reportObj.REPORT_TYPE_BAR_GRAPH)%>" /> Error :.. ...
3
by: mattmao | last post by:
Hello everyone. My project is to build a online video retailer system (of course just simulation, not for real). I have been thinking about this for days and already made some researches....
2
by: gaya3 | last post by:
Hi All, is it possible to include jsp page in jspx file? I'm having as follows... in jspx file JSPX file: <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"...
5
by: lalia | last post by:
I have a xyz.jsp page has a submit button This page is included in another jsp file by <jsp:include page="/../xyz.jsp"/> tag. when i click that button the whole main page get submit where i only...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.