JohnWilliam Fitz

Ranch Hand
+ Follow
since Oct 13, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by JohnWilliam Fitz

Why? I'm in a contest for the worst programmer of the month at my company and the competition is stiff. ;o)
14 years ago
JSP
Yes. ;o)

Should I write my own tag?
14 years ago
JSP
Hi!

I want to set a session scope attribute in my jsp, but I will only know the name of the attribute to set at runtime (long story).

I first tried something like this...

<c:set var="prefix" value="${something}" />
<c:set var="attribName" value="${prefix}Attrib" />
<c:set var="${attribName} value="howdy" />

...but alas <c:set> does not accept expressions for the var attribute (which I knew but forgot).

So, before I go writing my own custom tag to do this, I'd like to know: Does something already exist in JSTL or the standard custom tag library <jsp:xxx> to do this? Or perhaps in struts 1.x (which I am using in this project)?

Thanks muchly!
John
14 years ago
JSP

Paul wrote: but you might want to just do code reviews instead of Maginot Line programming.



Thanks Paul.

I can't find a definintion of Maginot Line Programming. What is that? Is it a bad thing? Are singletons bad?

John
15 years ago

Paul Clapham wrote:In a web application, the standard way to have only one object is to make it an attribute of the application. Which you get at via the servlet context.



Hi Paul.

Thanks, I may do that as well. But it seems to me that alone isn't enough. It won't prevent some thread from setting the chosen attribute to null, then instantiating a brand new object (i.e. different instance) and setting the new object as the attribute. Also I need orderly startup and shutdown so that the file is open before the different threads start calling read() and write(), and so the file closed properly when the application is shutting down.

John
15 years ago

Garrett Rowe wrote:Do you plan on writing any unit tests for this class?



Hi Garrett.

Um, possibly. Should that make a difference in my choice?

John
15 years ago
Hi all.

I have a web application that reads and writes from a text file. The different servlet request threads may need to read or write to/from this file, and so I want the read/writes to happen one at a time (synchronized that is), of course. Performance is not an issue in my particular case. It will only be used by two or three people at a time.

So, at first I thought I create a singleton class with synchronized NON-static read and write methods. The singleton would have a NON-static File member object that it uses for access to the file. A worker thread would call...

MySingleton instance = MySingleton.getInstance();
instance.read();
instance.write();

...and so forth. It seems that should work.

But then I thought, why not just make a purely static class? By that I mean that all the members functions (read() and write()) would be static and synchronized, AND the File member object would ALSO be static. It seems to me that accomplishes the very same thing without the overhead of writing a getInstance() method and making sure that only one instance is ever created of my object.

So, unless I am missing something (and I usually am), in this case functionally there is no difference in the two approaches and the "purely static" approach is less code and (who knows) maybe less memory consumption?

Can anyone tell me if I'm wrong? Should I be using a singleton instead?

Thanks!
John
15 years ago

Ulf Dittmer wrote:It's largely a matter of personal preference. Using DOM has the advantage of not requiring any additional libraries (it's built into the JRE), although that's not often an important consideration.



Thanks Ulf.

Actually, I always like to go for the built-in solutions first, and abandon them only when my needs exceed their capabilities. So I will start with DOM.

Another question: Does writing XML with DOM mean I should be using the LSXxx classes? Like LSSerializer and LSOutput?

Gruss,
John
Hi.

I'm new to working with XML in Java. I have two questions...

* Where's the FAQ for this forum? I searched the forum for "faq" first, I swear.
* I am overwhelmed by the number of options. I think I have come across a least a dozen different ways to write/update xml from java. Which one should I use? My needs are very simple: updating (that is writing to already existing) xml files of small size and rather simple structure.

Thanks,
John
Yes, you're right. I wrote my own in the meantime, converting all the "less thans" and "ampersands". I'm just worried I missed some poisonous combination of characters that I should also be watching out for that these other might already know about and handle.

Thanks again.
15 years ago
Thank you both for the replies. I will look at these different possibilities.

But now I have a new question: Where does one find the docs for these packages/classes/methods from Apache?

I searched around for documentation but I can find nothing. I even directly entered "org.apache.taglibs.standard.Functions" into the search field on "apache.org" and none of the hits were documentation. (Well, ok, I did find what appears to be the source code for the Functions class, and I guess source code is really the ultimate documentation, but I was looking for something a little more concise, maybe in javadoc format.)

Thanks for your help!
15 years ago
Hi.

Short version of my question: Is there a convenience method somewhere in the Servlet API that will accomplish the same thing the <c:out escapeXML="true"> does?

Long version: I have some html to output from my servlet that should be output "as is", meaning, for example, the browser should see "<textarea>blahblahblah</textarea>" instead a text area in their browser. Before I embark on looping through my output strings and replacing all my '<' characters with "<", I thought I would ask if there is already a function that does that.

Thanks!
John
15 years ago
Sam Mercs said: >>"This doesn't look like a relative path to me ... Looks like an absolute path starting at root.
(Assuming you are on a Unix like system since where you root starts with a '/')"<<

Thanks for your reply Sam.

Actually I said "relative to my context root", not "relative path". Perhaps you are familiar with the use of ServletContext#getResource(String path), where the dox say "Returns a URL to the resource that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root. "

Fortunately I got some useful replies from other users, and I am on my way. Thank you all for quick and helpful replies!! This forum is great.
15 years ago
Hi.

I have a file in my WEB-INF folder that I wish to open as a File object in my servlet. When I try...



...the path it tries to open is relative to the root of the OS file system, not my web application. So at the moment I open the file like this...



...needlesss to say that's rather ugly and unportable.

So, can anyone inform me how to open a File in my WEB-INF folder using a path that is relative to my context root?

Thanks!

John
15 years ago
Hi.

The following is a snippet of JSP code from question 33 of Sun's SCWCD practice exam, Form 1.



They claim that this snippet is the correct answer to a question. But I believe it is mistaken. Notice the use of "colorAssignment.key" and "colorAssignment.value". They use them as if they were beans in EL, but shouldn't they be colorAssignment.getKey() and colorAssignment.getValue()?

Does anyone believe the above is valid code? And if so, can you explain it to me perhaps?

Thanks!
John