Tutorial: Create Struts2 Hibernate Example in Eclipse

This is a demo Contact Manager application that we will create using Struts2 and Hibernate framework. In this article we will see how we can use Hibernate to perform Insert / Delete operations in Struts2 framework.

Our Goal

Our goal will be to demonstrate the use of Struts2 with Hibernate framework and to create a demo application “Contact Manager”. The basic requirement of the Contact Manager app will be:

  1. Add new contact in the contact list.
  2. Display all contacts from contact list.
  3. Delete a contact from contact list.

Once we will build the application it will look like:
struts2-hibernate-contact-manager

Getting Started

For our Contact Manager example, we will use MySQL database. Create a table contacts in any MySQL database. This is very preliminary example and thus we have minimum columns to represent a contact. Feel free to extend this example and create a more complex application.

CREATE TABLE CONTACTS
(
	id 		INT PRIMARY KEY AUTO_INCREMENT,
	firstname 	VARCHAR(30),
	lastname	VARCHAR(30),
	cell_no		VARCHAR(15),
	email_id	VARCHAR(30),
	website		VARCHAR(150),
	birthdate	DATE,
	created		TIMESTAMP DEFAULT NOW()
);

Creating Project in Eclipse

Open Eclipse and goto File -> New -> Project and select Dynamic Web Project in the New Project wizard screen.
struts dynamic web project

After selecting Dynamic Web Project, press Next.
dynamic web project

Write the name of the project. For example ContactManager. Once this is done, select the target runtime environment (e.g. Apache Tomcat v6.0). This is to run the project inside Eclipse environment. After this press Finish.

We will need a source folder called resources. Right click on Project in project explorer and select New -> Source Folder and create a folder with name resources.

Also we will create Java packages for our application. As we will use Struts2, we will follow MVC architecture. Create 4 packages in the sources.
struts2-hibernate-package

We created 4 new packages. The net.viralpatel.contact.controller will hold the Java class that will act as controller and will fetch the data from database and pass it to view. The net.viralpatel.contact.model package will hold the Hibernate persistent model class. The net.viralpatel.contact.view will contain the struts2 action class. And finally the net.viralpatel.contact.util will have some hibernate related util file that will be see shortly.

Required JAR Files

Now copy all the required JAR files in WebContent -> WEB-INF -> lib folder. Create this folder if it does not exists.

Create JSP for Contact Manager

We will need only one JSP file for this tutorial. The JSP will include a form to add new contact as well as will list the contacts at the end. Create a JSP file index.jsp in WebContent folder and copy following content into it.
WebContent/index.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
	<title>Contact Manager - Struts2 Hibernate Example</title>
</head>
<body>

<h1>Contact Manager</h1>
<s:actionerror/>

<s:form action="add" method="post">
	<s:textfield name="contact.firstName" label="Firstname"/>
	<s:textfield name="contact.lastName" label="Lastname"/>
	<s:textfield name="contact.emailId" label="Email"/>
	<s:textfield name="contact.cellNo" label="Cell No."/>
	<s:textfield name="contact.website" label="Homepage"/>
	<s:textfield name="contact.birthDate" label="Birthdate"/>
	<s:submit value="Add Contact" align="center"/>
</s:form>

<h2>Contacts</h2>
<table>
<tr>
	<th>Name</th>
	<th>Email</th>
	<th>Cell No.</th>
	<th>Birthdate</th>
	<th>Homepage</th>
	<th>Delete</th>
</tr>
<s:iterator value="contactList" var="contact">
	<tr>
		<td><s:property value="lastName"/>, <s:property value="firstName"/> </td>
		<td><s:property value="emailId"/></td>
		<td><s:property value="cellNo"/></td>
		<td><s:property value="birthDate"/></td>
		<td><a href="<s:property value="website"/>">link</a></td>
		<td><a href="delete?id=<s:property value="id"/>">delete</a></td>
	</tr>
</s:iterator>
</table>
</body>
</html>

Adding Hibernate Support

For adding hibernate support, we will add following source code in Contact Manager application.
hibernate.cfg.xml – This is the Hibernate configuration file. This file will contain configurations such as database connection information, persistence class info etc. Create hibernate.cfg.xml under resources folder and copy following content into it.

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
	<session-factory>
		<property name="connection.driver_class">
			com.mysql.jdbc.Driver
		</property>
		<property name="connection.url">
			jdbc:mysql://localhost:3306/ContactManager
		</property>
		<property name="connection.username">root</property>
		<property name="connection.password">root</property>
		<property name="connection.pool_size">1</property>
		<property name="dialect">
			org.hibernate.dialect.MySQLDialect
		</property>
		<property name="current_session_context_class">thread</property>
		<property name="cache.provider_class">
			org.hibernate.cache.NoCacheProvider
		</property>
		<property name="show_sql">true</property>
		<property name="hbm2ddl.auto">update</property>

		<mapping class="net.viralpatel.contact.model.Contact" />

	</session-factory>
</hibernate-configuration>

HibernateUtil.java – This is the Util file that we use to create connection with hibernate. Create HibernateUtil.java under package net.viralpatel.contact.util and copy following content into it.

package net.viralpatel.contact.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {

	private static final SessionFactory sessionFactory = buildSessionFactory();

	private static SessionFactory buildSessionFactory() {
		try {
			// Create the SessionFactory from hibernate.cfg.xml
			return new AnnotationConfiguration().configure()
					.buildSessionFactory();
		} catch (Throwable ex) {
			System.err.println("Initial SessionFactory creation failed." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
}

Contact.java – This is the persistence entity class that will map to Contacts table in MySQL. Create Contact.java under net.viralpatel.contact.model package and copy following content into it.

package net.viralpatel.contact.model;

import java.io.Serializable;
import java.sql.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="Contacts")
public class Contact implements Serializable{

	private static final long serialVersionUID = -8767337896773261247L;

	private Long id;
	private String firstName;
	private String lastName;
	private String emailId;
	private String cellNo;
	private Date birthDate;
	private String website;

	private Date created;

	@Id
	@GeneratedValue
	@Column(name="id")
	public Long getId() {
		return id;
	}
	@Column(name="firstname")
	public String getFirstName() {
		return firstName;
	}
	@Column(name="lastname")
	public String getLastName() {
		return lastName;
	}
	@Column(name="email_id")
	public String getEmailId() {
		return emailId;
	}
	@Column(name="cell_no")
	public String getCellNo() {
		return cellNo;
	}
	@Column(name="birthdate")
	public Date getBirthDate() {
		return birthDate;
	}
	@Column(name="website")
	public String getWebsite() {
		return website;
	}
	@Column(name="created")
	public Date getCreated() {
		return created;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public void setEmailId(String emailId) {
		this.emailId = emailId;
	}
	public void setCellNo(String cellNo) {
		this.cellNo = cellNo;
	}
	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}
	public void setCreated(Date created) {
		this.created = created;
	}
	public void setWebsite(String website) {
		this.website = website;
	}
}

Note how we have mapped Contact class with Contacts table using Java persistence API annotations.

Adding Controller to access data

We will add a controller class in Contact Manager application which will be used to get/save data from hibernate. This controller will be invoked from Struts action class. Create a file ContactManager.java under net.viralpatel.contact.controller package and copy following content into it.

package net.viralpatel.contact.controller;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import net.viralpatel.contact.model.Contact;
import net.viralpatel.contact.util.HibernateUtil;

public class ContactManager extends HibernateUtil {

	public Contact add(Contact contact) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.save(contact);
		session.getTransaction().commit();
		return contact;
	}
	public Contact delete(Long id) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Contact contact = (Contact) session.load(Contact.class, id);
		if(null != contact) {
			session.delete(contact);
		}
		session.getTransaction().commit();
		return contact;
	}

	public List<Contact> list() {

		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<Contact> contacts = null;
		try {

			contacts = (List<Contact>)session.createQuery("from Contact").list();

		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return contacts;
	}
}

Note that how we have created different methods in controller class to add/delete/list the contacts. Also the ContactManager class is extending HibernateUtil class thus allowing it to access sessionFactory object.

Adding Struts2 Support

Let us add Struts2 support to our web application. For that, will add following entry in deployment descriptor (WEB-INF/web.xml).

Add Struts2 Filter in web.xml

<filter>
	<filter-name>struts2</filter-name>
	<filter-class>
		org.apache.struts2.dispatcher.FilterDispatcher
	</filter-class>
</filter>
<filter-mapping>
	<filter-name>struts2</filter-name>
	<url-pattern>/*</url-pattern>
</filter-mapping>

Creating struts.xml

We will need to create struts.xml file that will hold the action mapping for our example. Create a file struts.xml in resources folder and add following content into it.
struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
	<constant name="struts.enable.DynamicMethodInvocation"
		value="false" />
	<constant name="struts.devMode" value="false" />

	<package name="default" extends="struts-default" namespace="/">

		<action name="add"
			class="net.viralpatel.contact.view.ContactAction" method="add">
			<result name="success" type="chain">index</result>
			<result name="input" type="chain">index</result>
		</action>

		<action name="delete"
			class="net.viralpatel.contact.view.ContactAction" method="delete">
			<result name="success" type="chain">index</result>
		</action>

		<action name="index"
			class="net.viralpatel.contact.view.ContactAction">
			<result name="success">index.jsp</result>
		</action>
	</package>
</struts>

Related:
Create Struts Application in Eclipse
Create Struts2 Application in Eclipse

Create Action class

Up-till now we have almost completed our Contact Manager application in Struts2 and Hibernate. Only task left is to add Struts Action class. Create a class ContactAction.java under net.viralpatel.contact.view package and copy following content into it.

package net.viralpatel.contact.view;

import java.util.List;

import net.viralpatel.contact.controller.ContactManager;
import net.viralpatel.contact.model.Contact;

import com.opensymphony.xwork2.ActionSupport;

public class ContactAction extends ActionSupport {

	private static final long serialVersionUID = 9149826260758390091L;
	private Contact contact;
	private List<Contact> contactList;
	private Long id;

	private ContactManager contactManager;

	public ContactAction() {
		contactManager = new ContactManager();
	}

	public String execute() {
		this.contactList = contactManager.list();
		System.out.println("execute called");
		return SUCCESS;
	}

	public String add() {
		System.out.println(getContact());
		try {
			contactManager.add(getContact());
		} catch (Exception e) {
			e.printStackTrace();
		}
		this.contactList = contactManager.list();
		return SUCCESS;
	}

	public String delete() {
		contactManager.delete(getId());
		return SUCCESS;
	}

	public Contact getContact() {
		return contact;
	}

	public List<Contact> getContactList() {
		return contactList;
	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}

	public void setContactList(List<Contact> contactsList) {
		this.contactList = contactsList;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
}

ContactAction class contains different methods that gets called by Struts2. The execute() method is the default method which gets called when we call /index action from browser. It fetches the list of contacts and display it in index.jsp. Similarly, when a new contact is added, add() method is called. If you check the action mapping entry in struts.xml for add() method, the <result> is mapped with /index action and the type is chain. This is because we want to display the list of contact once we add a new one. Hence we have done Action chaining and called /index action after /add action.

The Contact Manager App

That’s it. The app is ready, just compile and run the project in Eclipse Run -> Run As -> Run on Server. Set the URL to:
http://localhost:<port>/<project name>/index

struts2-hibernate-contact-manager
Fill the contact form and hit enter and the new contact will be persisted in database and will be shown in below table. Similarly, click on delete link next to a record. It will delete the record from database.

Let me know your input about this application.
Cheers.

Download Source

Download Source without JAR files (19.2 KB)

Download Source with JAR files (8.5 MB)



164 Comments

  • gwalterg wrote on 1 November, 2011, 18:11

    Look interesting, but i never can run it. It lacks more information about basic configuration, libraries, etc…remember it’s targeted to newbies. By example, i allways get http://localhost/StrutsHibernate/ errors, “required resource not available” 404 error page.

  • Jury wrote on 10 November, 2011, 17:17

    I am newbie in Struts2, but this tutorial is very simple to understand. I have no problems with running, but in my realization when I push Add Contact I get two singular notices in base. Maybe it is my own bag. Thank you for tutorial!

  • uttam kumar wrote on 24 November, 2011, 19:26

    after created model,view,contact.class
    while running project the index page is coming after fill-up data it’s show..
    java.lang.NoClassDefFoundError: org/hibernate/HibernateException
    net.viralpatel.contact.view.ContactAction.(ContactAction.java:20)

    please guide me..
    thanks in advance

    • Viral Patel wrote on 25 November, 2011, 12:15

      @Uttam – The error says that the class org.hibenate.HibernateException was not found. Check the version of Hibernate you using. You must use latest version.

  • manoj wrote on 25 November, 2011, 17:44

    hello sir i could not undrstand the concepts of hibernate …….and i am not able to create a hibernate program in eclipse please understood me via my email address …………Thank You……

  • A.Penna wrote on 2 December, 2011, 7:48

    I try run this code, but return these errors:

    HTTP Status 404 – No result defined for action net.viralpatel.contact.view.ContactAction and result input

    ——————————————————————————–

    type Status report

    message No result defined for action net.viralpatel.contact.view.ContactAction and result input

    description The requested resource (No result defined for action net.viralpatel.contact.view.ContactAction and result input) is not available.

    Why this happens? Where are the bugs?!!!!

    Thx a lots Viral !!!!

  • Saikat Gupta wrote on 2 December, 2011, 18:28

    when i tried to run this application I got the error like this. pls help me out.
    Caused by: java.lang.NoClassDefFoundError: javax/faces/lifecycle/Lifecycle
    at java.lang.Class.getDeclaredMethods0(Native Method)
    … 31 more
    Caused by: java.lang.ClassNotFoundException: javax.faces.lifecycle.Lifecycle
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)

    • Viral Patel wrote on 2 December, 2011, 18:52

      @Saikat – Not sure why your project tries to load javax.faces.lifecycle.Lifecycle class. This class comes with jsf-api.jar and is used if we want to integrate JSF framework. Check your struts.xml file and see if you following steps as mentioned in above tutorial.

  • Saikat Gupta wrote on 2 December, 2011, 20:47

    Viral pls give me the possible reasons why my application is not finding out the action add. I have created the struts.xml inside the source folder. The error is as follows.

    WARNING: No configuration found for the specified action: ‘add’ in namespace: ”. Form action defaulting to ‘action’ attribute’s literal value.
    Dec 02, 2011 8:45:31 PM org.apache.struts2.components.Form evaluateExtraParamsServletRequest
    WARNING: No configuration found for the specified action: ‘add’ in namespace: ”. Form action defaulting to ‘action’ attribute’s literal value.

    • sarty wrote on 16 December, 2011, 21:04

      Even i’m also getting the same issue.In webspehere it’s coming like

      [12/16/11 15:22:05:143 GMT] 0000002d WebApp A SRVE0180I: [ContactUsers_war#ContactUsers.war] [/ContactUsers] [Servlet.LOG]: Error page exception The server cannot use the error page specified for your application because of the exception printed below.
      [12/16/11 15:22:05:147 GMT] 0000002d WebApp A SRVE0181I: [ContactUsers_war#ContactUsers.war] [/ContactUsers] [Servlet.LOG]: Error Page Exception: : com.ibm.websphere.servlet.error.ServletErrorReport: SRVE0190E: File not found: /add

      —-Dont’ kno why..bangin my head from past 2 days.It’s not going the ContactAction itself.I think struts.xml we are doing some mistake.

  • vv.b wrote on 8 December, 2011, 10:50

    Hi Viral
    Can u please send me contact manager program by using
    Struts 1.3 , Hibernate 3 and eclipse , thanks in advance.

  • Maleb wrote on 12 December, 2011, 10:43

    Please Mr.Patel, could you post (or send to me by email) all JAR files used in this project?

    I have the same problem that Jury. When I push the “ADD Contact” button two insert entries are made in the database. I don’t know why!

    Nice website, thX a lot Viral.

  • Ramkumar wrote on 12 December, 2011, 14:35

    Hi.

    Can you show us the folder structure..

  • MF wrote on 12 December, 2011, 15:58

    You`ve got a problem with your hierarchy of directories. Try to create your project using two source directories with Eclipse called java and sources or whatever you want.Then observe if ,when you introduce a new archive on the directories, the Eclipse IDE actualize “its own directories”, its to say, the view of the directories that the IDE creates. If the last one doesn’t happend is cause of the configuration of the hierarchy is wrong.

  • Neeraj wrote on 13 December, 2011, 13:35

    Hi,
    plz could u send jar file ..of your application .

    • Viral Patel wrote on 17 December, 2011, 17:08

      Hi Neeraj,

      I have included the source code with jar files at the end of article. Hope that helps.

      -Viral Patel

  • Anirban wrote on 13 December, 2011, 17:08

    not able to find out struts.tld. giving the error message: cannnot find the tag library descriptor for “/struts-tags” . I think the struts.tld is required. Please give me the tld file..

  • Kevin Phytagoras wrote on 13 December, 2011, 17:48

    hi,
    why i kept getting The Struts dispatcher cannot be found error ?
    help plizzz

    • ketan wrote on 14 December, 2011, 12:48

      check out your struts.xml configuration file and see that FilterDispatcher must be initialized properly.

  • Anirban wrote on 13 December, 2011, 22:05

    Hi Viral, the previous issue has been resolved. Now a new issue has been occurred. ITs giving “HTTP Status 404 – No result defined for action net.viralpatel.contact.view.ContactAction and result input” and “java.lang.NoSuchMethodException: setBirthDate([Ljava.lang.String;)” and “ognl.MethodFailedException: Method “setBirthDate” failed for object net.viralpatel.contact.model.Contact@1096cd8 ” exceptions.. Please help in resolving these issues. Thanks in advance//..

    Regards,
    Anirban

  • Anirban wrote on 14 December, 2011, 22:27

    Issue is resolved… !!! :) Thanks…

  • Arjun Sridhar UR wrote on 16 December, 2011, 13:50

    Excellent,Great work working fine except Date.
    Unable to store Date of birth as Date.It’s refer’s Java.util.Strilng even the HBM file I mentioned Date and auto genetrated code by jboss tools. if I set’s as string type in Date column. It work’s perfectly. Thanks. thanks a lot..

  • Arjun Sridhar UR wrote on 16 December, 2011, 13:54

    Hi anriban,
    how you resolved the date problem please share with us.
    Still I’m using BirthDate as String…

  • Maleb wrote on 17 December, 2011, 0:59

    The bug still exist here.
    The eclipse returns after push “ADD Contact” button:
    net.viralpatel.contact.model.Contact@66ae66
    Hibernate: insert into Contacts (birthdate, cell_no, created, email_id, firstname, lastname, website) values (?, ?, ?, ?, ?, ?, ?)
    Hibernate: insert into Contacts (birthdate, cell_no, created, email_id, firstname, lastname, website) values (?, ?, ?, ?, ?, ?, ?)
    Hibernate: select contact0_.id as id0_, contact0_.birthdate as birthdate0_, contact0_.cell_no as cell3_0_, contact0_.created as created0_, contact0_.email_id as email5_0_, contact0_.firstname as firstname0_, contact0_.lastname as lastname0_, contact0_.website as website0_ from Contacts contact0_
    [net.viralpatel.contact.model.Contact@d35cb2, net.viralpatel.contact.model.Contact@33048b, net.viralpatel.contact.model.Contact@16f67bb, net.viralpatel.contact.model.Contact@1fa739a, net.viralpatel.contact.model.Contact@1bb8cae, net.viralpatel.contact.model.Contact@111d6d, net.viralpatel.contact.model.Contact@1a31895]
    76
    Do you could post the complete project (with all JARs)?
    Thanks Viral

  • DasKhatri wrote on 23 December, 2011, 17:12

    Its a great tutorial.. i used it was very useful… thanks a lot for such a awsum tutorial..
    But I’m getting a problem of that when I add a record it is added twice.. I’m not able to recognize it that why this happening . while I had used the same code after downloading source code.

    Thanks , any help.
    BR-DasKhatri

    • Viral Patel wrote on 23 December, 2011, 17:24

      @DasKhatri – Thanks for the kind words :-)
      Regarding problem record getting added twice, check the execute() method of ContactAction class. Make sure it doesn’t have call to contactManager.add() method.

      • DasKhatri wrote on 27 December, 2011, 11:52

        yes thanks , there was if statement at wrong place for that reason it was adding twice a record, perhaps some where this mistake is done by me. But caught it. :) thank u so much Mr.Viral

  • DasKhatri wrote on 27 December, 2011, 11:49

    HI, thanks for such a nice tutorial, gave a big support to start struts2 and hibernate :) . actually I required now the same application functionality but with one to one and one to many and many to many hibernate xml mapping files. As I did google but couldn’t find any helpful link to develop a crud application with hbm files support with struts2.
    So any hint or example if you could provide me, i will be very thankful to you :)

    BR
    Das Khatri
    Software engineer
    from Sindh

  • Sushil wrote on 9 January, 2012, 11:39

    I’ve been trying to run the application but keeps me on displaying the errors. I don’t know why but I tried a lot to find out what’s go on with the error message:
    HTTP Status 404 – No result defined for action net.viralpatel.contact.view.ContactAction and result input
    description The requested resource (No result defined for action net.viralpatel.contact.view.ContactAction and result input) is not available.

    Could you please help me. Your help will be greatly appreciated. By the my gratitude for your effort in helping New J2EE learners. This is indeed a very good and kind help. Thanks for your benevolence.
    Thanks again :-)
    Sushil

    • Jose wrote on 12 January, 2012, 8:43

      I have the same problem, did you fix it???

  • Ansh wrote on 12 January, 2012, 14:04

    HTTP Status 404 – No result defined for action net.viralpatel.contact.view.ContactAction and result input
    type Status report
    message No result defined for action net.viralpatel.contact.view.ContactAction and result input
    description The requested resource (No result defined for action net.viralpatel.contact.view.ContactAction and result input) is not available.
    ______________________________________________________________

    I am having the same problem as Sushil..no idea whats wrong.Will greatly appreciate your help.

  • Ansh wrote on 12 January, 2012, 14:31

    um,I found my reasons its because I filled birthdate dd/mm/yyyy , but mysql convention is mm/dd/yyyy.

    @Sushil – check this..maybe you doing the same

    • Jose wrote on 13 January, 2012, 1:47

      yes that was the problem I already found but I appreciate your time Ansh thanks.

  • shahumali wrote on 19 January, 2012, 11:25

    Thanks :)

  • Aatif wrote on 20 January, 2012, 18:38

    Hi..I took help from this tutorial. It worked for me. Really very nice it it..:) thanks.

  • vikash wrote on 21 January, 2012, 3:14

    Thanks Viral ..

  • suresh wrote on 24 January, 2012, 15:48

    Hi Viral,

    am getting below error message :
    HTTP Status 404 – No result defined for action net.viralpatel.contact.view.ContactAction and result input

    Thanks
    Suresh

  • koustoov wrote on 27 January, 2012, 11:05

    Hello Viral….Thanks 4 such an application.

    I am a beginner & it worked…….but i got a problem in inserting firstname,lastname & birthdate.

    I dont know why……… can u please tell me that why these are not going to database????else everything is fine…..

    please help me out……

    Thanks & Regards

  • sridevi_sun wrote on 28 January, 2012, 2:56

    Hi Viral, thanks for the good tutorials, I am one among them who got benefited. Have a question for you; is it possible to change an entry in hibernate.cfg.xml file? or to rewrite this file at runtime? my requirement is to have a primary and secondary datasource connectivity for an application and to change the primary and secondary values at runtime. Is this something doable with hibernate?

  • Bhaskar wrote on 28 January, 2012, 23:06

    Hi, i am getting this error..SQL Error: 1045, SQLState: 28000
    Access denied for user ‘root’@'localhost’ (using password: YES).
    I am giving the correct username and password for my DB but still getting this error. Can you please help.

  • darshan wrote on 31 January, 2012, 12:24

    i found your ever blog very very helpful and usable ..your brilliant

  • ykShipp wrote on 1 February, 2012, 9:19

    I use postgresql, so I change the

    org.postgresql.Driver

    jdbc:postgresql://localhost:5432/test

    but it looks like I got nothing insert into the table. and get an error 404 – No result defined for action net.viralpatel.contact.view.ContactAction and result input. does anyone know what is wrong???

  • ykShipp wrote on 2 February, 2012, 12:12

    look like I have problem with the birthday field, I just comment it out for testing. it works ok. but why the hibernate can’t parse the date?

  • Anoop wrote on 3 February, 2012, 12:33

    Hi Team ,

    Thanks for posting the example. I tried this but not able to run the application.I am getting the error
    The requested resource (There is no Action mapped for namespace / and action name add.) is not available” .
    Appreciated if you could help me ASAP.

  • ykShipp wrote on 3 February, 2012, 14:34

    anyone know what is going on:
    16:57:23,921 DEBUG XWorkConverter:57 – falling back to default type converter [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@1dcc4cd]
    16:57:23,921 DEBUG XWorkConverter:61 – unable to convert value using type converter [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter]
    Could not parse date – [unknown location]
    at com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.doConvertToDate(XWorkBasicConverter.java:366)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.text.ParseException: Unparseable date: “1966-01-01″

    give me a hand please~~~~~

  • sandeep kumar wrote on 6 February, 2012, 21:38

    Hi Viral,
    Thanks for the tutorial. I always refer your tutorial. Here i have a problem while displaying the data. I am able to insert the records but i am not able to display it somehow. I tried session.CreateSQL instead of session.CreateQuery and it worked (at least i was able to display 1 column of one record) but i am not able to display list of items.
    I would like to ask what is the significance of var=”contact” in your jsp code. Is that the DomainObject class that you are refering here or its of no use bcz i dont see any use of contact any where else.

    Thanks
    Sandeep

    • sandeep kumar wrote on 6 February, 2012, 21:42

      Viral,
      I put the debug while running the application and i saw contactList was returning correct number of records. so that means i am having problem somewhere in my jsp rght ?
      I am really stuck here…. any help in this regard would be a great help.

      Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Copyright © 2012 ViralPatel.net. All rights reserved.