Clivant Yeo

Ranch Hand
+ Follow
since May 22, 2004
Merit badge: grant badges
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Clivant Yeo

I guess I will just let status.php output the required data without any formatting, which could be JSON or csv format.

Then I will use jQuery/javascript to load the data into some variables which I will manipulate and do the formatting.

This is because, the visual aspect of an application tends to change more then server side counterpart. By pushing the formatting job to the javascript side, you will only need to make any visual changes in one file. But if you were to let your server end output the visual information, you will need to change the data in more places.

But of course to cater to cases in which Javascript is disabled, I will have another PHP file which will provide for the visual aspect. And I will group the file under a same folder as index.php, so that when I need to change the visual part, I will not need to look too far.

Just my 2 cents though.
11 years ago

I'm supposed to write a loop that initializes the second row to store integers starting with 2 and incrementing by 3 for each element in the row.
So the second row would have integers 2, 5, 8, 11, 14, 17.

grid[1][1] refers to row 2, column 2, not row 2, column 1.

should be

The inner loop should be j++ instead of i++.

12 years ago
Hey Senol,

I took a look at the api again. It seems that FileItemStream extends FileItemHeadersSupport, which means that there is a getHeaders() method available from the fileItemStream instances.

API for FileItemStream

API for FileItemHeadersSupport

I have a strong feeling that the getHeaders() method is what you are looking for.

I don't have a Java web container installed on my machine, but let me know if this works.

Campbell Ritchie wrote:

Clivant Yeo wrote:. . .
Loop number of times equal to midpoint + 1.

Maintain two counters:
. . .

If first counter == second counter, break out of the loop.

Why + 1? That looks like a mistake.
You don’t need two counters. Only one.
If you use the correct values to count to, there is no need for the break. In fact, using break might introduce an out-by-one error, but I am not certain on that point. Depends how you use it.

Hi Campbell,

You are right about the midpoint, didn't gave much thoughts. Hmm, I am suggesting to use two counters because I am thinking in the direction of an in-place reverse algorithm.

Thanks for highlighting the mistakes!
12 years ago
Compute the midpoint of the array.
Loop number of times equal to midpoint + 1.

Maintain two counters:
1) One counting up from 0 to midpoint.
2) One counting down from last index to midpoint.

Swap the element at the first counter with the element at the second counter

If first counter == second counter, break out of the loop.

12 years ago
You are most welcome!
12 years ago

Think you can achieve what you want by doing the following:

Use the getItemIterator method instead of the parseRequest method.

Use the FileItemIterator returned to iterate through the FileItemStream instances.

Use the openStream method of the FileItemStream instances to read the contents.

I didn't try it yet, but that's what I can gather by reading the API.

Hope it helps!

What is a HTTP multipart request?

It is a type of HTTP request that HTTP client construct to send information to the server.

An example:

Connection: keep-alive
Referer: http://localhost/GetPostRequest.php
Content-Length: 1611568
Cache-Control: max-age=0
Origin: http://localhost
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.91 Safari/534.30
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryX6nBO7q27yQ1JNbb
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Content-Disposition: form-data; name="myFileDescription"

My sample file description.
Content-Disposition: form-data; name="myFile"; filename="SomeRandomFile.pdf"
Content-Type: application/pdf

file contents...

Notice the string "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryX6nBO7q27yQ1JNbb".

This is the part that tells the server:
1) the HTTP request is a multipart request
2) The separator between different chunks of data.

In the example, there are two pieces of information:
1) A form data "myFileDescription" with value My sample file description.
2) A file named as "SomeRandomFile.pdf" and its contents.

Where it can be used?

It is used by browsers and HTTP clients to upload files to the server.

Hope this helps.
12 years ago
Do you mean HTTP multipart request?

If that's the case, a HTTP multipart request is a type of HTTP request that HTTP clients construct to send file and data over to the server side.

I had written a post on this topic in C#. You could probably look at the first few sections to get an understanding on that.

Hope it helps!
12 years ago
I assume that you should know how to program with Java and that you know how to read APIs (application programming interface).

Check out the java.util.Scanner class at,5,0/docs/api/java/util/Scanner.html

This should help you understand how to read the numbers from a file.

12 years ago
Write calls block because the receiver of the data you are writing to is not ready to receive the data.

For instance, when writing to file, the operating system needs time to get/create the file before populating it with data.

Similarly, in TCP/IP, the process that is receiving your data needs to be "listening" to your data before your write can proceed. In such a case, if you find that your writing process blocks infinitely, you can know for sure that you need to revise your communication protocol between your write and read process. In a way, blocking also helps in debugging communication protocol related errors.

Just my 2 cents. ;)
Hi You Gin,

I heard that servlets and JSP are losing their popularity for backend development and people more using .NET for websites

It depends on whether your boss wants to use .NET or Java. While made easier for developers, .NET costs money, if your boss have the money, then .NET is the choice. However, Java although just a bit harder to code, is able to give you a free alternative, it is a very good and powerful options for startups. Popularity is probably not a good factor to determine where you go next. Sometimes it is more profitable to choose the less popular choices, since you will have less competition as well.

Mobile is a growing area, but web will also be in demand -- especially mobile web.

Indeed, although mobile phones are getting more and more powerful, there are many interesting things that are only possible with server side technologies. Most often, those servers are the ones doing bulk processing so that mobile phones can present the results nicely to the end user. Hence, I will get a foothold on server side technologies before laying my feet on Android.

13 years ago
Hi Wilson,

Perhaps you could try "Effective Java" by Joshua Blotch, which I believe will help you gain insights on using the Java effectively, OO style.

Just my 2 cents.

Welcome to the Java family
13 years ago
The wireless toolkit comes with the complier and the emulator.

I guess you will need some beginners guide on Java. Learn how to navigate through the api first. As you ride further with this bandwagon, the web and some java forums will be your "companion guide". APIs are just references remind you of class methods and etc; it is the methodologies that you need to pick up.
18 years ago