Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Database connection with struts  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys.

I have a problem with connecting to Access database like inserting values in a table etc.

My Registration.jsp:

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>




<html:form action="">
First Name: <html:text property="firstName"/><br>
Last Name: <html:text property="lastName"/><br>
Address: <html:textarea property="address"/><br>
Phone no: <html:text property="pnumber"/><br>
D.O.B: <html:text property="dob"/><br>
Sex: <html:radio property="sex" value="M"/>Male
<html:radio property="sex" value="F"/>Female<br>


<logic resent name="lastName" scope="request">
<logic:equal name="submitForm" property="age" value="a">
<logic:equal name="submitForm" property="age" value="c">
<bean:write name="lastName" scope="request"/>
</logic resent>


My Action Class :

import javax.servlet.http.HttpServletRequest;
import javax.servlet.*;
import javax.servlet.GenericServlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletConfig;
import javax.servlet.http.*;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;

import javax.servlet.http.*;
import org.apache.struts.action.*;

public class RegisterAction extends Action {

// private String Mobile;
static Connection theConn;
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
String lastName,firstName, upno,uname,uaddress,upwd,dob, mob;
RegisterForm f=(RegisterForm)form;
request.setAttribute("firstName", firstName.toUpperCase());

request.setAttribute("lastName", lastName.toUpperCase());

String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc dbc:Church";
// return mapping.findForward("success");
Connection connection = DriverManager.getConnection(url);
// theConn = MyConnection.getConnection();

String ssql="insert into userinfo values(?,?)";
PreparedStatement pistmt=connection.prepareStatement(ssql);
ResultSet rs= pistmt.executeQuery();
// pistmt.executeUpdate();
return mapping.findForward("success");

} catch(Exception e)
return mapping.findForward("error");

/** Creates a new instance of Registeruser*/
// return mapping.findForward("success");



Struts Config.xml:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"


<set-property property="driverClass"
<set-property property="url"
value="jdbc dbc:Church" />

<form-bean name="registerForm"



<forward name="welcome" path="/"/>

<action path="/submit"
<forward name="success" path="/Success.html"/>
<forward name="error" path="/Error.html"/>


<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

<message-resources parameter="com/myapp/struts/ApplicationResource"/>

<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">



When the data-sources tag is added in the struts config.xml file, an error comes and if I remove it, atleast it goes to Error.html page. No data is entered in the "userinfo" table in the "Church" database.

Is my data-source tag is alrite or any changes have to be made?

Please help me so that I could successfully enter data in the Access database table.

Thanks a lot.
Posts: 9501
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by NIRMAL YARAM:
When the data-sources tag is added in the struts config.xml file, an error comes and if I remove it,

Welcome to the JavaRanch. It is a good idea to Tell The Details, for example, which version of Struts are you using and what are the errors you are getting?
you should be aware that datasource is not available in all versions of Struts. The Struts FAQ explains why and the better approaches to accessing databases.
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestion.

I'm using NetBeans 5.0

Struts- 1.2.7

Apache Tomcat-5.5.9

Databse: MS Access.

I wrote a Registration.html page which takes the first name and last name as inputs and sumits them.

When it submits, the following error occurs:

HTTP Status 404 - Servlet action is not available

type Status report

message Servlet action is not available

description The requested resource (Servlet action is not available) is not available.
Apache Tomcat/5.5.9

My Registration.html form looks like thhis:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Contact Us</title>
<link href="style.css" rel="stylesheet" type="text/css" />

<h1><p>Registration Details</p></h1>
<div id="body2"><form action="./" method="post" >
<label>FIRST NAME:</label>
<input name="firstName" type="text" id="fname" value="" /><br>
<label>LAST NAME:</label>
<input name="lastName" type="text" id="lname" value="" /><br>

<input name="" type="submit" class="botton" value="SUBMIT" />

The Reegister form and Register Action class remain the same as in the prev post.

Please help me....plzzzzzzzzzzzzzz
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
Why should you try IntelliJ IDEA ?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!