Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Data Graham
Dec 28, 2009

📈📊🍪😋



Hey guys, I need wiser and more patient heads than my own to help me with a Java/JSP problem that keeps cropping up.

I have openjdk8 installed (FreeBSD). I'm running tomcat8 like this, which is the default configuration installed by the tomcat package:

/usr/local/bin/jsvc -java-home /usr/local/openjdk8 -server -user www -pidfile /var/run/tomcat8.pid -wait 30 -outfile /usr/local/apache-tomcat-8.0/logs/catalina.out -errfile &1 -classpath /usr/local/apache-tomcat-8.0/bin/bootstrap.jar:/usr/local/share/java/classes/commons-daemon.jar:/usr/local/apache-tomcat-8.0/bin/tomcat-juli.jar -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/usr/local/apache-tomcat-8.0/conf/logging.properties -Djava.endorsed.dirs=/usr/local/apache-tomcat-8.0/endorsed -Dcatalina.home=/usr/local/apache-tomcat-8.0 -Dcatalina.base=/usr/local/apache-tomcat-8.0 -Djava.io.tmpdir=/usr/local/apache-tomcat-8.0/temp org.apache.catalina.startup.Bootstrap

I have a JSP page with this in it:

code:
<%@ page import="java.awt.*"%>
<%@ page import="javax.swing.*"%>
But periodically, seemingly after I reboot or tinker with the install or anything, I get this:

code:
javax.el.ELException: The package [java.awt] could not be found
(Same thing with javax.swing if I comment the awt line out.)

I hosed with this a little while ago and swapped out libraries and things and it mysteriously started working, but then last night it broke again (I suspect after I rebooted, implying that something changed in the tomcat startup parameters).

Thing is, I don't have any idea where to look to see why it's not finding these libraries. I poke through /usr/local/openjdk8 and nothing looks familiar. People discussing problems like this seem to usually point to JAVA_HOME not being set properly, but I've got it set in my (root) environment, and -java-home is being specified in the tomcat startup options.

Can someone please help me understand what's going on here? Thanks.

Adbot
ADBOT LOVES YOU

Data Graham
Dec 28, 2009

📈📊🍪😋



Here's a more focused demo of the above:

code:
<%@ page import="java.awt.*"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:set var="blah" value="foo" />
blah: <c:out value="${blah}" />
If I remove the java.awt line, it works fine, and prints out "blah: foo". But with that line in there, I get the error, seemingly triggered on the <c:out> line.

code:
org.apache.jasper.JasperException: An exception occurred processing JSP page /test2.jsp at line 6

3: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    
4: 
5: <c:set var="blah" value="foo" />
6: blah: <c:out value="${blah}" />


Stacktrace:
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:469)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

javax.el.ELException: The package [java.awt] could not be found
	javax.el.ImportHandler.importPackage(ImportHandler.java:135)
	org.apache.jasper.runtime.PageContextImpl.getELContext(PageContextImpl.java:948)
	org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:933)
	org.apache.jsp.test2_jsp._jspx_meth_c_005fout_005f0(test2_jsp.java:164)
	org.apache.jsp.test2_jsp._jspService(test2_jsp.java:112)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Note that this also works fine:

code:
<%@ page language="java" import="java.util.*,java.io.*,java.sql.*,javax.sql.*,javax.naming.*,java.security.*,java.math.*" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:set var="blah" value="foo" />
blah: <c:out value="${blah}" />
But not this:

code:
<%@ page language="java" import="java.util.*,java.io.*,java.sql.*,javax.sql.*,javax.naming.*,java.security.*,java.math.*,java.awt.*" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:set var="blah" value="foo" />
blah: <c:out value="${blah}" />
So it seems like specifically java.awt and java.swing that break <c:out>, or something? WTF.

Data Graham
Dec 28, 2009

📈📊🍪😋



Yeah, I do need the graphics libs; I'm directly using stuff like ImageIcon.

I'll check to see if there's a headless version that I installed by mistake or something.


E: Not that I can tell. There's a /usr/local/openjdk8/jre/lib/amd64/libawt_headless.so in the install; I'm not sure what that tells me though.

Data Graham
Dec 28, 2009

📈📊🍪😋



There are installable ports for openjdk8 (which includes a jre), and openjdk8-jre; I only had the former installed, now I'm trying the latter.

Both have (in different places):

code:
# ls -l /usr/local/openjdk8/jre/lib/amd64/
total 3078
-r-xr-xr-x  1 root  wheel    9268 Mar  6 03:00 jexec
drwxr-xr-x  2 root  wheel       3 Mar  9 09:46 jli
-r-xr-xr-x  1 root  wheel   16146 Mar  6 03:00 jspawnhelper
-r--r--r--  1 root  wheel    1624 Mar  6 03:00 jvm.cfg
-r--r--r--  1 root  wheel   11806 Mar  6 03:00 libattach.so
-r--r--r--  1 root  wheel  682957 Mar  6 03:00 libawt.so
-r--r--r--  1 root  wheel   34205 Mar  6 03:00 libawt_headless.so
-r--r--r--  1 root  wheel  424170 Mar  6 03:00 libawt_xawt.so
-r--r--r--  1 root  wheel   22230 Mar  6 03:00 libdt_socket.so
-r--r--r--  1 root  wheel  419732 Mar  6 03:00 libfontmanager.so
-r--r--r--  1 root  wheel  186885 Mar  6 03:00 libhprof.so
-r--r--r--  1 root  wheel  100769 Mar  6 03:00 libinstrument.so
-r--r--r--  1 root  wheel   44489 Mar  6 03:00 libj2gss.so
-r--r--r--  1 root  wheel   17328 Mar  6 03:00 libj2pcsc.so
-r--r--r--  1 root  wheel   76005 Mar  6 03:00 libj2pkcs11.so
-r--r--r--  1 root  wheel    7367 Mar  6 03:00 libjaas_unix.so
-r--r--r--  1 root  wheel  204359 Mar  6 03:00 libjava.so
-r--r--r--  1 root  wheel   34293 Mar  6 03:00 libjava_crw_demo.so
-r--r--r--  1 root  wheel    6510 Mar  6 03:00 libjawt.so
-r--r--r--  1 root  wheel  257923 Mar  6 03:00 libjdwp.so
-r--r--r--  1 root  wheel  201642 Mar  6 03:00 libjpeg.so
-r--r--r--  1 root  wheel   10865 Mar  6 03:00 libjsdt.so
-r--r--r--  1 root  wheel   10193 Mar  6 03:00 libjsig.so
-r--r--r--  1 root  wheel    6767 Mar  6 03:00 libjsound.so
-r--r--r--  1 root  wheel   80437 Mar  6 03:00 libjsoundalsa.so
-r--r--r--  1 root  wheel  364056 Mar  6 03:00 liblcms.so
-r--r--r--  1 root  wheel   41895 Mar  6 03:00 libmanagement.so
-r--r--r--  1 root  wheel  907028 Mar  6 03:00 libmlib_image.so
-r--r--r--  1 root  wheel  102505 Mar  6 03:00 libnet.so
-r--r--r--  1 root  wheel   81812 Mar  6 03:00 libnio.so
-r--r--r--  1 root  wheel   14041 Mar  6 03:00 libnpt.so
-r--r--r--  1 root  wheel   52974 Mar  6 03:00 libsaproc.so
-r--r--r--  1 root  wheel   28228 Mar  6 03:00 libsctp.so
-r--r--r--  1 root  wheel  318870 Mar  6 03:00 libsplashscreen.so
-r--r--r--  1 root  wheel  208532 Mar  6 03:00 libsunec.so
-r--r--r--  1 root  wheel  125226 Mar  6 03:00 libunpack.so
-r--r--r--  1 root  wheel   66959 Mar  6 03:00 libverify.so
-r--r--r--  1 root  wheel   40960 Mar  6 03:00 libzip.so
drwxr-xr-x  2 root  wheel       5 Mar  9 09:46 server
And tomcat is running with -java-home set to /usr/local/openjdk8-jre. But same behavior as before.

Tried running with -Djava.awt.headless=true too.


E: And just to be clear: it only seems to be <c:> that fucks everything up. If I change this one particular <c:set> near the top of the file:

<c:set var="basepath_local" value="${sessionScope.basepath}" scope="page" />

to

<c:set var="basepath_local" scope="page" value="/usr/local/apache-tomcat-8.0/webapps/ROOT" />

Then it all works fine, including the ImageIcon calls and stuff that uses awt/swing.

And it's not because of sessionScope; same thing happens if I use a variable from a different scope.

Data Graham fucked around with this message at 20:03 on Mar 9, 2015

Data Graham
Dec 28, 2009

📈📊🍪😋



Hokay. So what it seems to be doing is trying—and failing, for some unknown reason—to set a variable, but then afterwards whatever was causing the exception recovers its bearings and everything is fine.

I had a <c:catch> around some input validation stuff a little further down the initial page I was working on, which was swallowing the java.awt exception and then allowing the rest of the script to proceed normally, including all the stuff using AWT. That's what was making debugging this thing so confusing.

So here's what works, 100% of the time so far:

code:
<c:catch var="catchException">
    <c:set var="basepath_local" value="${sessionScope.basepath}" scope="page" />
</c:catch>
<c:if test="${catchException != null}">
    <c:set var="basepath_local" value="${sessionScope.basepath}" scope="page" />
</c:if>
:catstare:

Data Graham
Dec 28, 2009

📈📊🍪😋



It's not a servlet, just a plain old JSP. I've never done anything with servlets, and am pretty unclear on what goes into making one. I've been trying to hackishly try tomcat6 to check if that fix is to blame but can't get it running properly.

The page in question is an image uploader. I'm setting various session variables and then calling this JSP via AJAX with a form post. Theoretically the session variables should all be available, and they are, but apparently when the JSP is first being initiated the first JSTL <c:set> tag that refers to an external variable triggers this weird "can't find java.awt" thing. Like, I can <c:set var="foo" value="bar" /> but not <c:set var="foo" value="${bar}" />.

So this also works:

code:
<c:catch var="catchException">
    <c:set var="foo" value="${bar}" scope="page" />
</c:catch>

<c:set var="basepath_local" value="${sessionScope.basepath}" scope="page" />
Which I might as well use just as a band-aid at the top of all my pages. I just hate not understanding things.

Data Graham fucked around with this message at 23:09 on Mar 9, 2015

Data Graham
Dec 28, 2009

📈📊🍪😋



Aha, I see. Thanks, I'll try that.

Data Graham
Dec 28, 2009

📈📊🍪😋



I apologize in advance for this. I wouldn't want my worst enemy to have to stare down the barrel of a keytool question.


Trying to import a newly generated code signing cert from GoDaddy. The file is in .spc format, which I take to mean PKCS#7.

I'm following these instructions, which people seem to be saying are good: https://support.godaddy.com/help/article/4780/java-code-signing-generating-a-csr

But maybe they're written for a different version of java or something, because in steps 3 and 4, the -storepass option seems to require an argument in my version, but they seem to think you can just toss it in there without one. (If I leave it out, it prompts me for the password, which I prefer anyway.)

But I keep getting this:

code:
# keytool -importcert -trustcacerts -keystore keystore.jks -alias codesigncert -file e6c287786fc96d5d.spc 
keytool error: java.lang.Exception: Input not an X.509 certificate
Which is weird, because I can do this:

code:
# keytool -printcert -file e6c287786fc96d5d.spc 
Certificate[1]:
... 
And it lists pages of seemingly accurate information.

I'm not sure what to do from here. Anyone wrestled with this one lately?

Data Graham
Dec 28, 2009

📈📊🍪😋



Nah, it's in the right format; apparently GoDaddy always uses .spc for its files, which are in binary PKCS#7. Which you can clearly infer from their download page:



:hurr:

Turns out I was using the wrong alias name, as I should have been able to figure out from the helpful exception message, I guess.

(Also it seems openjdk has its own ideas about what kinds of options keytool should support, so you use -importcert instead of -import, but -import still works as an alias to -importcert, even though it isn't listed in the options)

Data Graham fucked around with this message at 02:48 on Mar 11, 2015

Data Graham
Dec 28, 2009

📈📊🍪😋



13 year old girls posted:

I knew it was a good move posting here today.

:iamafag:

Data Graham
Dec 28, 2009

📈📊🍪😋



Leave little notes to your future self in your comments!

Data Graham
Dec 28, 2009

📈📊🍪😋



Volguus posted:

Maybe you're right, maybe I am a bad programmer. I have learned over the years to pick my battles, however. Always try to improve, always try to do the right thing, but look at your surroundings, look at what can you do and let some things go if you have to. Change them if you can on the fly, and if you hit a wall ... make your decision then if you want to continue or not. You are sounding like a stubborn little child who's not going to do his homework unless the exact amount of cake is present on the table. No more, no less. And throws a tantrum until the cake arrives on the table. Good luck, is all I can say.

Principle #96: Don't pick your battles. Fight them all.

Probably the single most contentious of these from when I worked there, and it sounds crazy, but the reasoning was that if you allow yourself to tolerate badness on a small level or in something that's only tangentially related to what you're doing, it feeds into lots of other adjacent aspects of what you do. A) it leads you into a mindset where you find it more acceptable to tolerate badness in other areas; B) it leads to you not "thinking like an owner" and to allowing poo poo to persist just because it's not your job; C) it sets a poor example for others, who will learn to accept that some stuff just sucks and isn't worth improving.

Of course not every place is a crazy meritocracy cult, so yeah, you do what you gotta do.

Data Graham
Dec 28, 2009

📈📊🍪😋



How I wish they cold come up with normal names for things, like "propagate" or something.

Data Graham
Dec 28, 2009

📈📊🍪😋



"While I'm at it I'll just fix this bug"

The burned hand teaches best.

Data Graham
Dec 28, 2009

📈📊🍪😋



Elias_Maluco posted:

Its funny to think javscript and java share the "java" word, considering that JS is the complete opposite when it comes to OOP features, variable types and stuff.

More "maddening" than "funny". Literally the only reason it's called JavaScript instead of ECMAScript or LiveScript whatever is that some bright bulb at Netscape decided that because they were shipping the hot new version 2.0 with a Java runtime, the new in-page scripting language Brendan Eich wrote should be co-branded with it.

Data Graham
Dec 28, 2009

📈📊🍪😋



Squashy Nipples posted:

Also, I'm a big fan of the Sams Teach-yourself books. The "Java in 24 Hours" starts off REALLY slow if you already know how to program (it doesn't get into Objects until chapter 10!!!), but it gave me a lot of contextual information about how Java is used, and how it's evolved.
http://www.amazon.com/gp/product/0672337029

Sweet, glad to hear you like those :cheers:

Data Graham
Dec 28, 2009

📈📊🍪😋



Rather not say for :ninja: reasons, but I wrote a couple and tech edited several others.

No Java ones though.

Data Graham
Dec 28, 2009

📈📊🍪😋



I'm still maintaining a massive site that I built all in Perl CGIs in the late 90s.

I'm like three generations of MVC structure ahead in my day job and new projects, but part of me likes keeping the old poo poo around just to remind me how good we have it now.

Data Graham
Dec 28, 2009

📈📊🍪😋



Put some more prints in so you can see which loop it's getting stuck in and why.

Data Graham
Dec 28, 2009

📈📊🍪😋



So when does x change?

Data Graham
Dec 28, 2009

📈📊🍪😋



'Scool, that's why this was a valuable exercise :)

Data Graham
Dec 28, 2009

📈📊🍪😋



Such as not using java?

I actually don't mean that to sound snarky. I'm really wondering: what are the benefits of using Java for web dev, when there are plenty of other stacks available that don't require you to muck around with IDEs or roll your own DAOs? Is the performance benefit that significant? Or is it all about scale, for maintainability of large codebases?

Data Graham
Dec 28, 2009

📈📊🍪😋



For web it's always seemed way more straightforward :shrug: For editing code on remote servers and all.

I'm happy to use an IDE for stuff like iOS, where it's clearly necessary, but it seems like huge overkill for webdev.

Data Graham
Dec 28, 2009

📈📊🍪😋



Well yes, that's how I normally work for any project with significant size. I've just never seemed to need anything more than basic syntax coloring for most stuff, and dependencies don't tend to be much of an issue with sandboxed environments and such.

My happy place these days is Django, but I've built JSP sites and lots of other stuff back to the days of Catalyst and raw Perl and poo poo. At the very least I can agree that JSP's idea of template/scriptlet separation is a horrorshow, but I'm glad there are better ways nowadays that don't mean "you have to write three big boilerplatey class files for every model".

Data Graham
Dec 28, 2009

📈📊🍪😋



I suppose front-to-back or back-to-front depends on how bigendian you are

Data Graham fucked around with this message at 20:28 on Oct 12, 2016

Data Graham
Dec 28, 2009

📈📊🍪😋



Sometimes fate just has it in for you. "release" is a keyword now, but it wasn't back when I first designed the system :doh:

Data Graham
Dec 28, 2009

📈📊🍪😋



In my experience, and I may be completely misunderstanding how it works, but I've spent years trying to make my way through the impenetrable fog of 15-year-old documentation and incoherent developer forum posts, and would love to be corrected, but...

JSP tells you to do database operations and queries in the templating language (EL), i.e. <sql:query> . Which is fine if you just want to do simple queries and loop through the results and spit them out into HTML. But the moment you try to do anything more complex, like I dunno doing some math operations on your query results, or formatting strings, or doing file manipulations, you have to pass that data into the scriptlet space (<% %>). Which is a completely separate world from the EL layer, with its own namespace and its own context and its own everything. And never the twain shall meet.

You can't pass complex variables (like query result rows) to or from scriptlets. The best you can do is read attributes from the pageContext and set them back as attributes into the pageContext after you're done with your scriptlet, which makes for insanely clunky and repetitious code. Or at least I've found no simple way to do it; you have to cast and prep and attribute-pass every individual value separately.

People writing how-tos always say you're never supposed to do any serious complex code in scriptlets; you're supposed to write beans and build DAOs and stuff to feed the templates from the back-end. Which is great, that's how I'd much rather do it, if it weren't a massive amount of code to write in itself. But JSP is very insistent that you do your <sql:query> stuff in the EL layer, not in the back-end. So basically there are two competing philosophies battling it out: simple query magic in the EL template, and full-fledged DAO modeling in the Java layer. And JSP doesn't help you out at all if you're doing the latter; you're basically starting from scratch and may as well use some other MVC framework like Struts or something and forget about the EL templating stuff entirely.

Again, I could be completely missing some huge major piece of the puzzle. But I've been fighting with JSP for one project of mine for years now and it makes me weep every time I want to do something as simple as write my gently massaged query results to a logfile, and I cannot believe anyone would want anyone to go through it the way I have, though for the life of me that's the only conclusion I can draw from the docs/community.

Data Graham
Dec 28, 2009

📈📊🍪😋



Looks like a mixin to me.

Data Graham
Dec 28, 2009

📈📊🍪😋



Database, that's like a spreadsheet right ??

Data Graham
Dec 28, 2009

📈📊🍪😋



Volguus posted:

No, providing options is generally good. No, it does not have to increase the level of technical expertise to use your product. It can, and yes there are horror stories from the 90s software that have gone too far, but it doesn't have to. Removing options is simply an effect of laziness and nothing else disguised under "user friendliness". There is absolutely nothing "friendly" to the user if I dictate how my product should be used. There is 100% friendly if I provide sane defaults and allow the user to customize if/when they feel like it. And is perfectly ok if that "when" is never.

I sure didn't have enough of this argument circa 1997.

Data Graham
Dec 28, 2009

📈📊🍪😋



Yeah PyCharm's got some goofy-rear end ideas of how keybindings and such are supposed to work in macOS. Scrolling and searching in the Terminal pane feels like I'm having a bad dream where I scream but nothing comes out and every button I try to press gets further and further away

Data Graham
Dec 28, 2009

📈📊🍪😋



chippy posted:

That seems to be the thing that people try to do themselves an alarming amount of the time. I worked on a website once that the client had built a good amount of themselves, including some home-rolled crypto and they wouldn't let me touch it.

Who among us has not had this experience.

Some dunning-kruger enthusiast writing his own ColdFusion password hashing algo that is "secure" because it calls a series of obscurely-named functions in various different files named after characters from his favorite book so it will be impossible for a hacker to untangle

"Don't use a standard crypto library, that's just what they'd be expecting"

Adbot
ADBOT LOVES YOU

Data Graham
Dec 28, 2009

📈📊🍪😋



Still pisses me off. What a dumb rear end in a top hat move

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply