Matthias Reuter's picture

Better Javascript: Updates on the address book

Last night I met Jennifer again and apart from being hot it turns out she's pretty perceptive as well. When she read my previous article, she objected to some aspects of my address book.

Her point is, it's a waste of memory to store empty properties of an address. That's true, so I sat down and threw away those unneccessary bits:

var addresses = [{
    nickName  : "Mom",
    phoneNumber : "555-69-666"
},
{
    firstName : "Mathilda",
    lastName  : "Wozzle",
    phoneNumber : "555-343-37847"
},
{
    firstName : "Jennifer",
    phoneNumber : "555-467-4475"
}];

Unfortunately, we now encounter some problems: First checking for an empty string no longer is sufficent, and second, since undefined is not a string, concatenating is a problem:

var address = {
    nickName : "Mom",
Read more

Phillip Steffensen's picture

Developing a simple SOAP-webservice using Spring 3.0.1 and Apache CXF 2.2.6

In the past few years many techniques have been developed to help applications interact with each other. One of them are webservice-interfaces. These interfaces are extremly popular in the world of Java software development. One Framework that can be used to build such interfaces is Apache CXF. Apache CXF delivers a toolset to develop interfaces using different protocols like XML/HTTP, RESTful HTTP, Corba and SOAP. In this article i'd like to show how easy it could be to develop a simple SOAP-webservice based on Apache CXF 2.2.6 and the Spring Framework 3.0.1. You can download the full example at the bottom of this article.

Read more

Nico Heid's picture

Using an EntityManagerFactory with JPA, Hibernate and Wicket

If you read the previous article "@OneToMany Relationship with Java, Hibernate and Annotations" you might have noticed some imperfections in the persistence layer. On the code side we have been lazy by just using FetchType.EAGER. This of course puts extra stress on the database, because in our example, for each BlogPost all Comments are fetched, even though they might not be displayed.

Maybe you played around with the example version 0.1.1(download tarball). You might have noticed that if you switch to FetchType.LAZY you will most likely get a no session or session was closed on certain operations.
Read more
Matthias Reuter's picture

Better Javascript: Three women and one address book

This is about three women and a javascript address book. The first woman is my mom. Though she does have a first name and a last name, I have been referring to her as mom for my whole life, so her entry in my address book should be labelled "Mom".

The second woman is my probation officer, a Mrs. Mathilda Wozzle. I do not have a nickname for her, and obviously I don't want anybody who happens to look over my shoulder to see what she is. Her address book entry should therefore be labelled innocently "Mathilda Wozzle".

The third woman is Jennifer. I met her in a pub last week, and I do not remember her last name. I'm not even sure she gave me a last name, can't remember much of that night. The note she handed me contained only two bits, Jennifer and a phone number. I definitely want her in my address book and until further contact she has to go as "Jennifer".

I'm afraid it's getting technical now.

My address book now looks like this:

 Read more

Christian Harms's picture

Number crunching with javascript - a tutorial

This article will describe how to build a more complex javascript application. I chose to build a number cruncher for finding sociable numbers. There are many idle browser out there and the new Worker-thread object (available in modern browsers) offers the complete power of all cpu cores. In the first part I will describe how to inherit javascript objects with the optimization steps and discuss the usage of a profiler. The second part will improve the performance with using Web Worker in threads for greater computing power and how to handle it.

introduction

Did you heard of perfect numbers? No? A number is perfect if the number is equal to the sum all proper positive divisors. The old greek mathematics found the following examples (or try out the demo):

The 6 has as positive divisors 1, 2 and 3 and the sum is 6.Read more

Nico Heid's picture

@OneToMany Relationship with Java, Hibernate and Annotations

NOTE: There is a follow up here: Using an EntityManagerFactory with JPA, Hibernate and Wicket which fixes some design flaws.

If you followed the first article on hibernate: Java persistence with Hibernate and Annotations you might be interested in how to create relationship between classes (or sql tables).

Let's pretend we're writing a little blog software. We only need articles and comments. To keep it simple, one article can have many comments. Comments can have no comments.

The database, once filled, should look like this:

mysql> select * from BlogPost;
+-------------+-----------------------------+---------------------+--------------------------+-----------+----------------+Read more

Phillip Steffensen's picture

Spring Module OXM – A new feature of Spring Framework 3.0

Since a few days Spring 3.0 is out. The frameworks core APIs (e.g. the BeanFactory) have been updated for Java 1.5. But there are also some new features in Spring 3.0. Today I will take a look on Springs new OXM-feature and see how it can be used. Naturally all features added to the Spring framework are easy to use. Let's see if Springs simplicity still exists...

Read more

Matthias Reuter's picture

Circumvention of Opera's Upload Field Path Protection

If you have a form with a file upload field, in some browsers you cannot extract the path to the chosen file. This is meant as a security measure, because it might reveal some information about the user, e.g. the username.

In earlier versions of Opera, if you tried to read the upload field's value, only the file name was given:

var uploadField = document.getElementById("upload");
var path = uploadField.value; // was "foo.jpg"

In the recent version, Opera for some reason reveals a full path, but it's a fake path:

var uploadFIeld = document.getElementById("upload");
var path = uploadField.value; // now "C:\fake_path\foo.jpg"
Read more

Christian Harms's picture

Escaping examples and the worst test data

After the fine and long article about escaping from Matthias here some examples for special characters in a simple web application. This article should be only an inspiration, I will describe some code samples with python/javascript and explain why [<"@%'&_\?/:;,>কী €] is the ultimate input to test input in web applications.

The demo application offers a simple form with name and message field for an one-line guest book.Read more

Matthias Reuter's picture

The art of escaping

Escaping is the art of transforming a text into a transport format from which it can be extracted again without any modification.

That's something every developer does - to a certain level. For example take the sentence

Matthias says: "I love Javascript".

Now put this sentence in a Java source code:

String s = "Matthias says: "I love Javascript".";

If you don't complain about this, your compiler will. In Java (any many other programming languages) the quotation mark " has a special meaning, it defines a string. So if you have a string containing the quotation mark, you need to escape it:

String s = "Matthias says: \"I love Javascript\".";

If you print out s, the original text is shown:

System.out.print(s); // Matthias says: "I love Javascript".
Read more

Syndicate content