Member Avatar for masterofpuppets

Hello guys,

Here's a problem that's giving me a hard time. I am working on a web server in Java and right now I want to enable the user to create a photo album. The user can type the album name in an <input> field in an HTML form. The problem is that I receive the client request to create a new album with the album name being encoded in some way, which I can't figure out. Here's what I have so far:

1. A simple .html file that contains the form (it's quite large, so I won't post it here) and I am using this as the encoding:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

2. A form that contains the input field for the album name. Here's the code for it:

<form method="post" name="createAlbumForm" action="../createnewalbum" enctype="multipart/form-data">
    <font color="gray">New album name </font>
    <input type="text" id="albumNameField" name="albumNameField" style="border-color:#7799ff; margin-left:10px; margin-top:15px; width:200px"><br \>
    <input type="button" value="Create album" style="height:25px; background-color:#7799ff; color:white; font-weight:bold; margin-top:10px; margin-bottom:10px; margin-right:20px" onClick="createNewAlbum()">
    <input type="button" value="Close" style="height:25px; background-color:#7799ff; color:white; font-weight:bold;" onClick="closeNewAlbumDialog()">
</form>

3. The createNewAlbum() function:

function createNewAlbum() {
    var string = document.getElementById( 'albumNameField' ).value;
    if ( string != "" ) {
        document.forms[ 'createAlbumForm' ].submit();
    }
}

And here's the request from the client that my server prints out:

POST /createnewalbum HTTP/1.1
Host: www.gravyty.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Referer: http://www.gravyty.com/UserHome.html
Content-Type: multipart/form-data; boundary=---------------------------14945890932209
Content-Length: 179

-------------------14945890932209
Content-Disposition: form-data; name="albumNameField"

&#1058;&#1077;&#1089;&#1090;
-----------------------------14945890932209--

So, my question is how should I read this &#1058;&#1077;&#1089;&#1090; ? I tried to use URLDecoder with both "UTF-8" and "ISO-8859-1" with no luck? Any ideas? Thanks in advance :)

Recommended Answers

All 3 Replies

Member Avatar for masterofpuppets

The 'Тест' is the part that's encoded. What you can see here in the forum is what I get in my site as well, i.e. I can see the correct name in the browser but on my computer it is encoded.

I receive the client request to create a new album with the album name being encoded

What kind of data type is the name received as?
For debugging Can you print it out char by char using the String.charAt() and Integer.toHexString() methods to show the values of each character?
Perhaps the hex display will show what you are receiving and help come up with a conversion method.

What user input generated the value you received for the name?

Member Avatar for masterofpuppets

The name and all POST data (apart from file upload) is received as a String. I have it as byte[] as well but I'm using the String one since parsing is easier. Could this be the issue? The user input that generated this was the word Test written in Cyrillic (Тест). I don't have internet access right now but I'll try to test it using String.charAt(...) later and let you know how it goes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.