Oliver Moore

Ranch Hand
+ Follow
since Mar 04, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Oliver Moore

Hi All,

Apparently this is a long standing bug

UTF-8 encoding does not recognize initial BOM

This class here seeems like a reasonable solution:

UnicodeReader and UnicodeInputStream

Hope this is of use.
16 years ago
Hi All,

Having looked at this a bit further, I think I'm having a problem with Notepad inserting a UTF8 byte-order mark of EF=BB=BF in any files saved as UTF8.

I'm assuming that Java doesn't add this BOM when it writes a UTF8 file.

I'm just suprised that Java parses in the BOM when it reades the template, thus causing the problem I'm seeing. Is anyone aware of a way round this? I'm going to try saving the files without BOM (I think Jedit can do this) but I'd like to know if there's a better way.

I guess I could examine the incoming stream in binary and look for the BOM coming in and filter if present.

Here's a couple of useful links I found whilst looking at this issue

Sun Forums
Unicode Transformation Formats: UTF-8 & Co.
16 years ago
Hi David,

Thanks for the coding tip.

I've had a look at the files being created using PSPad and the characters that seem to be present are ��� (Hex EF BB BF). If I look at the base file I'm parsing in PSPad, these charaters are not visible (in Hex or other).

If I look at the first line of any Notepad created file I parse in by printing to the console, the first charater is always ? (I assmume meaning unknown character).

If I modify the String and the write it out to file, it's fine. It's just when I insert one parsed template into another that I see these charaters carried into the file. I assume this is because the file writer discards the junk characters prior to writing if they're at the start of the string to be writen, but will carry them if they're present in the String somewhere.

I hope this information is of help.
16 years ago
Hi All,

I've written a program which parses several templates inserting relevant values and then writes them to a new file.

When I read a UTF-8 encoded file created using notepad and saved as UTF-8 encoded text, a junk (unknown) character gets inserted as the first character of the resultant string created from the incoming stream.

If I write the String containing the junk character out to a file after manipulation, the file is created with no problem and the junk character is not shown.

If I insert the String representing the file into another String and then write a file out containing both Strings, the first character before the inserted String will be junk.

As you can see from my code, I'm cutting the first character off of any incoming file to resolve this. However, in some cases I need to re-read and insert Strings into files that have been written using my output code (below). If I read a file which has been created using my code, the junk character is not present on reading the file.

Is this known behaviour (E.g. notepad doesn't implement utf-8 files in the same way as Java) or is there an error in my code that is causing it? I can solve this by noting whether the file I'm reading is a native file or has been created in Windows but this seems to be a work around rather than solving the problem directly.

Any help would be much appreciated.

Regards,

Oliver

My code for reading the file:



Code for Writing File
16 years ago
ah... that's the exact problem.... thanks...

First time I've played with IO...
16 years ago
Hi All,

I'm reading a file using BufferedReader.readline(). I've noticed that the formatting of the file you're trying to read has to be spaced by carrage returns!! Is this correct behaviour?

My Code is:



If my text file is formatted as follows, only test2 and null will be output.

Start Of File
test1
test2
test3
EOF

However, if I format it as follows, test1, test2 and test3 will be output.

Start Of File
*carriage return
test1
*carriage return
test2
*carriage return
test3
EOF

Utilmately, this can be solved by carefully formatting my input first, but can anyone explain if it's an inherant Java problem or my code.

Thanks!!
16 years ago
Hi All,

I have 3 elements on a form I wish to validate. All three elements are required, but one is an email so I am applying the email rule to it as well. However, when the form is submitted, the JS error regarding the email formatting is only returned if all three fields are populated. If I submit an invalid email address with the 2 other required elements empty, only errors for the missing elements are displayed.

Is this normal behaviour or am I doing something obviously wrong? I would expect an error to be displayed for the first level of testing an element failed at.
16 years ago
Hi All,

I believe the issue I was experiencing was that all strings passed back to the server were assumed to be in ISO format, despite the page encoding being set to utf-8. As I now understand it, many browsers do not correctly support passing the encoding type of a response back to the server.

After much messing about with request/response setContentType(), <%@ page contentType="text/html; charset=utf-8" %> and modifying the Struts-config file I was having very little success until I found that there is an encoding filter included in Tomcat 5 (\jakarta-tomcat-5.0.19\webapps\servlets-examples\WEB-INF\classes\filters\SetCharacterEncodingFilter.java).

Implementing this has solved all my issues and everything seems to be carried as utf-8 now. Seeing as this corrected my issue, I assume the root cause was that the contentType of the request object was not being set correctly at some point in the application.

I've attached a few useful links below on the subject of encoding. Any comments on my fix or a definite cause of my issue would be appreciated.

Common problems with i18n and servlets/jsp-s
Tomcat User-list
Struts Guide
16 years ago
Hi All,

I'm using struts 1.1 as part of my web application, but I've hit some major character encoding issues! Why does struts automatically encode all of the strings placed directly into a given form bean as ISO-8859-1?

I've set all my JSPs to UTF-8 encoding, but the � symbol still renders incorrectly as �� if I look at the contents of my form bean. I can get out of this by doing the following

but this is a pain to do for all strings. I guess I could put a method to do this conversion in all of my entity beans, but this issue seems so fundamental that I feel I'm missing something.

Is this normal behaviour for struts, or is there a setting I require?

My reason for using UTF-8 encoding is that the � symbol seems to be rendered incorrectly by my JSPs (be it dynamic content or hard coded in the page) as �� when I use ISO-8859-1.

Any suggestions as to either solve the struts conversion problem, or how to render � correctly with ISO-8859-1 would be much appreciated.

Regards,

Ols
16 years ago
Hi Lasse,
Thanks, that does illustrate a few things I wasn't aware of, however, I have a couple of questions.
As I understand it from the post you suggested, the following happens:
1)form submitted
2)paramters placed into request header
3)struts places parameters into associated formbean
4)action completes then forwards to uri defined in struts config
5)2nd action instanciates, and the only paramters available to it are those it submitted by the form (1)
Is this correct?
As I understand it now, all the original paramters should be available in the request accoss the whole action chain. Placing parameters in a form bean only copies them from the request into the bean, not remove them from the request?
By stating that the request parameters cannot be be changed, I assume this means that that the original values passed into the action (and therefore used to popluate the associated actionForm) cannot be changed. However, you can add parameters to the request, such as a resultSet which is then forwarded to a JSP and those values will be available. In the case above, I can add messages to the request which are passed, but no other parameters I put in are passed. Is this what you would expect as messages use a different mechanism to attach to the request?
Whilst exploring this problem, I stopped forwarding to the 2nd action, and started going to a JSP. I also added a hidden value "test" in the form which is not associated with the formBean for the add action. I would expect this to be available to the JSP the action forwards to by using a request.getParameter, but it is not. As this "test" request paramter is part of the original input, should I not be able to access it as I'm not attempting to modify it in any way?
Thanks for your help...
17 years ago
Hi all,
I have the following 2 actions, addGalleryPictureAction and listGalleryAction shown below, chained together with struts. The general idea is that on successful file upload, a new list of pictures should be generated and then passed to a page to display this new list. All this depends on the paramter marina_id, which is passed from the upload form to the add action. However, it does not get passed to the list action. Printing the marina_id in the list action shows it as null, even though I am explicitly setting it in the add action.
The list action definitly works both individually and as part of a chain, and the add action completes as the picture is created, as are the DB entries. The only difference between this and other code blocks with a similar flow is that the original uplaod form on the jsp is set to multipart/form-data... Should this make any difference?
Any help would be gratefully recieved...
Regards,
ols

17 years ago
Hi Vijay,
I've never used this extension presonally, but Struts workflow extensions seems to encapsulate what you're trying to do...
http://www.livinglogic.de/Struts/
Hope it's of help...
17 years ago
JSP
Hi Somshekhar,
I'm not really sure you're asking the right question here...
HTML is static, i.e. you write a pge once, and every time a user views it, it will look the same.
JSP is dynamic, i.e. it allows you to perform actions and generate data using java embedded in either the jsp page or an external class file. These actions are carried out by the JSP websever application (Tomcat, JBoss etc) to generate HTML code, which is then sent to the client browser for interpretation and display.
A very quick example of how HTML and JSP co-exist is below. The starting point is an html page with a form on, one single textbox called nameIn for the user to enter their name, and a submit button to submit the form to the jsp page below. I assume you've read some of the basics of how JSP tags work...

I would strongly suggest getting a book on the subject (search for JSP on amazon, and javaranch for book reccomendations).
If I was going from a static HTML page to JSP, I'd want to think about where any dynamic data is coming from (xml, DB, user input), the types of operations you want to perform on it, whether a framwork is suitable rather than JSP pages, are there different type of user accessing your site, does it require security, what web server are you using etc... I'm sure others can think of far longer lists...
I hope this is of some help...
17 years ago
JSP
Hi Chad,
Firstly, you make the point that you need a session scoped bean in order that the page retains the values you enter when you return to it on an error.
Using Struts, you don't need to do this. If you are use

to return on error, the request scoped form bean will be returned to the input page (i.e. your form) and it's values used to repopulate the boxes on that form.
Using a request scoped bean may also help to remove your caching problem. Another possibility is to call

just before your action forwards to the sucess page defined in your struits config for this action. This will remove the form bean mapped in your struts action from the request scope, so it will not be available to any future pages.
Hope that helps...
17 years ago
Hi All,
I need to return the following to my JSP page:
A list of results from a single table (to use in a select box)
A single result from the same table to display for editing.
In this scenario, the list I return will always contain the single result I wish to display. My question is, which is the most efficient way to get the single result. I see 3 alternatives:
1) Place the key for the single result in a response, Then iterate through the list at the JSP page until I find the desired single result.
2) go to the database twice, once to generate the list from a db access, then a 2nd db access to get the single result.
3) When processing the returned result set, pull out the desired single result and place it in a seperate bean to return to the page.
I think option 1 is the best, as 2 has 2 expensive DB accesses in it, and 3 would seem to make the class file processing the result very specific. Does this sound reasonable, or is there a better way altogether?