wood burning stoves*
The moose likes Struts and the fly likes Struts error : servlet action not available..pls solve asap..its very urgent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts error : servlet action not available..pls solve asap..its very urgent" Watch "Struts error : servlet action not available..pls solve asap..its very urgent" New topic
Author

Struts error : servlet action not available..pls solve asap..its very urgent

Anju Bhatia
Greenhorn

Joined: May 08, 2007
Posts: 1
Hi am devloping a small application on struts using netbeans,sqlserver...
when i had not done any connectivity with database then all thingds was doing well...but now after connectivity as i hit any submit button on form..it gives error...SERVLET ACTION NOT AVAILABLE..

i have already stuck my 4-5 days for solving this...pls help me asap..
********************************************************************
struts-config.xml
********************

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">


<struts-config>
<data-sources>
<!--<data-source type="org.apache.tomcat.dpcp.BasicDataSource" key="StrutsTab"> -->
<data-source type="org.apache.commons.dpcp.BasicDataSource" key="StrutsTab">
<set-property property="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
<set-property property="url" value="jdbc:microsoft:sqlserver://10.20.1.22;DataBaseName=tempdb"/>
<set-property property="username" value="sa" />
<set-property property="password" value="" />
</data-source>
</data-sources>
<form-beans>
<form-bean name="userRegistrationForm" type="com.sahara.action.userRegistrationForm">
</form-bean>
</form-beans>

<global-exceptions>
</global-exceptions>

<global-forwards>
</global-forwards>

<action-mappings>
<!-- <set-property property="cancellable" value="true"/> -->
<action path="/userRegistration"
type="com.sahara.action.userRegistrationAction"
input="/userRegistration.jsp"
name="userRegistrationForm">
<set-property property="cancellable" value="true"/>
<exception key="errors.cancel"
type="org.apache.struts.action.InvalidCancelException"
path="/userRegistration.jsp"/>
<forward name="success" path="/regSuccess.jsp"/>
<forward name="cancel" path="/regSuccess.jsp"/>
</action>
<action forward="/regSuccess.jsp" path="/logout"/>
</action-mappings>

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

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


<!-- ========================= Tiles plugin ===============================-->
<!--
This plugin initialize Tiles definition factory. This later can takes some
parameters explained here after. The plugin first read parameters from
web.xml, thenoverload them with parameters defined here. All parameters
are optional.
The plugin should be declared in each struts-config file.
- definitions-config: (optional)
Specify configuration file names. There can be several comma
separated file names (default: ?? )
- moduleAware: (optional - struts1.1)
Specify if the Tiles definition factory is module aware. If true
(default), there will be one factory for each Struts module.
If false, there will be one common factory for all module. In this
later case, it is still needed to declare one plugin per module.
The factory will be initialized with parameters found in the first
initialized plugin (generally the one associated with the default
module).
true : One factory per module. (default)
false : one single shared factory for all modules
- definitions-parser-validate: (optional)
Specify if xml parser should validate the Tiles configuration file.
true : validate. DTD should be specified in file header (default)
false : no validation

Paths found in Tiles definitions are relative to the main context.
-->

<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>

<!-- ========================= Validator plugin ================================= -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

</struts-config>

**************************************************************************
Action Servlet
***************
/*
* userRegistrationAction.java
*
* Created on April 13, 2007, 12:09 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package com.sahara.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
//import org.apache.commons.dbcp.BasicDataSource;


import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.sql.DataSource;
/**
*
* @author Administrator
*/
public class userRegistrationAction extends Action{
/**
* Creates a new instance of userRegistrationAction
*/
public userRegistrationAction() {
}
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
userRegistrationForm userForm= (userRegistrationForm)form;
DataSource objDataSource =getDataSource(request, "StrutsTab");
//DataSource objDataSource=(DataSource)servlet.getServletContext().getAttribute("StrutsTab");
Connection conn=objDataSource.getConnection();

try{
PreparedStatement stmt=conn.prepareStatement
(" insert into StrutsTab " +
"( fName , lName, uName, Password ,Phone ,Fax ,Email ) " +
"values (?,?,?,?,?,?,?)");
stmt.setString(1,userForm.getfName());
stmt.setString(2,userForm.getlName());
stmt.setString(2,userForm.getuName());
stmt.setString(3,userForm.getpassword());
stmt.setString(3,userForm.getPhone());
stmt.setString(3,userForm.getFax());
stmt.setString(3,userForm.getEmail());

stmt.executeUpdate();
}
finally{
conn.close();
}

/*if(isCancelled(request)){
System.out.println("Request Cancel");
return mapping.findForward("cancel");
}
else
{*/
return mapping.findForward("success");
//}
}

}

******************************************************************
web.xml
**********


/*
* userRegistrationAction.java
*
* Created on April 13, 2007, 12:09 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package com.sahara.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
//import org.apache.commons.dbcp.BasicDataSource;


import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.sql.DataSource;
/**
*
* @author Administrator
*/
public class userRegistrationAction extends Action{
/**
* Creates a new instance of userRegistrationAction
*/
public userRegistrationAction() {
}
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
userRegistrationForm userForm= (userRegistrationForm)form;
DataSource objDataSource =getDataSource(request, "StrutsTab");
//DataSource objDataSource=(DataSource)servlet.getServletContext().getAttribute("StrutsTab");
Connection conn=objDataSource.getConnection();

try{
PreparedStatement stmt=conn.prepareStatement
(" insert into StrutsTab " +
"( fName , lName, uName, Password ,Phone ,Fax ,Email ) " +
"values (?,?,?,?,?,?,?)");
stmt.setString(1,userForm.getfName());
stmt.setString(2,userForm.getlName());
stmt.setString(2,userForm.getuName());
stmt.setString(3,userForm.getpassword());
stmt.setString(3,userForm.getPhone());
stmt.setString(3,userForm.getFax());
stmt.setString(3,userForm.getEmail());

stmt.executeUpdate();
}
finally{
conn.close();
}

/*if(isCancelled(request)){
System.out.println("Request Cancel");
return mapping.findForward("cancel");
}
else
{*/
return mapping.findForward("success");
//}
}

}
**********************************************************************8888
Paras Jain
Ranch Hand

Joined: Feb 26, 2005
Posts: 137
Can you please post the exception stack trace?


Paras Jain
SCJP 5.0
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The answer to this question is found in question 7 of the JavaRanch Struts FAQ.

I recommend that you do not use the Struts DataSource utility. See the FAQ article for recommendations on what you should use instead.


Merrill
Consultant, Sima Solutions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts error : servlet action not available..pls solve asap..its very urgent