I know that we need to put this line of code in a HTML page for having an icon (corner of the website).
<link rel="shortcut icon" href="fav.ico" />
but if i have many JSP(s) and Servlet(s), is there any simple way instead of put that line of code into every single page of JSP(s) or even Servlet(s)?
The common way is that you write some codes as header and import it in all jsp pages like this:
<%# include file="/common/header.jsp"%>
There are other decoration frameworks like sitemesh which you can create template page with lots of abilities for your hole website.
I have a jsp code, where I fetch some JSON data from JAVA Class file. [Basically openfire users]
Now I get the data successfully, but I want to show this data in HTML table format.
How do I Do this ?
My JSP Code :
<%# page language="java" import="prov.*, java.util.*, java.io.*,java.text.*" contentType="text/html"%>
<%# page errorPage="error.jsp" %>
<%
Openfire tc = new Openfire();
tc.getUsers("192.168.50.218","epvFjHq5RHA614C7");
out.println("Data Is As Below : " + tc.getUsers("192.168.50.218","epvFjHq5RHA614C7"));
%>
And I get Response from the JAVA Class method like this :
[{"username":"abcd","name":"","properties":null},{"username":"admin","email":"admin#example.com","name":"Administrator","properties":null},{"username":"bizdd456d454mnc","email":"bizMNC#bizrtc.com","name":"bidzMNC","properties":null},{"username":"bizddd454mnc","email":"bizMNC#bizrtc.com","name":"bidzMNC","properties":null},{"username":"bizmnc","email":"admin#example.com","name":"511515151515151","properties":{"property":[{"#key":"console.order","#value":"session-summary=1"},{"#key":"console.rows_per_page","#value":"user-summary=8"}]}},{"username":"dhaval","email":"dhaval#bizrtc.com","name":"dhaval","properties":null},{"username":"keyur","email":"keyur#bizrtc.com","name":"keyur","properties":null},{"username":"minz","email":"bizMNC#bizrtc.com","name":"bidzMNC","properties":null},{"username":"patel","email":"rau#example.com","name":"patelbhai","properties":{"property":[{"#key":"console.order","#value":"session-summary=1"},{"#key":"console.rows_per_page","#value":"user-summary=8"}]}},{"username":"rajan","email":"rajan#bizrtc.com","name":"rajan","properties":null},{"username":"+username+","email":"+email+","name":"+name+","properties":null}]
As I am very new to JAVA and JSP I don't know how to parse this data to HTML Table.
So Please help.
You can see here how to do it. You can populate it in Javasript or jQuery, but it is better to use JSTL and not just call java code inside JSPs.
I would suggest you use mustache als template engine.
It allows you to use a HTML fragment as template (store it as resource) where double curly brackets (hence the name Mustache) denote the insertion points.
The full documentation of the Mustache syntax is here and a Java example here. Let us know how it is going.
I have a webapp built using Struts2, with Tomcat 7 as application server and MySQL database as backend. Now i pass some string from my jsp file using jquery ajax but this string contains special characters (ñ - enye). When i alert it before passing to the class via jquery ajax, it displays fine but when i receive it in the java class, it displays like ñ . I need the string to be as exact as possible as i am querying the mysql database with an entry similar to the string.
All jsp pages have <%#page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> and <meta http-equiv="content-type" content="text/html; charset=utf-8"/> in head as well as the jquery contentType contentType: 'application/json; charset=utf-8'.
What could be the possible solution to this? Thanks for your reply. Here are the screenshots by the way. Thanks for your help :)
Luckily found the answer within StackOverflow. Thanks guys, you're the best :)
How to determine if a String contains invalid encoded characters
How can pass json values from jsp to javascript as object via ajax?
I can not use global js variables in jsp because this will lead to json content to be visible in page's source
Here is the scenario that I want to achieve:
url of jsp is opened in browser.
Data is being created in scriptlet and coverted to JSON format
json is "sent" to javascript as object
From above scenario, i understand that javascript must initiate the ajax call to jsp.
The issue with this, that jsp's code will be invoked 2 times:
When page is opened in browser - data is prepared
on each ajax call same code will be called again
Constrains: No jquery, no other libs, no servlets, no additional jsps. :(
EDIT:
There is additional problem, I need to pass multiple json objects to javascript.
I wont be able to do it with response.getWriter().write();
I don't think concatenating all json objects and sending is the correct solution.
The parsing of the received object in javascript http.responseText will be overwhelming.
Why do you need ajax here? If you know that you need to populate some things from server onto jsp page you can do that through scriplets itself:
EX
<%# page import="com.mypackage.PersonDAO" %>
<html>
<body>
<table>
<th>Name</th><th>Email</th><th>Contact</th>
<%
List<Person> myList = PersonDAO.getAllPersons();
for(Person person:myList)
{
%>
<tr>
<td><%=person.getName()%></td>
<td><%=person.getEmail()%></td>
<td><%=person.getContact()%></td>
</tr>
<%}%>
</table>
</body>
</html>
This is a very simple example. You can do more complex things using JSTL.. :)
So there is no jquery, no Servlets, no ajax and no extra jsp's :)
UPDATE
Since you want data in your javascript before page loads you can use jQuery's holdReady() method.
$.holdReady( true );
$.get( url, function() {
// Perform something
$.holdReady( false );
});
See but all modern browsers have developer tools like firebug for mozilla, so any ajax call made will be trapped by them. The only way you can secure them is my encrypting them.. which will complicate things for you... IF you can explain the scenario you are trying to implement may be I can come up with it..
I have been using Jsoup for parsing my HTML files and so far it does a great job. However, it's not able to parse any server tags ( <% ... %> ). I decided to extend it but I cannot find an easy way to extend its Parser and all those private/package level classes (i.e. TreeBuilder, TransitionState ... etc)...
So I started looking at Jericho as it claims it can parse server tags - however, its documentation is so poor that I cannot even get started easily. And seems like its API is not as friendly as what Jsoup provides - it's not that straight forward to extract some nodes and move it around ...
I wonder if anyone has the similar situation before and how you get it solved? In short, I just want to parse JSP files in Java. (Well .. please don't ask me to implement one by myself ;p )
Lastly I get a workaround: put server code block in a HTML comment block so that 1) server code can get executed correctly; 2) Jsoup can process the whole block as a HTML comment node without touching anything inside.
e.g.
<!--
<%# page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%# page import="com.systemcrossed.groupbuystart.webapp.display.DisplayHelper" %>
<%# page import="com.systemcrossed.groupbuystart.webapp.util.JsonUtil" %>
<%# page import="org.apache.commons.lang.StringEscapeUtils" %>
<%# include file="/_sys/pages/public/incl/jspCommon.jsp" %>
-->
<!--<%
// Java code here
%>-->
<html>
<head>
... html stuff
It works well for me now! Hope ppl who got the same problem could get some help ! ;)