This week's giveaway is in the Beginning Java forum.
We're giving away four copies of Bad Programming Practices 101 (e-book) and have Karl Beecher on-line!
See this thread for details.
Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!

Rolf Johansson

Ranch Hand
+ Follow
since Feb 25, 2004
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 Rolf Johansson

Specifications in original posting can justifiably be called sloppy

There will be 2 though 6 values separated by colons following User=
These values will always be comprised of digits and characters, so \\w will work.

I appreciate all the help!
10 years ago
Thanks for the replies. I've tried both regular expressions, but neither locate the desired string. I've tried as:


10 years ago
I need to parse a string that contains a Name=Value as:

blah=value;junk=avalue; User=one:two:three:name; morejunk=value

I need to grab the User=one:two:three:name; part of the string (User= is the fixed part of the string followed by 1 or more fields separated by colons), then take the value after the last colon, before the semicolon (name in this case).

What would be the Pattern to give in order to find the string I am interested in?

Is the best approach something like:

My experience with Scanner has been limited to a fixed delimiter, such as colons. This particular problem seems to fit Scanner's ability to deal with regular expressions / patterns.

Any suggestions are appreciated.
10 years ago
I am running apache 2.2.4 on Red Hat. I need to set 2 cookies, then redirect the request. The redirect is working, but the cookies are not being set. In order to debug this, I wrote a simple Perl CGI that sets 2 cookies, then redirects to another Perl CGI on the same server which reads all cookies.
Here is the CGI that sets the cookies and performs the redirect (note: domain name changed to protect the innocent)

The redirect occurs and this CGI reads all cookies, but the 2 cookies set above are never found:

Is there an apache config / directive that I need to set?
Any help is appreciated.
10 years ago
I need to search for a string in a data file, based on a user-supplied regular expression. I am using the Pattern class for this as:

When userSuppliedRegex is set to * or a a string beginning with *, such as *foo, I get this exception:

Exception in thread "main" java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0 *

How do I specify a regex that begins with a metacharacter, such as * or *foo or .bar?

From the Pattern javadoc, I see:

Perl is forgiving about malformed matching constructs, as in the expression *a, as well as dangling brackets, as in the expression abc], and treats them as literals. This class also accepts dangling brackets but is strict about dangling metacharacters like +, ? and *, and will throw a PatternSyntaxException if it encounters them.

10 years ago
all URLs and servlets are in the same domain--I denoted the doamin as
10 years ago
I have a servlet create 2 cookies, then perform a redirect to another URL (on another server) which needs these 2 cookies. My redirect works fine, but the application behind the other URL does not "see" these 2 cookies.
As a test, I wrote 2 simple servlets. One servlet adds the cookies to the response and performs the redirect to a servlet on the same server. The servlet to which I redirect simply looks at all the cookies in the request. The servlet to which the redirect is performed does not find the 2 cookies the first servlet adds to the response. (snippets below)

Any ideas why the cookies cannot be added / retrieved? Any help appreciated.

JDK 1.5
apache-tomact 6.0.10

Code to add cookies:

Code to retrieve cookies from request--never finds the 2 added?

[ February 16, 2008: Message edited by: Bear Bibeault ]
10 years ago
I just executed the self-extracting file from sun for Solaris:
j2re-1_4_2_09-solaris-*.sh. I want to execute a different version of Java than is "formally" installed on my Solaris box. The installation went fine and when I execute

it yields:

When I try and run one of my Java applications, I get:

I realize that there must be some interaction between the 1.4 Java launcer I just installed and the older (1.2) JRE "formally" installed. Can anyone tell me how I can get my newly installed (private) JRE to run?
- Rolf.
[ September 26, 2005: Message edited by: Michael Ernest ]
12 years ago
I need to periodically read an RSS page. I was expecting to find a Java class or set of classes that allowed me to read and parse the RSS returned from the page. Am I missing something or can I just use classes that read XML with RSS?
- Rolf.
13 years ago
I have an application that uses classes contained in a jar file for processing Excel spreadsheets (the Java Excel API). This works fine when I run it as:

with my CLASSPATH set to:

I want to "bundle" all my classes for this application into an executable jar file, then run the application from the executable jar file. So I create the executable jar file containing the "mainClass" as:

But when I execute it as:

Java cannot find classes contained in the jxl.jar file:

This class was found when executing directly from the .class file and this file is indeed in the jxl.jar file:

So I have 2 questions:
1) Why isn't jxl.jar found when I try to execute the executable jar file?
2) Is there a way I can add jxl.jar to the executable jar file, so I just need to deliver 1 file?

- Rolf.
13 years ago
I am using the HTMLEditorKit cnd HTMLDocument classes to read in and parse HTML. I have it working just fine but would like to understand why
the createDefaultDocument() method in the following code throws an InternalError exception when DISPLAY is not set to something reasonable.

When I set DISPLAY to something reasonable this works fine, but I would like to know what is causing createDefaultDocument() to do anything "graphical".

- Rolf.
13 years ago

Explicitly get the URLConnection object associated with the URL using getConnection()

Do you mean openConnection()?

and be sure to call close() on the URLConnection itself after the request.

I do not see a close() method in the URLConnection class. Perhaps I am misunderstanding something?

So, something like this:
assume the arrayOfURLs is filled with URLs to read from like:

13 years ago
I have a program that must read the results from similar URLs. These URLs are of the format similar to:*%20from%20ARCHIVE1*%20from%20ARCHIVE2*%20from%20ARCHIVE3*%20from%20ARCHIVE4
I must read from 2,000-3,000 URLs such as these. Presently, my code makes a URL, gets a InputStreeam from the URL and creates a BufferedReader from the InputStream from which it reads. Like this:

It takes close to 1 second to perform the url.openStream(). So, I have 2 questions:
1) Is this the most efficient way to convert a URL into something from which I can read.
2) Since these URLs are accessing the same host ( is there a better way to "navigate" from URL to the next?

- Rolf.
13 years ago
I need to supply a compareTo() method for a class that contains 2 integers representing a part of a whole (similar to a fraction containing a numerator and denominator. There are other attributes in the class, but equality (and therefore the hascode) is based solely on these 2 integers. What do you think of this algorithm?

The challange is to represent the 2 integers as one int (the return value). It is perfectly fine that 2 sets of integer values (such as 1/3 and 10/30) return the same hashCode. These 2 sets are considered equal.

- Rolf.
13 years ago
In this case I don't need to rollback. The source data can be re-processed any number of times without damage.

So, my question is, does JDBC have an internal method of automatically committing N records, or do I need to keep track of the number of records inserted and explicitly perform a commit?