adding .js.map files to page header in apache wicket-6.x - java

after adding a javascript file to my Wicket panel like so
renderJsHeaderItem(response, "js/jquery/dist/jquery.min.js");
I get an error in the javascript console along the lines of
GET http://localhost:9080/js/jquery/dist/jquery.min.map 404 (Not Found)
How would I add the map file to my Panel code? (same question for css.map)
Thanks!

Wicket 6 comes with jquery so you dont have to add it again. You should add javascript and css files in your base page, that way all of the pages that extend the base page will have these files available and you only have to add them in one file.
To add javascript or css in renderHead use:
JavaScriptHeaderItem.forUrl("js/jquery/dist/jquery.min.js");
CssHeaderItem.forUrl("css/style.css");
Example:
#Override
public void renderHead(IHeaderResponse response) {
response.render(JavaScriptHeaderItem.forUrl("js/jquery/dist/jquery.min.js"));
response.render(CssHeaderItem.forUrl("css/style.css"));
}

Related

How to use jsp include tag in javascript

I have created on page that page has one button as the user click on that button new row inserted with input field and drop down box. i have to show the dynamic value in drop down which is using from XMl. For that i have created one page getdata.jsp which return value1value2.
I have included that page in index.html where i want to show drop down.
but problem is when i trying to use inculde tag in java script that is no working.
I have to include this page in my index.jsp so that drop down will create dynamical.
I want to include my page here
cell4.innerHTML ="<%#include file="getdata.jsp" %>";
How can i achieve this. Thanks
A couple thoughts for you.
This is usually done with an ajax request rather than a direct include like this. This allows you to refresh the data at any time and keeps better separation between your server side and client side code. It looks something like this:
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
cell4.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","getdata.jsp",true);
xmlhttp.send();
Alternatively if you really want to include the jsp file like this you'll need to include it from a jsp file as well. Currently your script is most likely in a ".js" file. Your webserver will not process this like a jsp file and your include will be ignored. You can change this to a ".jsp" and update the script tag's src attribute. I don't recommend this approach however.

Adding javascript tags to vaadin UI head

When you create a vaadin 7 project in eclipse, execution begins in the UI class.
I was wondering if there was some way to add a javascript tag such as this to the header of the html page generated when executing a vaadin project.
<script src="amcharts.js"/>
Here is a page that describe how to do this.
You can write your own code into the modifyBootstrapPage method:
#Override
public void modifyBootstrapPage(BootstrapPageResponse response) {
response.getDocument().head().append("<script src=\"amcharts.js\"/>");
}
You can also write own component which use JavaScript. Look into that chapter in the official Vaadin book.

How to map server response retrieved in jsp to an iFrame

I'm using struts2 framework(java/js/html/css combo) for my webapp. I am reading a text file from server and I want to write the response to an iFrame present in the same jsp.
Flow:
(1) On click of a link, I pass the relative URL of the text file to jsp.
(2) When the jsp page loads, the java code in the jsp reads the file from server.
(3) Now this response has to be written to an iFrame present in the same jsp file
Can anyone plz help me in writing such response to an iFrame?
Thanks in advance :)
[code not tested, only a demostration of the concept]
here's some very rough idea as to how to fix your code, they definitly not the best but they should be enough to help you understand the concept.
However I'd still recommend going over the whole concept and maybe come up with a more efficent way to do what you need.
if you insist on using iframe, you need to make use of 2 seperate jsp as W3C says in "Implementing HTML Frames":
Any frame that attempts to assign as its SRC a URL used by any of its ancestors is treated as if it has no SRC URL at all (basically a blank frame).
so you'll need 2 jsp, the first one is basically what you have but the the src of the iframe changed to:
<iframe scrolling="yes" width="80%" height="200" src="second.jsp?content=<%=all%>" name="imgbox" id="imgbox">
and the second one will be something like :
<html><body><%= request.getAttribute("content") %></body></html>
From the code you've shown you forced a "content update" on the iframe by using javascript. The proper/usual way to update an iframe is to provide different input parameter to the second jsp and let it update it for you.
Finally, I'd recommend using JSTL as much as possible instead of scriptlets. It is much cleaner.
What you need to do is set the src attribute of the IFRAME to the jsp url when your link is clicked. Another way to do it is doing something like this:
<iframe src="" name="iframe_a"></iframe>
<p>W3Schools.com</p>
with the correct parameters of course

Servlet response in different .htm file

How to show response or output generated by servlet using separate .html file designed with CSS?
For example, output generated by servletresp.java in htmlpage.html.
Can we use CSS in Servlet programming?
You question is very generic so I'm going to assume you are a beginning Java web programmer.
To your first question, I advise you to use JSP pages (or any other template technology).
Yes, it is possible to serve .html files from a Servlet using a RequestDispatcher, but JSP pages are meant to generate such output - it is easy to make a small part of a JSP page dynamic, while serving HTML files from a servlet doesn't give you an option for some dynamic behaviour.
Just rename your file.html page to file.jsp and put in in your web source directory of your war project.
To your second question - HTML sent by a servlet or a JSP page is still normal HTML and you can use CSS as you would in any HTML page.
Code example:
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher dispatcher = request.getRequestDispatcher("/file.html");
// If you want to include the file in your response, use dispatcher.include -
// you can include multiple different files or send more output using
// response.getWriter() or response.getOutputStream
dispatcher.include(request, response);
// If you just want to send this one file as the response, use dispatcher.forward
dispatcher.forward(request, response);
}
If your aim is to have the user's browser (appear to) request a static .html page, but have your servlet code executed instead, there's a few ways you could do that.
Most (All? I'm only familiar with running Struts on WebSphere) servlet containers allow you to specify an arbitrary pattern for URLs that are mapped to actions, so you could simply put in a mapping for htmlpage.html to your servlet action that executes the associated code then runs through a JSP (or similar) to render HTML to be sent as the response.
Alternatively you could simply serve up a static HTML page that uses a JavaScript (so executed client-side) templating engine, then load the data for the page from your servlet (likely as JSON) via an AJAX call when the page loads.
The second part doesn't really make any sense. CSS isn't a programming language, it's simply rules for specifying how things look. It's also meaningless without something to interpret and apply those rules to the content (which is what the browser does). You can include CSS inside HTML, or a separate file, generated in your servlet code, but it's not going to do anything.

How to grab a whole body unless header and footer of another site page

I'm developing with Liferay portal.
And now I'm facing a little problem:
I'm making site for some Company that has subsidiaries.
Then, I must cut out some parts(precisely header and footer)
of other site(sub. site) and put the body of page without'em in iframe of main site.
I was "googling", looking for something about Grabbers.
but I've found just about how to grab with PHP or Perl.
and here
It doesn't seem to be exact what I need.
You can try the WebProxy portlet for this.
As you'll have to modify the external content's body, you can't simply show it in an iframe, so this portlet might be what you need. It doesn't work with an iframe internally and you can replace some content on-the-fly.

Categories