Brett B Doehr

Greenhorn
+ Follow
since Jun 04, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Brett B Doehr

Wait a minute...so you're saying that things like ejbPostCreate and setEntityContext actually have a purpose and aren't intended to always just be empty required functions?!
Thanks for pointing out what should have been obvious. Although it should have been creating a new bean in the situation I was in, using setEntityContext should certainly work, and ejbPostCreate might as well.
Well, it appeared to be a problem with doing it in the ejbCreate. Must be something peculiar to the ObjectSpace Voyager EJB container, since the J2EE tutorials seem to indicate it should work. Anyway, I moved my DB stuff from the ejbCreate to a business method and it now works.
--Brett.
I think it should be possible to obtain a Connection from a JDBC DataSource in an ejbCreate, doing the below:
// Resources.java
public class Resources {
private static DataSource dataSource;
static {
try {
dataSource =
(DataSource) new InitialContext().lookup("java:comp/env/jdbc/intersys");
} catch (Exception e) {
e.printStackTrace();
}
}
public static Connection getDBConnection() throws SQLException {
return dataSource.getConnection();
}
}
// EJB class
...
public void ejbCreate(String name)
throws CreateException {
Statement stmt = null;

try {
// This next line causes an SQL exception!!
stmt = Resources.getDBConnection().createStatement();
...
}
}
However, the above line results in:
java.sql.SQLException: Connections can only be accessed during a transaction
The bean is installed in the ObjectSpace Voyager server with transactions Required, so it should create a transaction if no transaction exists. Any thoughts on why the above doesn't work?
--Brett.
If you want to set some values on a page that get propagated but don't want them displayed like a "text" object would be, try:
<input name="myVariable" type="hidden" value="someValue">
You get then do the same kind of get that you would if the type was "text" instead of "hidden", but the input field won't be displayed. Hopefully this is what you wanted.
--Brett.
23 years ago
To reiterate Peter's point, are you sure that you have exact matches between your request parameter names and the JavaBean variable names, and the appropriate set/get methods? Maybe you can post more of your code. For example, if your request came from a page that had:
<input name="fooBar" value="" type="text">
then your JavaBean class should have something like:
public class UserProfileBean {
private String fooBar;
...
public String getFooBar() {
return fooBar;
}
public void setFooBar(String newBar) {
fooBar = newBar;
}
}
23 years ago
Jonathan,
Individual class files go into WEB-INF/classes. However, .jar and .zip files go into WEB-INF/lib. Try creating WEB-INF/lib and putting your .jar file in there.
--Brett.
23 years ago
It also depends on where your servlet classes are located. If they are .class files, store them in the/WEB-INF/classes directory relative to your HTML/JSP pages. If they are in .zip or .jar files, store them in the /WEB-INF/lib directory.
If they are in another directory that is in your CLASSPATH, they
will be found initially but will not be dynamically reloaded. (I know, I wasted a lot of time on this one. <sigh> )
--Brett.
23 years ago
There are some good instructions from the Jakarta FAQ on installing Tomcat on a Windows NT platform:
http://jakarta.apache.org:8080/jyve-faq/Turbine/screen/MainMenu/action/SetAll/screen/DisplayQuestionAnswer/topic_id/102/question_id/693/
One thing worth mentioning is that its link to Apache is broken. If you need to download Apache for Windows, go to:
http://httpd.apache.org/dist/httpd/binaries/win32/
Then for Apache setup, try: http://httpd.apache.org/docs/windows.html
Good luck!
--Brett.
23 years ago
As far as helpful sites (and JavaRanch is a great one), check out:
http://developer.java.sun.com/developer/onlineTraining/JSPIntro/
http://developer.java.sun.com/developer/onlineTraining/Servlets/
These on-line tutorials are fairly helpful, although I think the servlet one is at least a version out of date. But they walk you through setting up Tomcat and provide complete solutions for exercises, which can be helpful for beginners.
I also have a book that's not too bad, "Java Developer's Guide to Servlets and JSP" from Bill Bordgen (or something like that).
--Brett.
P.S. I hope this doesn't make me "erudit".
23 years ago
This might be a little off topic, but I have a somewhat related problem. I'm writing a login application that moves through a set of JSPs, and launches an applet on successful login. The concern is that if someone successfully logs in and runs the applet, then logs out, someone else could come up to the computer if the browser is left running and use the Back and Forward browser buttons to essentially relogin. It doesn't appear that the JSPs are re-executing when going back to a page using the browser buttons, based on some print statements I have. On logout I do a showDocument back to the initial login page, but the applet will re-execute if you use the Back button.
Is there a way to catch the browser Forward and Back button clicks in the JSP, so I can try to prevent someone reloading a successful login page? I tried the "no-cache" code from the thread that Maha Anna mentioned, but as I said above, it seems like the files aren't uncached (even when using ?dummy=123) since it's not really executing my JSPs to move between pages.
Thanks for any assistance/suggestions.
23 years ago
Either syntax should work. The syntax I normally use is:
<jsp:useBean class="FooBean" id="foo" scope="session">
</jsp:useBean>
However, the other syntax will also work:
<jsp:useBean class="FooBean" id="foo" scope="session" />
As far as the set and get property tags, put them between
the useBean tags if you want them to execute only when the
bean is first instantiated. If the bean is reused, either
on that page or another one, any set or get property tags
will be ignored. For good general info on useBean, go to:
http://developer.java.sun.com/developer/onlineTraining/JSPIntro/contents.html#JSPIntro11
It's hard to be sure what's causing your error without seeing
the line of code it referenced. My guess it that you have a
declaration statement without a semi-colon at the end:
<%! int i=0 %> instead of <%! int i=0; %>
--Brett.
23 years ago