I have tried the same application by creating a
jsp page one action class one form bean and another
java bean as in your case to access the database and it is running absolutly fine. I cannot figure out why it cannot work out for you. OK. I m posting my code find out the problem urself.
LogonAction.java
****************
package ideas;
import javax.servlet.http.*;
import javax.servlet.*;
import org.apache.struts.action.*;
import javax.sql.*;
import java.sql.*;
public class LogonAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest req, HttpServletResponse res)
{
Logon l = (Logon)form;
String Uname = l.getUname();
String Passwd = l.getPasswd();
if(Uname.equals("ADMIN")){
if(Passwd.equals("admin")){
return mapping.findForward("Logon");
}
}
bean BEAN = new bean();
try{
BEAN.create(Uname);
}catch(Exception e){System.out.println(e);}
return mapping.findForward("LogonError");
}
}
Bean.java
*********
package ideas;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
public class bean {
public void create(String name) throws Exception{
Context ctx = new InitialContext(System.getProperties());
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/struts");
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select max(IND) from struts_index");
rs.next();
int index = Integer.parseInt(rs.getString(1));
System.out.println("index::"+index);
stmt.executeUpdate("insert into struts_index values ("+ ++index +",'"+name+"')");
stmt.close();
con.close();
}
}
Struts-config.xml
*****************
A Part of my Struts-Config.xml Contains the following.
<!-- ========== Form Bean Definitions =================================== -->
<form-beans>
<form-bean name="Logon"
type="ideas.Logon"/>
</form-beans>
<!-- ========== Global Forward Definitions ============================== -->
<global-forwards>
<forward name="Blank"
path="/jsp/ideas/blank.jsp"
redirect="false"/>
<forward name="Logon"
path="/jsp/ideas/LogonSuccess.jsp"
redirect="false"/>
<forward name="Logout"
path="/jsp/ideas/LogoutSuccess.jsp"/>
<forward name="LogonError"
path="/jsp/ideas/LogonError.jsp"/>
<forward name="Login"
path="/login.jsp"/>
</global-forwards>
<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings>
<action path="/Logon"
type="ideas.LogonAction"
name="Logon"
input="/jsp/ideas/Logon.jsp"
scope="session"/>
<action path="/Logout"
type="ideas.LogoutAction"
name="Logon"
scope="request"/>
</action-mappings>
[ April 22, 2004: Message edited by: The BigBarber ]