
When surfing the internet and casually viewing the source of your favourite sites [as you do :) ] you may notice some CSS links with query strings.
<link rel="stylesheet" href="sources/css/basic.css?pr=452343223" type="text/css" media="all" />
This may seem pretty pointless as the webserver will ignore any parameters and continue to read the CSS file's contents as normal.
So what is the purpose of the query string on a CSS link?
It's actually a pretty simple hack. If you change the query string every time the style sheet is changed it will force the client's browser to reload the CSS file from the server - removing the possibility of the client using an out of date cached version. This then ensures that the webpage is rendered with the most up to date CSS after each release.
Tags: CSS, Browser, Trick, HTML
The tutorial also provides some examples of CSS, HTML & googles Gson Jar files that convert Java Objects into their JSON representation. Making it easy for Javascript to parse the response data.
Obviously I would not recommend using this word for word in production as I did not include XSS security such as striping tags and escaping output. Here is a great XSS cheat sheet from OWASP.

import java.util.Map; import java.util.TreeMap; /** *Simple first level JavaScript Object Notation Map converter
*http://www.philipstarritt.com
* @version 1.0 * @author Philip Starritt * @since 2013/04/15 22:25 */ public class JavaSon { /** *Will convert a Java Map into JSON format that can be easily used in AJAX calls.
*String, Integer & Boolean will be printed in JSON expected format.
*Other objects (Arrays/Lists/Objects etc) will .toString() so it's best to override.
*This method can be further extended to include nested arrays & Objects in the * JavaScript Object Notation.
* @param map * @return String in JSON */ public static String toJson(Map map){ return (map != null && !map.isEmpty()) ? parse(map) : null; } private static String parse(Map map) { int counter = 0; StringBuilder stringBuilder = new StringBuilder("{\n"); for (Map.Entry mapEntry : map.entrySet()) { stringBuilder.append("\t\"" + mapEntry.getKey() + "\":"); String className = mapEntry.getValue().getClass().getSimpleName(); if(className.equals(Boolean.class.getSimpleName()) || className.equals(Integer.class.getSimpleName())){ stringBuilder.append("" + mapEntry.getValue() + ""); } else{ stringBuilder.append("\"" + mapEntry.getValue() + "\""); } if((map.size() - counter) != 1){ stringBuilder.append(",\n"); } counter++; } return stringBuilder.append("\n}").toString(); } /** *Main
*/ public static void main(String...args){ Map map = new TreeMap(); map.put("1 - first", 2); map.put("2 - second", "dfdf"); map.put("3 - third", true); map.put("last", new Integer(4)); System.out.println(JavaSon.toJson(map)); /* * OUTPUT * * { * "1 - first":2, * "2 - second":"dfdf", * "3 - third":true, * "last":4 * } * */ } }
On Thursday I will add a another code example on how to use jQuery/Javascript AJAX calls on a Java servlet and access the JSON formatted response data.
cya!
Tags: Java, JavaScript, JSON
I hope this comes in handy for someone.
Here is an example division recursive method.
public static int divide(int a, int b){
if(b == 0){
return 0;
}
else if(a < b){
return 0;
}
else if(b == 1){
return a;
}
else{
return add(1, divide(sub(a,b),b));
}
}
Tags:
Java,
Recursion,
Maths

I will go back and optimise this program sometime in the next week or so and provide a video demo and upload the source.
Anyway.... Here is a brief demo on how to use JMapper.
First we need to create a bean that implements my JMapperBean interface. The bean should match the database column names/data types & have a method that returns the table name. (You can have any number of data columns)
After that we can then use the JMapper Class to set (Bean), build & execute the transaction. I will provide the JMapper Class Source / reference later.
Please note I have not optimised this code... (all them exceptions could be better handled in JMapper...)
Then some metrics... (Yes I know 0.283.. could be faster)
As you can see this removes the need to write / execute any inline SQL in your java. Data inserted...
My JMapper Class was mainly built from reflection, giving it the ability to examine its own structure & types on the fly. (Package java.lang.reflect) Example:
Overall - This small project has been very fun and I plan to add/optimise its features in the future.
Tags: JMapper, Programming, Reflection, Java


Today I finished developing my new Blogging CMS. I decided to use lots of JS/AJAX/jQuery as that's the way the web seems to be going. (With server validation of course for you XSS nerds!)
Try out the comment form.
Tags: Blog, AJAXYoo
Posted By: Anon k on Monday, 04 March 2013 at 02:30
Nerd
Posted By: Pete on Wednesday, 06 March 2013 at 23:10
...
Posted By: Orange Tango on Wednesday, 06 March 2013 at 23:10
Hello
Posted By: Gord on Saturday, 09 March 2013 at 13:27
Cool
Posted By: Philip on Friday, 26 April 2013 at 18:03
Dfgdf
Posted By: Hghf on Friday, 26 April 2013 at 18:03









