Sam Gardner

Ranch Hand
+ Follow
since Jul 22, 2008
Merit badge: grant badges
For More
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 Sam Gardner

Hey Guys -

Currently, I have a bunch of "Survey" objects that I use to store various parameters of the surveys that my web application displays. These are instantiated by reading external survey definitions (currently MySQL tables, but eventually I'd like to move them to xml files or something along those lines. The key is that they are not deployed *with* the web application, and can be quickly added by non-programmers and accessed by the application without redeploying it). As it stands right now, I'm currently creating a new one of these objects by reading the parameters out of it every time I need some information about each survey (generally on each new "page" of the survey).

This really isn't necessary, as these definitions generally stay consistent throughout a user's session, so I'd like to figure out a way to initialize them once at login, and just read the parameters (the parameters aren't very huge at all - the data takes up about 400kb at worse on the tables) out of memory rather than having to hit the external data source on every page.

To accomplish this, I've tried just sticking them in the session by doing session.setAttribute(survey + "survey_parameters", surveyObject), but since Surveys are not Objects, there are all sorts of class mismatch issues.

I feel like this really shouldn't be that difficult, and that I'm missing something obvious, but I can't for the life of me figure out what it is. It would be much appreciated if someone could help me out.

14 years ago

Sebastian Janisch wrote: However, it's considered bad practice to do that kind of stuff in a JSP.

What would a better practice be?

I need to read the words specified in the files into a Vector or array for display, so I need to specify the location of those files somewhere.

Wouldn't that necessitate getting the context path at a minimum? From my understanding, I can't use the request implicit object since it will return null if deployed in a .war.
14 years ago

Sebastian Janisch wrote:request.getResourceAsStream() should be what you are looking for...

Alright, Eclipse is claiming that getResourceAsStream() is not defined for the request object. Some googling revealed that it is a method of ServletContext objects though.

Somehow I've managed to avoid this in my JSP career, so does anyone mind telling me how to get the current ServletContext so I can use this getResourceAsStream method?

14 years ago
Hey All -

The project that I am currently working on requires that I load some values from a few textfiles. I've gotten it working with scanners, using request.getRealPath("/"), but it is deprecated and from this thread it doesn't appear as if that is the correct way to go about it, since when I deploy in a .war, the request.getRealPath() method will return null.

Does anyone have any guidance on how I might be able to do it correctly, in a way that will work fine with a .war? For refrerence, the "parent" JSP page is in a folder called "Survey_1" and the text files that need to be read in are in a child folder of "Survey_1" called "Practice", so the relative path would be "practice/filename". Using the normal File constructor to pass in that doesn't work for some reason.

Thanks for any help!
14 years ago

Bear Bibeault wrote:To a JSP, anything that's not a JSP element is just template text. It could care less...

Ah, well, now that I think about it it makes sense.

Getting the formatting right on the scriptlet is proving to be a royal PITA though.

Bear Bibeault wrote:Eric's point is if you can use the scriptlet expression in one place in the JSP, why can't you use it elsewhere?

(Hint: the answer is there's no reason).

Oh, heh.

I didn't even think of emitting JavaScript with the JSP expression - too meta for me I guess. I'll give it a shot - thanks for the help.

Eric Pascarello wrote:How is it any different setting it in the meta refresh as it is setting the JavaScript in the same page?


Well, this is basically the JSP code I have now:

If you can tell me how to access that session variable, only add a timeout if it isn't null (or an invalid value that I can set or something like that), and add the timeout for the number stored in the session variable, then I can add the window timeout. Since JavaScript is client-side I couldn't see an easy way to access the server-side session variables.

Bear Bibeault wrote:Why not just use window.setTimeout()?

Well, I can't figure out how to dynamically set the number of miliseconds while doing that.

Right now, the refresh rate is set via user editable config files (this project is designed so that parts can be added without someone having to modify the application itself). As far as I know, I can't easily get access to those values (currently stored in session variables) from JavaScript, whereas its very easy to access them from the JSP code (and hence, easy to dynamically emit a meta tag with the correct parameters).
Hey Guys -

I've come up with a way that I can do form submission after a specified number of seconds that is reliable enough for our purposes in Firefox. Unfortunately, the technique fails in all other browsers that I've tested and I can't seem to figure out why.

Refresh Code (the timer checks/values are all set by JSP - checking the page source before the form submission shows the same code in all browsers, so I think I can rule out my JSP as the culprit here):


HTML (if timing is needed):

HTML form definition:

Basically, I set a timer variable that determines whether a meta refresh tag should be placed, and what its value should be. This is important because I need the timer to use externally specified times. Since I know that the page is going to refresh (and hence, trigger the onunload event), I warn users not to use back/forward/refresh commands, and have the onunload event trigger a form submission. For some reason, in Safari, Chrome, and IE, the code on the submitted form's target page never executes, even though the alert in the submitForm() function is triggered.

Does anyone have any idea what might be going on here? My method seems pretty simple, and I'm having a hard time seeing what the issue might be.

Thanks for any help.
Hey Guys -

I have a timed page that I need to use to submit a form upon the end of a specified time period.

The usage would be: User visits page, 90 seconds later all form data is submitted and user is redirected to next page.

The user is well aware that the page they are on is timed (its for a web-only experiment), so I'm not too worried about "unfriendly" browser behavior on this page.

Ideally, I'd like to avoid using JavaScript (some of our targeted users are using no-script for various reasons, but if its the only way, so be it), and would also like to avoid just passing variables through the URL (to cut down on the possibility of spoofing). It is easy enough to set a META refresh tag to do the redirecting, but at the end of the time period I need some way for the response header to be set as if the submit button was clicked, whether or not it actually was.

Thanks in advance for any thoughts you might have.

Eric Pascarello wrote:You could also just make it an image.


Ah, but for the number of separate words that have to be displayed in my project, this way is much less resource-intensive.

Also, this ensures that the text will scale up nicely as you zoom and otherwise behave like normal text.
Alright, just in case anybody runs across this in the future, I came up with a decent workaround.

Any "button" input type is unsearchable via Ctrl-F by any browser I've found - Safari v4, IE 6/7/8, FF 3.5, Chrome.

Using CSS can make the background of the field blend in (set a border of 0px to get rid of the "drop" effect), and you can change the text attributes to make the text appear completely normal in FF (other browsers seem to force the "graying" of the text.

If you set the disabled attribute it even gets rid of the "click motion", but it grays the text in IE and Safari/Chrome. Other than that, it looks surprisingly decent, even on IE 6.

Bear Bibeault wrote:No. And you shouldn't -- it's not your browser.

What you might want to consider is popping the page up in a new window sans menu and capturing the keystroke.

Alright, that's what I kind of thought. Thanks for the help.
Hi Guys -

This is kind of a shot in the dark, but does anyone know any way that I can disable the ctrl+f functionality in a browser?

We are implementing a timed survey that entails reading columns of words and selecting ones with certain properties (ie, "please select all words with the letter 'a' in them"), and users being able to search for them would defeat the purpose of what we are trying to study.

If nothing else, I'll just make separate image files of each word, but that would be a resource hog and a pain in the butt to set up.

Thanks for any help!
Whoops, figured it out already.

Probably should have looked at the documentation earlier.

Thanks anyway.
14 years ago