Jacob Fenwick

Ranch Hand
+ Follow
since Apr 28, 2006
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 Jacob Fenwick

Someone created a context-param in the web.xml file with a param-name with a name of app.version. When I try to use ${initParam.app.version}, it won't let me access it, but if I go in and change the . to and _, it works. Is there a way around needing to change the variable name?

Is there a specific for web.xml somewhere that specifies that you can't use . in param-name's that I could point to so I can enforce this standard?
11 years ago
JSP
Many thanks Ulf, I completely forgot about the security manager.
11 years ago
This might not be the right forum to ask this question, as it seems to span multiple problem areas, but I wasn't sure where to post it.

I'm having trouble creating a file from inside a servlet.

I'm using Tomcat5.5 on Ubuntu 6.10.

I'm trying to create a file from inside a servlet:

File auditLogFile = new File(getInitParameter("audit.log"));

When I get to this line, this is the error that is thrown:

SEVERE: StandardWrapper.Throwable
java.security.AccessControlException: access denied (java.io.FilePermission /var/log/tomcat5.5/audit_log.log read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
at java.security.AccessController.checkPermission(AccessController.java:427)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
at java.io.File.exists(File.java:700)
at org.test.util.Init.init(Init.java:121)
...

Now, I have previously created this file and given it the same permissions as other files that Tomcat generates:

-rw-r--r-- 1 tomcat5 nogroup 2 2007-01-19 17:21 audit_log.log

Compared to:

-rw-r--r-- 1 tomcat5 nogroup 138259 2007-01-19 17:24 catalina_2007-01-19.log

The second log file is one that Tomcat generates itself, and so I copied the permissions from that.
What else could be causing this?

Thanks,
Jacob
11 years ago
Just in case anyone ever runs into this problem again, it turns out that I was sending too much information to the page, so when the error was thrown it just dumped out whatever was in the buffer at the time. To fix this, I increased the buffer size of the page.

11 years ago
JSP
Ok, here is the code for the tag. In the Tomcat dump I see "Throwing exception in MappingViewTag.java" printout but I don't see the JspException error, and I don't get the JspException showing up in the JSP page. Instead, the jsp page that calls this tag abruptly cuts off half the html of the entire page. However, the cutoff point seems to be arbitrary, I can find no relationship between where the page is cut off and this tag, it cuts off the page in the middle of some different tag. Very bizarre.



[ November 22, 2006: Message edited by: Jacob Fenwick ]
[ November 22, 2006: Message edited by: Jacob Fenwick ]
11 years ago
JSP
Sometimes when a tag inside a jsp throws an exception, I don't get the exception. Instead, it just cuts off the page at some strange, arbitrary place.

Example: I have a tag that throws a JspException from its doTag function. It throws this JspException when it catches an exception from another piece of code. Now, when I have a Jsp that is reaching this error state, but instead of getting the JspException, the page is getting cut off. I know the JspException is being thrown because I am using a System.err.println.

The question is, why is this happening, and what the heck do I do?
11 years ago
JSP
Can I declare .tag files inside a .tld file stored in /WEB-INF/tld, or is it absolutely necessary to declare them in /META-INF/?

I tried declaring a tag file in an existing .tld file stored under WEB-INF like this:



But when I try to compile it says:

C:\workspace\foo\build.xml:346: org.apache.jasper.JasperException: file:C:/works
pace/foo/webroots/common/foo/update/update.jsp(89,12) No tag "savecancelb
uttons" defined in tag library imported with prefix "foo"
11 years ago
JSP
Nevermind, someone figured it out... If it's in a hashmap, and I have the list of ids, just loop through the list of ids and use those to pull the correct value out of the hashmap.
11 years ago
That's true, I suppose I should have explained it in terms of a hashmap to cut down on wording.

A more clear question is: Is there a way to get an ordered entrySet from a hashmap, where the ordering is based on some non-natural ordering of the keySet?
[ October 12, 2006: Message edited by: Jacob Fenwick ]
11 years ago
I have an unsorted, two dimensional array that contains a key value pair. I also have a sorted one dimensional array that contains the keys in their order. Like so:



Now, the ordering in the sorted array is probably NOT a natural ordering.
I want to sort the unsorted 2d array based on the sorted 1d
array.
Is there a way built into java to do this? I'm researching using a Collection with a Comparator. I'm not knowledgable enough to immediately have a solution, perhaps someone else has dealt with this before?
11 years ago
Thanks Bear.
I have read it. It's a good article.
I've managed to convert a lot of code from "model-less" architecture to model 1. I'm at the point now where I'm grappling with converting to model 2.
11 years ago
The reason I'd want to use a servlet is because the process I want to use requires a parameter from the web.xml file, and I'd rather store it as an init-param than a context param.
Clarification: This is some fileupload code. I want the code to be reusable. The way I want it to be reusable is that I want to create numerous fileuploads, each by instantiating the same code, but by changing the data in the web.xml file so that it decides where the file is saved based on an init-param in the servlet. That's why I'd want to use an init-param instead of a global context-param.
However, I also need to execute that javascript markup. I don't know of a way to embed a servlet inside a jsp, so I was trying to do it the other way, storing the markup inside the servlet.
[ October 03, 2006: Message edited by: Jacob Fenwick ]
11 years ago
I currently have some code in a jsp that I'd like to move into a servlet. The only problem is that the jsp contains some javascript that I'd like to execute. The body tag has an onload call to this function:

Is it possible execute this from inside a servlet, or should I just move the code into a regular class and keep using the jsp to call it?
11 years ago
Er... nevermind. It helps to read FAQs, heh.


Why does FileItem.getName() return the whole path, and not just the file name?
Internet Explorer provides the entire path to the uploaded file and not just the base file name. Since FileUpload provides exactly what was supplied by the client (browser), you may want to remove this path information in your application. You can do that using the following method from Commons IO (which you already have, since it is used by FileUpload).

String fileName = item.getName();
if (fileName != null) {
filename = FilenameUtils.getName(filename);
}


11 years ago
JSP
I've built a fileupload jsp using Apache Commons fileUpload and I want to get the original filename of an uploaded file.
I put the file into a FileItem object and use the getName function. When I'm in Firefox it works perfectly, as it gets just the name and not the path. However when I'm in IE it uses the entire path of the file as the name. I want it to work the way it does in Firefox, I want to get only the name and not the path. Has anyone encountered this problem, and if you did, how did you solve it?
This is not necessarily specific to the Apache Commons fileUpload, I imagine the problem of stripping a path out of a filename is something people encounter often.
11 years ago
JSP