#include<myheadfile.h>和#include"myhedafile.h"的不同

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.
I am currently trying to learn JSP. My question is, at present I used to include the header and footer of the page using:
&%@include file="includes/header.jsp" %&
&%@include file="includes/footer.jsp" %&
But now, I have separated the page content also. So, if user clicks on a page, say products, it has to load the JSP file which is situated in: includes/pages/products.jsp
So, the link to the user is like: &a href="index.jsp?p=products"&Products&/a&.
So, I have to get the p value and display the page based on it.
Following is what I have done so far.
if(request.getParameter("p")!=null)
String p = request.getParameter("p");
&%@include file="includes/page_name.jsp" %&
So, how do I place the value of variable "p" in position of "page_name" ?
Or, is there any other method that I could use ?
In PHP, we could use the include() or include_once(). I am bit stuck in this JSP. :(
Thanks in advance. :)
2,66521533
What you're doing is a static include. A static include is resolved at compile time, and may thus not use a parameter value, which is only known at execution time.
What you need is a dynamic include:
&jsp:include page="..." /&
Note that you should use the JSP EL rather than scriptlets. It also seems that you're implementing a central controller with index.jsp. You should use a servlet to do that instead, and dispatch to the appropriate JSP from this servlet. Or better, use an existing MVC framework like Stripes or Spring MVC.
7,45932851
333k22339524
Did this answer by JB Nizet help you? It's easy to give back.
to get started.
You can use Include Directives
if(request.getParameter("p")!=null)
String p = request.getParameter("p");
&%@include file="&%="includes/" + p +".jsp"%&"%&
or JSP Include Action
if(request.getParameter("p")!=null)
String p = request.getParameter("p");
&jsp:include page="&%="includes/"+p+".jsp"%&"/&
the different is include directive includes a file during the translation phase.
while JSP Include Action includes a file at the time the page is requested
I recommend Spring MVC Framework as your controller to manipulate things.
use url pattern instead of parameter.
instead of
/?p=products
Watch this video
You can use parameters like that
&jsp:include page='&%=p+".jsp"%&'&
&jsp:param name="articleId" value=""/&
&/jsp:include&
in about.jsp you can take the paramter
&%String leftAds = request.getParameter("articleId");%&
1.&a href="index.jsp?p=products"&Products&/a& when user clicks on Products link,you can directly call products.jsp.
I mean u can maintain name of the JSP file same as parameter Value.
if(request.getParameter("p")!=null)
String contextPath="includes/";
String p = request.getParameter("p");
p=p+".jsp";
p=contextPath+p;
&%@include file="&%=p%&" %&
2.you can maintain external resource file with key,value pairs.
like below
: products.jsp
: customers.jsp
you can programatically retrieve the name of JSP file from properies file.
this way you can easily change the name of JSP file
3,56821226
At JSP page translation time, the content of the file given in the include directive is ‘pasted’ as it is, in the place where the JSP include directive is used. Then the source JSP page is converted into a java servlet class. The included file can be a static resource or a JSP page. Generally JSP include directive is used to include header banners and footers.
Syntax for include a jsp file
&%@ include file="relative url"&
&%@include file="page_name.jsp" %&
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledVC++6.0如何实现多文件程序_百度知道
VC++6.0如何实现多文件程序
将file1和file2编译连接file1#include&stdio.h&void main(){ int a=2,b=5,c;c=add(a,b);printf(&%d\n&,c);}file2int add(int x,int y){return x+y;}求大神指教
提问者采纳
首先,必须创建工程,并将文件加入同一工程下;其次,必须有自定义头文件(.h)将多个源文件(.c/.cpp)关联起来,并将函数定义放在头文件中。你的例子,首先两个file增加一行:(在其它包含include之后)#include &myhead.h&并增加一个myhead.h文件到工程,文件内容:int add(int,int);
提问者评价
其他类似问题
为您推荐:
其他1条回答
1)把两个文件都加入工程2)file1 前面添加
extern int add(int x,int y);然后编译运行。
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁文件1中定义了一个类a,文件2中如何用这个类创建一个对象?_百度知道
文件1中定义了一个类a,文件2中如何用这个类创建一个对象?
提问者采纳
先声明一点:你所描述的不是类,而是结构体,这与类是有差别的。struct XXX {} ;
这种形式的叫结构体定义class XXX {}; 这种形式的叫类定义如果你想在多个文件中引用一个自定义的结构体,可以将结构体定义写到一个头文件中,然后在使用这个结构体类型的程序文件中,include这个头文件就可以了。如:// myhead.h
(你的头文件,以下为结构体内容)struct str{
};以下为你的两个文件//file2:
222.cpp#include &myhead.h&
//引用头文件int jia(str ss){ return ss.a+ss.b;}//file1:
111.cpp#include &iostream.h&#include&myhead.h&
//引用自己的头文件void main(){
//定义一个结构体变量sint jia(str ss) ;
//外部函数,在引用前,先声明 s.a=1;s.b=1.5; int c=jia(s); cout&&c&&} 编译时,两个文件链接到一起就可以得到可执行文件了
提问者评价
谢谢。我知道那不是类
来自团队:
其他类似问题
为您推荐:
其他1条回答
你说的太简单了啊,那我就简单的说文件2中#include “文件A”a A;这个A就是a的对象了,当然了,真正应用中我想不会这么简单咯
这样就不行://222.h#include &111.cpp&int jia(str ss){ return ss.a+ss.b;}//111.cpp#include &iostream.h&#include&222.h&struct str{
}s;void main(){ s.a=1;s.b=1.5; int c=jia(s); cout&&c&&}
怎么能这样啊,你把类和函数声明写在头文件中啊,在CPP文件肯定不行啊。头文件中 包括了类 和 一些函数的声明,具体的实现可以在Source 文件中实现头文件也就是 .h文件
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁查看: 9258|回复: 15
#include &avr/io.h&
为什么要这样写?
小弟是新学这个AVR& &用的是atmega16L&&我看到C:\WinAVR\avr\include\avr& & 保存有io.h 因为不太懂include&&平时我们写习惯写#include &io.h& 不知道行不行啊?
为什么要添加一个路径呢???而这个路径又很不清晰呀!我看到里面还有iom16.h 等这样的文件&&是不是一样的调用可以呀&&小弟需要这方面的指导&&相信有巨多的网友应该都不是很清楚··希望讲解一下呵呵···高手们要出来哦····
自己顶上···
AVR有好几种编译环境的
#include &avr/io.h&是GCC编译环境下声明调用头文件
就如你所知道的路径是C:\WinAVR\avr\include\avr
#include&iom16.h&是IAR编译环境下声明调用头文件
不同的编译环境下调用头文件的方法
公益广告:本论坛不得使用、宣传Q群。 有讨论请在论坛里进行。 违者将封锁ID.
回复【2楼】super373
-----------------------------------------------------------------------
但是GCC编译环境下C:\WinAVR\avr\include\avr 文件中也含有iom16.h&&这个文件呀&&我也可以调用呀 内容我没详看&&有何不同呢?
为何要&avr/io.h&这样写呢?加了一个AVR的路径& & 而且这个路径看起来根本无法理解啊········是GCC的固定格式么?那么GCC一般都有什么样的调用格式呢?
公益广告:发表招聘帖子需要缴费,有需要可以联系网站工作人员王小姐:.
默认路径是:C:\WinAVR\avr\include
所以要加avr/io.h,才能找到io.h这个文个。
使用&avr/io.h&让你移植到另外的AVR单片机上更方便,因为include这个文件后,编译器编译时会根据GCC里设定的芯片自动选择相应换头文件!当然如果是atmega16,LZ当然也可以include &avr/iom16.h&了!
另外LZ的长腿美女让我想入非非了!呵呵
公益广告:广告只能发在本论坛的广告区,否则将封锁ID。
这样包含C:\WinAVR\avr\include\avr就可以用&io.h&了
lz 随便是#include &avr/io.h&还是#include &avr/iom.16.h&&&都是对的,
因为io.h包括了他支持的所有avr的头文件路径,编译器编译的时候会自动找到你选用片子的头文件。
编译=》io.h=》iom16.h
编译=》iom16.h
就这个区别!
回复【7楼】mcu2007 努力出国
-----------------------------------------------------------------------
俺们就是不知道#include怎么来执行这个调用路径的····我看到一些头文件都是直接放在那个文件夹下面的&&像KILLC51的那样 ····能请教一些怎么设置#include的调用路径么?
我也是新学avr,用的是AVR Studio+WinAVR,对与编程开头的#include如何写一直很头疼,不知大家开始时是如何解决这个问题的?
,,,,,,,,,,,,,,,,,,,,!@@#
kyughanum 发表于
默认路径是:C:\WinAVR\avr\include
所以要加avr/io.h,才能找到io.h这个文个。
使用让你移植到另外的AVR单 ...
分析得很好,学习了
非常有用,谢谢楼上的网友们
&avr/io.h&就相当于&avr/io.h&吧,&是XML的语法,相当于\&号
阿莫电子论坛, 原"中国电子开发网"Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.
I have 2 HTML files, suppose a.html and b.html. In a.html I want to include b.html.
In JSF I can do it like that:
&ui:include src="b.xhtml" /&
It means that inside a.xhtml file, I can include b.xhtml.
How can we do it in *.html file?
599k15720102306
4,81951229
In my opinion the best solution is:
Using jQuery:
&script src="jquery.js"&&/script&
$(function(){
$("#includedContent").load("b.html");
&div id="includedContent"&&/div&
&p& This is my include file &/p&
Like that i can get a simple and clean solution to my problem.
4,81951229
Did this answer by lolo help you? It's easy to give back.
to get started.
My solution is similar to the one of
above. However, I insert the HTML code via JavaScript's document.write instead of using jQuery:
&h1&Put here your HTML content before insertion of b.js.&/h1&
&script src="b.js"&&/script&
&p&And here whatever content you want afterwards.&/p&
document.write('\
&h1&Add your HTML code here&/h1&\
&p&Notice however, that you have to escape LF's with a '\', just like\
demonstrated in this code listing.\
The reason for me against using jQuery is that jQuery.js is ~90kb in size, and I want to keep the amount of data to load as small as possible.
In order to insert the escape characters without much work, I recommend using a simple regular expression that matches whole lines (^.*$) and adds \ at the end of each line. For example, you could use sed on the command line like this:
sed 's/^.*$/&\\/g;' b.html & escapedB.html
2,70821628
A simple server side include directive to include another file found in the same folder looks like this:
&!--#include virtual="a.html" --&
Checkout HTML5 imports
For example:
&link rel="import" href="/path/to/imports/stuff.html"&
*You can enable the flag by turning on Enable experimental Web Platform features in about:flags in Chrome Canary.
5,65553677
I did met my needs back then, but here's how to do it standards-compliant code:
&!--[if IE]&
&object classid="clsid:F9-11CF-8FD0-00AA00686F13" data="some.html"&
&p&backup content&/p&
&![endif]--&
&!--[if !IE]& &--&
&object type="text/html" data="some.html"&
&p&backup content&/p&
&!--& &![endif]--&
5,30492249
Shameless plug of a library that I wrote the solve this.
&div data-include="/path/to/include.html"&&/div&
The above will take the contents of /path/to/include.html and replace the div with it.
As an alternative, if you have access to the .htaccess file on your server, you can add a simple directive that will allow php to be interpreted on files ending in .html extension.
RemoveHandler .html
AddType application/x-httpd-php .php .html
Now you can use a simple php script to include other files such as:
&?php include('b.html'); ?&
No need for scripts. No need to do any fancy stuff server-side (tho that would probably be a better option)
&iframe src="/path/to/file.html" seamless&&/iframe&
Since old browsers don't support seamless, you should add some css to fix it:
iframe[seamless] {
Keep in mind that for browsers that don't support seamless, if you click a link in the iframe it will make the frame go to that url, not the whole window. A way to get around that is to have all links have target="_parent", tho the browser support is "good enough".
To insert contents of the named file:
&!--#include virtual="filename.htm"--&
53k1675108
The Athari?s answer (the first!) was too much conclusive! Very Good!
But if you would like to pass the name of the page to be included as URL parameter, this post has a very nice solution to be used combined with:
So it becomes something like this:
/a.html?p=b.html
The a.html code now becomes:
&script src="jquery.js"&&/script&
function GetURLParameter(sParam)
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i & sURLVariables. i++)
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
return sParameterName[1];
$(function(){
var pinc = GetURLParameter('p');
$("#includedContent").load(pinc);
&div id="includedContent"&&/div&
It worked very well for me!
I hope have helped :)
Most of the solutions works but they have issue with jquery:
The issue is following code $(document).ready(function () { alert($("#includedContent").text()); } alerts nothing instead of alerting included content.
I write the below code, in my solution you can access to included content in $(document).ready function:
(The key is loading included content synchronously).
index.htm:
&script src="jquery.js"&&/script&
(function ($) {
$.include = function (url) {
async: false,
success: function (result) {
document.write(result);
}(jQuery));
$(document).ready(function () {
alert($("#test").text());
&script&$.include("include.inc");&/script&
include.inc:
&div id="test"&
There is no issue between this solution and jquery.
3,11153777
Following works if html content from some file needs to be included:
For instance, the following line will include the contents of piece_to_include.html at the location where the OBJECT definition occurs.
...text before...
&OBJECT data="file_to_include.html"&
Warning: file_to_include.html could not be included.
...text after...
Reference:
Expanding lolo's answer from above, here is a little more automatisation if you have to include a lot of files:
$(function(){
var includes = $('.include');
jQuery.each(includes, function(){
var file = 'views/' + $(this).data('include') + '.html';
$(this).load(file);
And then to include something in the html:
&div class="include" data-include="header"&&/div&
&div class="include" data-include="footer"&&/div&
Which would include the file views/header.html and views/footer.html
I came to this topic looking for something similar, but a bit different from the problem posed by lolo.
I wanted to construct an HTML page holding an alphabetical menu of links to other pages, and each of the other pages might or might not exist, and the order in which they were created might not be alphabetical (nor even numerical).
Also, like Tafkadasoh, I did not want to bloat the web page with jQuery.
After researching the problem and experimenting for several hours, here is what worked for me, with relevant remarks added:
&!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&
&meta http-equiv="Content-Type" content="text/application/ charset=iso-8859-1"&
&meta name="Author" content="me"&
&meta copyright="Copyright" content= "(C) 2013-present by me" /&
&title&Menu&/title&
&script type="text/javascript"&
var F000, F001, F002, F003, F004, F005, F006, F007, F008, F009,
F010, F011, F012, F013, F014, F015, F016, F017, F018, F019;
var dat = new Array();
var form, script, write, str, tmp, dtno, indx,
The "F000" and similar variables need to exist/be-declared.
Each one will be associated with a different menu item,
so decide on how many items maximum you are likely to need,
when constructing that listing of them.
Here, there are 20.
function initialize()
{ window.name="Menu";
form = document.getElementById('MENU');
for(indx=0; indx&20; indx++)
{ str = "00" +
tmp = str.length - 3;
str = str.substr(tmp);
script = document.createElement('script');
script.type = 'text/javascript';
script.src = str + ".js";
form.appendChild(script);
The for() loop constructs some &script& objects
and associates each one with a different simple file name,
starting with "000.js" and, here, going up to "019.js".
It won't matter which of those files exist or not.
However, for each menu item you want to display on this
page, you will need to ensure that its .js file does exist.
The short function below (inside HTML comment-block) is,
generically, what the content of each one of the .js files looks like:
function F000()
{ return ["Menu Item Name", "./URLofFile.htm", "Description string"];
(Continuing the remarks in the main menu.htm file)
It happens that each call of the form.appendChild() function
will cause the specified .js script-file to be loaded at that time.
However, it takes a bit of time for the JavaScript in the file
to be fully integrated into the web page, so one thing that I tried,
but it didn't work, was to write an "onload" event handler.
The handler was apparently being called before the just-loaded
JavaScript had actually become accessible.
Note that the name of the function in the .js file is the same as one
of the the pre-defined variables like "F000".
When I tried to access
that function without declaring the variable, attempting to use an
"onload" event handler, the JavaScript debugger claimed that the item
was "not available".
This is not something that can be tested-for!
However, "undefined" IS something that CAN be tested-for.
declaring them to exist automatically makes all of them "undefined".
When the system finishes integrating a just-loaded .js script file,
the appropriate variable, like "F000", will become something other
than "undefined".
Thus it doesn't matter which .js files exist or
not, because we can simply test all the "F000"-type variables, and
ignore the ones that are "undefined".
More on that later.
The line below specifies a delay of 2 seconds, before any attempt
is made to access the scripts that were loaded.
That DOES give the
system enough time to fully integrate them into the web page.
(If you have a really long list of menu items, or expect the page
to be loaded by an old/slow computer, a longer delay may be needed.)
window.setTimeout("BuildMenu();", 2000);
//So here is the function that gets called after the 2-second delay
function BuildMenu()
{ dtno = 0;
//index-counter for the "dat" array
for(indx=0; indx&20; indx++)
{ str = "00" +
tmp = str.length - 3;
str = "F" + str.substr(tmp);
tmp = eval(str);
if(tmp != unde) // "unde" is deliberately undefined, for this test
dat[dtno++] = eval(str + "()");
The loop above simply tests each one of the "F000"-type variables, to
see if it is "undefined" or not.
Any actually-defined variable holds
a short function (from the ".js" script-file as previously indicated).
We call the function to get some data for one menu item, and put that
data into an array named "dat".
Below, the array is sorted alphabetically (the default), and the
"dtno" variable lets us know exactly how many menu items we will
be working with.
The loop that follows creates some "&span&" tags,
and the the "innerHTML" property of each one is set to become an
"anchor" or "&a&" tag, for a link to some other web page.
A description
and a "&br /&" tag gets included for each link.
Finally, each new
&span& object is appended to the menu-page's "form" object, and thereby
ends up being inserted into the middle of the overall text on the page.
(For finer control of where you want to put text in a page, consider
placing something like this in the web page at an appropriate place,
as preparation:
&div id="InsertHere"&&/div&
You could then use document.getElementById("InsertHere") to get it into
a variable, for appending of &span& elements, the way a variable named
"form" was used in this example menu page.
Note: You don't have to specify the link in the same way I did
(the type of link specified here only works if JavaScript is enabled).
You are free to use the more-standard "&a&" tag with the "href"
property defined, if you wish.
But whichever way you go,
you need to make sure that any pages being linked actually exist!
dat.sort();
for(indx=0; indx& indx++)
{ write = document.createElement('span');
write.innerHTML = "&a onclick=\"window.open('" + dat[indx][1] +
"', 'Menu');\" style=\"color:#0000" +
"text-decoration:cursor:\"&" +
dat[indx][0] + "&/a& " + dat[indx][2] + "&br /&";
form.appendChild(write);
&body onload="initialize();" style="background-color:#a0a0a0; color:#000000;
font-family:sans- font-size:11"&
&h2&& & & & & & &
& & & & & &MENU
&noscript&&br /&&span style="color:#ff0000;"&
Links here only work if&br /&
your browser's JavaScript&br /&
support is enabled.&/span&&br /&&/noscript&&/h2&
These are the menu items you currently have available:&br /&
&form id="MENU" action="" onsubmit=""&
&!-- Yes, the &form& object starts out completely empty --&
Click any link, and enjoy it as much as you like.&br /&
Then use your browser's BACK button to return to this Menu,&br /&
so you can click a different link for a different thing.&br /&
&small&This file (web page) Copyright (c) 2013-present by me&/small&
If you use some framework like django/bootle, they often ship some template engine.
Let's say you use bottle, and the default template engine is .
And below is the pure html file
$ cat footer.tpl
&hr& &footer&
&p&& stackoverflow, inc 2015&/p& &/footer&
You can include the footer.tpl in you main file, like:
$ cat dashboard.tpl
%include footer
Besides that, you can also pass parameter to your dashborard.tpl.
There is no direct HTML solution for the task for now. Even
(which is permanently in
draft) will not do the thing, because Import != Include and some JS magic will be required anyway.
I recently wrote
that is just for inclusion HTML into HTML, without any complications.
Just place in your a.html
&link data-wi-src="b.html" /&
&!-- ... and somewhere below is ref to the script ... --&
&script src="wm-html-include.js"& &/script&
It is open-source and may give an idea (I hope)
, You can implement common library and just use below code to import any HTML files in one line.
&link rel="import" href="warnings.html"&
You can also try
3,14612227
Well, if all you're wanting to do is put text from a separate file into your page (tags in the text should work, too), you can do this (your text styles on the main page—test.html—should still work):
&p&Start&/p&
&p&Beginning&/p&
&script language="JavaScript" src="sample.js"&&/script&
&p&End&/p&
var data="Here is the imported text!";
document.write(data);
You can always recreate the HTML tags you want yourself, after all. There's need for server-side scripting just to grab text from another file, unless you want to do something more.
Anyway, what I'm starting to use this for is to make it so if I update a description common among lots of HTML files, I only need to update one file to do it (the .js file) instead of every single HTML file that contains the text.
So, in summary, instead of importing an .html file, a simpler solution is to import a .js file with the content of the .html file in a variable (and write the contents to the screen where you call the script).
Thanks for the question.
You can do that with JavaScript's library jQuery like this:
&div class="banner" title="banner.html"&&/div&
$(".banner").each(function(){
var inc=$(this);
$.get(inc.attr("title"), function(data){
inc.replaceWith(data);
Please note that banner.html should be located under the same domain your other pages are in otherwise your webpages will refuse the banner.html file due to
Also, please note that if you load your content with JavaScript, Google will not be able to index it so it's not exactly a good method for SEO reasons.
PHP is a server level scripting language. It can do many things, but one popular use is to include HTML documents inside your pages, much the same as SSI. Like SSI, this is a server level technology. If you are not sure if you have PHP functionality on your website contact your hosting provider.
Here is a simple PHP script you can use to include a snippet of HTML on any PHP-enabled web page:
Save the HTML for the common elements of your site to separate files. For example, your navigation section might be saved as navigation.html or navigation.php.
Use the following PHP code to include that HTML in each page.
&?php require($DOCUMENT_ROOT . "navigation.php"); ?&
Use that same code on every page that you want to include the file.
Make sure to change the higlighted file name to the name and path to your include file.
6,60352355
using jquery u need import library
i recommend you using php
echo"&html&
include "b.html";
echo" &/body&
&div&hi this is ur file :3&div&
protected by
Thank you for your interest in this question.
Because it has attracted low-quality answers, posting an answer now requires 10
on this site.
Would you like to answer one of these
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 lt gt 的文章

 

随机推荐