I'm learning Servlet now, and I was wondering if it is possible to generate 2 html content at once. I would like to generate an html page which is holding an iframe which also has a content. Is it possible to load 2 html page at once in Servlet?
yes this is completely possible. All you have to do is complete your code for html page which is going to be displayed in the iframe.
Now in servlet you have to write the html code for displaying and call the iframe in servlet.
So when your servlet will run on the server it will be running html code of servlet + iframe (which is displaying another html content)
Related
I have an ASP.NET web app with a standard default.aspx, from within which I need to load a html page from another site (all internal intranet) and pre-populate form input controls on that loaded html page using ASP variables. Specifically, username / pwd on a login form based user details loaded by the aspx from a db. The html page also contains a considerable amount of js (shouldn't directly impact this question though).
Not sure of the best route to approach this. I have considered:
1. Loading the html page in a frame, then somehow manipulating it's DOM from another frame loaded from the aspx.
2. Loading the html during aspx page load or render, then replacing the relevant sections of the html with the new values.
I have had a stab at both approaches and ran into issues. With (2) the resulting HTML isn't recognized as HTML by the browser at all (despite the written response being just the original html relayed from the original site). I can see the HTML source in the browser, but the page itself appears blank.
Answers warmly anticipated. Thank-you.
1.if you want to go wityh iframe
You can easily modify values from communicate between parent window and iframe
from parent to iframe function
document.querySelector('iframe').contentWindow.ChildFunction(33);
from chhild to parentfunction
parent.parentfunction("4rom child")
make a function in iframe that accept an object (from parent) and populate it in.
make a function in parent that accept an object (from child) .
2.how are you "Loading the html during aspx page load or render,"
- ajax or something else?
-making a user controll
both should work fine .
( could you tell how are you loading html ?)(as it should have worked)
I have a site on which Im trying to dynamically update the index.html page, replacing content held in a div, with new html content gathered from an AJAX request to a server holding my other html data. My question is how should I store my html on the server side. Should i create new html files with the content in the body, and try to extract the html from the body? Or Should I try to somehow store just the (div with a few elements inside) fragment I want to use?
You can just store the div and its contents in an external file, load it with ajax, and put the loaded content inside your main html file. Give a look into this exemple to see how to do it.
i need to get some data from external web page (specific text between and tags in this web page source code )
and then show this data in my html.
or get part of html code of another page
then put it in my html page by a button click for examle
This is really hard if it's somebody else's web page due to CORS. However, you should be able to if it's your web site.
Use XMLHttpRequest to get the page content.
Set the container element's .innerHTML to the textual representation of the HTML.
I want to load a .cshtml page inside html page (I dont want to redirect to another page).I tried using
$("#containerdiv").load("folder/Default.cshtml") or $("#containerdiv").load("folder") (html pages load successfully with this method) but when I saw the source code only heading was loaded into containerdiv. Is there other way to do this ?
Try using an iframe. With an iframe you can show the page within the page and view it's code from the same page. Try this
<iframe src="folder/Default.cshtml"></iframe>
Of course, this is only if your not going to anything with server code, which i'm guessing is what you want to do. You can't load server code from an html page because the browser processes the page, not the server.
EDIT:
Try this instead:
<iframe src="FULL_PATH_TO_FOLDER_HERE/folder/Default.cshtml"></iframe>
EDIT 2:
Since that's alot to type everytime, you could also do this, see if it works:
<iframe src="./folder/Default.cshtml"></iframe>
You can't load the cshtml directly, you need to call your controller which should return a partial view of the cshtml file
I am using Servlet to print HTML tag make it a web page.
If i want to highlight some text inside my web page by some background events.
For example if count > 100, then highlight some text.
How can I do that? Any example or tutorial?
Many Thanks
A servlet generates HTML, and sends it to the browser. Once the response has been sent, the HTML code is in the browser, and there is no way for a background task on the server to modify anything in this HTML code.
You'll need some background JavaScript polling in the page (AJAX), that will ask for updates to the server and modify the HTML page accordingly.
Or you can regularly reload the whole page, but it's less efficient and user-friendly.