Sharma Rajesh

Greenhorn
+ Follow
since Jun 28, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sharma Rajesh

Hi Keerthi
Thanks for reply.
Every thing is right but still it is giving the same error(Servlet action in unavailable).

Thanks
Rajesh
7 years ago
Hi Peter

Thanks a lot for reply.
No i haven't declared validate() method in UserForm class.
Pl. could you tell me what to declare in validate method.

Thanks & Regards
Rajesh
7 years ago
Hi All
I am facing a unique problen.I am using Struts ValidationFrameWork.I have user Struts-config.xml file.I am not able to use validator.
Here i am giving my code.Pl. tell me where i am wrong.

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

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

<form-beans>
<form-bean name="UserForm"
type="com.mkyong.user.form.UserForm" >
</form-bean>
</form-beans>

<action-mappings>

<action
path="/login"
type="org.apache.struts.actions.ForwardAction"
parameter="/src/main/webapp/pages/login.jsp"/>



<action
path="/RegisterUserPage"
type="org.apache.struts.actions.ForwardAction"
parameter="/src/main/webapp/pages/RegisterUser.jsp"/>

<action
path="/Register"
type="com.mkyong.user.action.UserAction"
name="UserForm"


scope="request"
validate="true"
input="/pages/Input.jsp">



<forward name="success" path="/pages/ThanksYou.jsp"/>

</action>



</action-mappings>



<message-resources
parameter="com.mkyong.user.properties.ApplicationResources.properties" />




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

<set-property property="pathnames"




value="/src/main/webapp/WEB-INF/validator-rules.xml,/src/main/webapp/WEB-INF/validation.xml"/>

</plug-in>





</struts-config>

Validation.xml
-----------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">;

<form-validation>
<formset>
<form name="userForm">
<field property="username" depends="required">

<msg name="required" key="errors.username.required" />
</field>
<field property="pwd" depends="required">

<msg name="required" key="errors.pwd.required" />
</field>
</form>
</formset>
</form-validation>

Validator-rules.xml
--------------------------------
<form-validation>
<global>
<validator
name="required"
classname="org.apache.struts.util.StrutsValidator"
method="validateRequired"
methodparams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
depends="required"
msg="errors.required"/>

<validator name="minlength"
classname="org.apache.struts.util.StrutsValidator"
method="validateMinLength"
methodparams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
depends="required"
msg="errors.minlength"/>
</global>
</form-validation>

ApplicationResources.properties
--------------------------------------------
#Normal resource bundle messages
label.username=First Name
label.pwd=Last Name

#Error messages used by the Validator
errors.required={0} is required.

errors.invalid={0} is invalid.


RegisterUser.jsp
----------------------------------

<%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core"; %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"; %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"; %>

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"; %>



<%@taglib uri="http://struts.apache.org/tags-bean"; prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-logic"; prefix="logic"%>
<%@taglib uri="http://struts.apache.org/tags-html"; prefix="html"%>



<html>
<head>
</head>
<body>

<h2>Struts - Validator Example</h2>

<b>User Registeration Form</b>
<br/><br/>

<font color="red">
<html:errors/>
</font>

<html:form action="/Register">

<br/>

<bean:message key="label.username" /> :
<html:text property="username" size="20"></html:text>
<br/>


<bean:message key="label.pwd" /> :
<html:text property="pwd" size="20"></html:text>
<br/>

<html:submit>
<bean:message key="label.button.submit" />
</html:submit>

</html:form>

</body>
</html>


UserForm.java
-----------------------------
package com.mkyong.user.form;

import org.apache.struts.validator.ValidatorForm;

public class UserForm extends ValidatorForm{

String username;
String pwd;




public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}

public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}

}

UserAction.java
----------------------
package com.mkyong.user.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;

public class UserAction extends Action{

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

return mapping.findForward("success");
}
}


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

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd"; >

<web-app>
<display-name>Struts Hibernate Examples</display-name>

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>
/WEB-INF/struts-config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

</web-app>


I am new to ValidationFrameWork.When i type

http://loclahost:8080/StrutsExample/RegisterUserPage.do

it says "Servlet action is not available".
Pl. tell me where i doing wrong.

Thanls and regards to all.
Rajesh

7 years ago
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory net.viralpatel.contact.dao.ContactDAOImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: invalid configuration

My Spring-servlet,xml is this

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:aop="http://www.springframework.org/schema/aop";
xmlns:context="http://www.springframework.org/schema/context";
xmlns:jee="http://www.springframework.org/schema/jee";
xmlns:lang="http://www.springframework.org/schema/lang";
xmlns:p="http://www.springframework.org/schema/p";
xmlns:tx="http://www.springframework.org/schema/tx";
xmlns:util="http://www.springframework.org/schema/util";
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">;
<context:annotation-config />
<context:component-scan base-package="net.viralpatel.contact" />
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" >
<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
<property name="url"><value>jdbc:oracle:thin:@performa-0d812b:1521:XE </value></property>
<property name="username"><value>system</value></property>
<property name="password"><value>manager</value></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
factory-bean="entityManagerFactory" factory-method="getSessionFactory">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>/WEB-INF/hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>


My contactDaoImpl.java is this

package net.viralpatel.contact.dao;
import java.util.List;
import net.viralpatel.contact.form.Contact;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@Repository
public class ContactDAOImpl implements ContactDAO {
@Autowired
private SessionFactory sessionFactory;
public void addContact(Contact contact) {
sessionFactory.getCurrentSession().save(contact);
}
public List<Contact> listContact() {
return sessionFactory.getCurrentSession().createQuery("from Contact").list();
}
public void removeContact(Integer id) {
Contact contact = (Contact) sessionFactory.getCurrentSession().load( Contact.class, id);
if (null != contact) {
sessionFactory.getCurrentSession().delete(contact);
}

}
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}


}

Thanks & Regards
Rajesh

Hi All
My struts application says that the requested source(StrutsExample1) is not available.
Also when i make the Action class and ActionForm Bean then it says that

import org.apache.struts.action.ActionForm;
is not available(org.apache.struts.action.ActionForm)
My code for ActionForm is


package com.vaannila.form;
import org.apache.struts.action.ActionForm;

public class HelloWorldForm extends ActionForm {

private static final long serialVersionUID = -473562596852452021L;

private String message;

public String getMessage() {

return message;
}
public void setMessage(String message) {

this.message = message;

}
}


This is code for Action class

package com.vaannila.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 com.vaannila.form.HelloWorldForm;
public class HelloWorldAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

HelloWorldForm hwForm = (HelloWorldForm) form;

hwForm.setMessage("Hello World");

return mapping.findForward("success");

}
}

here it says ActionMapping,ActionForward is not available.

My Index.jsp is this

<%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic" %>
<logic:redirect forward="helloWorld"/>

here it says
http://struts.apache.org/tags-logic
is not available.

Pl. tell me what to do.
Thanks in advance
Rajesh
8 years ago