Gordon Jenkinson

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

Recent posts by Gordon Jenkinson

I'm using Tomcat 4.0 and when I update my class files I have to restart the server before they are active. My JSPs are fine as they are recomplied whenever they are changed.
Is there a way to force tomcat to reload classes without having to restart the server?
Thanks
22 years ago
I'm using Tomcat 4.0 and when I update my class files I have to restart the server before they are active. My JSPs are fine as they are recomplied whenever they are changed.
Is there a way to force tomcat to reload classes without having to restart the server?
Thanks
22 years ago
JSP
Would something like this work. I've not tried this out but I don't see why it wouldn't work.
<%@ page errorPage="error.jsp?curpage=thispage.jsp" %>

Then you can get the pagename in by getting the parameter from the error page.
22 years ago
JSP
You may also want to erase the following keys HKEY_CLASS_ROOT/Oracle* too.
22 years ago
If TNSPING does not work it could mean that there is no listener running on the server. The reason you can get in using SQL*Plus is probably due to the fact that Oracle is running locally and the conenction is via IPC (Inter-Process communication) not SQL*Net.
I assume you are using a host string something like the following.

jdbc racle:thin:@hostname:1521 BNAME
This will require an Oracle listener on port 1521 on the host machine.
To check if a listener is running you can type 'lsnrctl status' at the command line and it should show you a list of databases and the ports it's listening on.

HTH
22 years ago
Post the code or a more detailed example. It's not clear what you are trying to do.
A type does not contain data unless you fetch into it. You will only get an invalid column name error if you have an invalid column name error if the column name does not exist in a table.
22 years ago
You need to create a shell script that looks like this.
sqlplus user/password@dbname <<EOF
execute stored_procedure_name;
EOF
Then just schedule the script in cron.
Gordon
22 years ago
You need to add the jar file to your project in Jdeveloper. Under project settings development/ libraries you'll need to add your jar file as a new library and include it in the project.
Once you've done this Jedeveloper will should look after the rest.

HTH
Gordon
22 years ago
You'll need ot edit your registry and remove all Oracle entries, then re-install Oracle. You can try editing the entries but you'll need to be sure what your doing.
To remove Oracle
1. From your start menu choose Run.. and type regedit
2. In regedit select HKEY_LOCAL_MACHINE and then software then Oracle.
3. With the Oracle entry selected hit delete and confirm.
4. Shutdown regedit.
5. Delete the Oracle directory from your hard drive. I assume you have no database you need to backup or that you have it backed up.

Now you can do a fresh Oracle Install.

This procedure assumes that you have no other Oracle products on the machine or that you can re-install them after you remove them.
One other suggestion is to export your registry before you do any deletes. However, I would be very careful restoring backed up registries as they can cause more harm if you are not sure exactly what you're doing.

There may be a safer way to do this but this way has worked for me many times on NT and 2000.
HTH
Gordon.
22 years ago
There's a great example of this in Professional JSP by Wrox ISBN1861003-62-5. Although this is the old one it's got stuff in there that's not in the 2nd edition. If you look at chapter 5 JSP Sessions it has an example that does exactly what you want without the restriction from multiple machines, however that would be easy to add.
From this example you can give them the option to stay logged in at the other machine or to invalidate the sesison on the other machine.
Unfortunatley I don't have the code handy but you can find it at
ftp://ftp.wrox.com/professional/3625/3625.zip.
Briefly this is how it works.
When a user logs in a User bean is instatiated with the users name and ip_address ( request.getRemoteHost() ) this is then stored in an application level bean along with the session.
If the user tries to log in again you can check to see if the user/IP combination is stored and if it is then you can either invalidate the other session ( session.invalidate() ) or not allow the login. Using this method you can also stop multiple users logging in from the same IP too.
The other benefit of this is that you can use the application level bean as a way of monitoring who is logged on.
HTH
Regards,
Gordon
22 years ago
JSP
Here's an example of how I've implemented it and it seems to works as you want it to.
********login.jsp *******
<%@ page import="com.mwp.*" errorPage="error.jsp" %>
<% String message = request.getParameter("message");
if ( message != null ) {
%>
<p><%=message %></p>
<% } %>
<b>Login</b></font></p>
<table width="41%" border="1" align="center" bordercolor="#000000">
<form action="loginCheck.jsp" method="POST">
<tr>
<td height="35" bgcolor="#9999FF" width="18%"><font face="Verdana, Arial, Helvetica, sans-serif">Username</font></td>
<td height="35" bgcolor="#CCCCFF" width="82%">
<input type="text" name="username">
</td>
</tr>
<tr>
<td bgcolor="#9999FF" width="18%"><font face="Verdana, Arial, Helvetica, sans-serif">Password</font></td>
<td bgcolor="#CCCCFF" width="82%">
<input type="password" name="password">
</td>
</tr>
<tr>
<td colspan="2" height="35">
<div align="center">
<font face="Verdana, Arial, Helvetica, sans-serif">
<input type="submit" name="Submit" value="Login">
</font></div>
</td>
</tr>
</form>
</table>
</HTML>
</BODY>

*************** loginCheck.jsp **************
@ page language="java"
import="com.mwp.*, java.util.*"
errorPage="error.jsp" %>
<jsp:useBean id="loginBean" scope="page" class="com.mwp.Login" >
<jsp:setProperty name="loginBean" property="*"/>
</jsp:useBean>
<jsp:useBean id="dbm" scope="page" class="com.mwp.DatabaseManager" >
</jsp:useBean>

<jsp:useBean id="monitor" scope="application" class="java.util.HashMap"/>
<%
if ( loginBean.getUsername().length() == 0 ) {
String display = "login.jsp?message=PLease Enter Username and Try Again";
}
if ( loginBean.getUsername().length() == 0 ) {
String display = "login.jsp?message=Please Enter password and Try Again";
}
String display = "login.jsp?message=Invalid Login. Try Again";
User user = loginBean.authenticate(dbm.getConnection(session));
if (user != null) {
user.setIpAddr(request.getRemoteHost());
// Got user. Now do they already have a session?
if (monitor.containsKey(user)) {
HttpSession oldSession = (HttpSession)monitor.get(user);
oldSession.invalidate();
monitor.remove(user);
}
session.setAttribute("user", user);
monitor.put(user, session);
System.out.println("Assigned new session for: " + user);
session.setMaxInactiveInterval(900);

display = "customerSearch.jsp";
}
%>
<jsp:forward page="<%= display %>"/>

***************************************

The a session attribute "message" is used to pass the reason for the failure back to the Login.jsp page. The login bean is used to get the userId and password.
HTH
Gordon
22 years ago
JSP
Thanks Graham, I suppose what I'm trying to do is model my application so that I can use these objects independently of a database. Your solution looks like a good alternative but makes the DatabaseManager more than it should be. Is this your standard approach to JSP and database development. Does your database manager not get very complex as the number of objects you need to save gets large?
I suppose either way I need to pass something between the two. I Either pass the object to the DatabaseManager or I pass a connection to the JavaBean.
On the session level db connection your point is well taken. I plan to modify the DatabaseManager later to work as an application level connection pool. This method allows me to start out with the basic objects in place and implement connection pooling later.
It's beginning to look like the answer to my question is no.
Thanks again for another alternative. I'm not sold on it yet as I like the idea of keepeing the save and retrive logic in the bean. It's seems closer to the idea of an Entity EJB with bean managed persistence. Maybe I should make the leap to EJBs instead.
Cheers

Gordon
22 years ago
JSP
Unfortunately that won't solve it as I have multiple beans active at one time witin a page.
Thanks for the response.
Gordon
22 years ago
JSP
Hi,
I'm relatively new to JSP and Java and have a question which has been bugging me and I can't seem to find a good solution.
I use a javabean to store customer information entered on a JSP page. This information is then validated and stored in a database. Currently I'm using a session level bean instantiated in the JSP to manage the database connection. This means (or does it, this is my question) that I have to pass the session as a parameter to the save() method of the Customer bean so that it can then get the database connection.
Is there a way for the bean to get it's session context without passing it to a method.
My code currently looks something like this.
JSP Page ***************************
<jsp:useBean id="customer" scope="page" class="com.mwp.CustomerDetails" >
<jsp:setProperty name="customer" property="*"/>
</jsp:useBean>
<jsp:useBean id="dbm" scope="page" class="com.mwp.DatabaseManager" >
</jsp:useBean>
<%
String display;
String message = null;
HashMap v = customer.validate(dbm.getConnection(session));
session.removeAttribute("validation");
if ( v.isEmpty() ) {
try {
customer.save(dbm.getConnection(session));
session.setAttribute("message",message);
String custId = customer.getCustomerID();
session.setAttribute("custId",custId);
session.removeAttribute("customer");
display="customerAdded.jsp";
} catch (SQLException e) {
session.setAttribute("message",e.getMessage());
session.setAttribute("customer",customer);
display="customerEdit.jsp";
}
} else {
message = "Errors in form see below for details";
session.setAttribute("message",message);
session.setAttribute("customer",customer);
session.setAttribute("validation",v);
display = "customerEdit.jsp";
}
%>
<jsp:forward page="<%= display %>"/>
DatabaseManager Bean code *************************
public class DatabaseManager
{
String driverName;
String dbURL;
String dbUser;
String dbPassword;
String session;
public DatabaseManager()
{
// Default database parameters here.
driverName = "oracle.jdbc.driver.OracleDriver";
dbURL = "jdbc racle:thin:@192.168.0.4:1521 ELLXP8I";
dbUser = "mwp";
dbPassword = "mwp";
}
public String getDriverName()
{
return driverName;
}
public void setDriverName(String newDriverName)
{
driverName = newDriverName;
}
public String getDbURL()
{
return dbURL;
}
public void setDbURL(String newDbURL)
{
dbURL = newDbURL;
}
public String getDbUser()
{
return dbUser;
}
public void setDbUser(String newDbUser)
{
dbUser = newDbUser;
}
public String getDbPassword()
{
return dbPassword;
}
public void setDbPassword(String newDbPassword)
{
dbPassword = newDbPassword;
}
public String getSession()
{
return session;
}
public void setSession(String newSession)
{
session = newSession;
}
public Connection getConnection(HttpSession session)
throws Exception, SQLException
{
Connection conn = (Connection)session.getAttribute("conn");
if ( conn == null ) {
Class.forName(driverName);
conn = DriverManager.getConnection(dbURL,dbUser,dbPassword);
session.setAttribute("conn", conn);
}
return conn;
}
}
Customner Java bean save method. *************************
public void save(Connection conn) throws SQLException
{
String sql = null;
PreparedStatement insertStmt;
conn.setAutoCommit(false);

if (getUpdateStatus().equals("NEW")) { // It's a new Customer.
sql = "INSERT INTO CUSTOMER"
+ "( CustomerID, UserID, Password, BusinessName, FirstName, Surname, MiddleName, Salutation, Sex, DOB, DefaultAddressID, CustomerTypeID)"
+ " VALUES (?,?,?,?,?,?,?,?,?,TO_DATE(?,'DDMMYYYY'),?,1 )";

try {

insertStmt = conn.prepareStatement(sql);

// Get sequences
customerID = OracleSequence.getNextVal(conn, "CUSTOMER_SEQ" );
mailingAddressID = OracleSequence.getNextVal(conn, "ADDRESS_SEQ" );
billingAddressID = OracleSequence.getNextVal(conn, "ADDRESS_SEQ" );

...
}
Any ideas would be appreciated.
Thanks
22 years ago
JSP