-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: how to create and configure Dynamic web appl. in eclipe
PostPosted: Sun Feb 26, 2012 10:32 am 
Newbie

Joined: Sun Feb 26, 2012 8:02 am
Posts: 2
Hi.... dear all,

i using eclipse indigo with JRE1.7 and Apache Tomcat7.0.22 version. Normally i have created java project and its deploy with out error/warning no problem its okay. but still i create a new dynamic web application and deploy on server it goes to url show the jsp page its okay after submitting the page it show the following error/warning

Quote:

HTTP Status 404 - There is no Action mapped for namespace / and action name add.

--------------------------------------------------------------------------------

type Status report

message There is no Action mapped for namespace / and action name add.

description The requested resource (There is no Action mapped for namespace / and action name add.) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/7.0.12


And also not create folder(mean deploy) file its war in webapp directory. pls.. guide me i'm new in Web application thanks...

Follow is my Project structure

-PerDynamicProject
-Deployment Descriptor: PerDynamicProject
-Java Resources
-src
-net.perumal.contact.controller
-ContactManager.java
-net.perumal.contact.model
-Contact.java
-net.perumal.contact.util
-HibernateUtil.java
-net.perumal.contact.view
-ContactAction.java
-Libraries
-Apache Tomcat v7.0
-EAR Libraries
-JRE System Libraries
-Web App Libraries
-JavaScript Resources
-build
-WebContent
-META-INF
-WEB-INF
-Lib
-web.xml
-index.jsp
-hibernate.cfg.xml
-struts.xml
--------------------------------------------------------------------------------------------------------------------------------
1)ContactAction.java
Code:
package net.perumal.contact.view;
import java.util.List;
import net.perumal.contact.controller.ContactManager;
import net.perumal.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;
    }
}


2) HibernateUtil.java
Code:
package net.perumal.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;
    }
}

[b] 3) Contact.java[/b]
[code]
package net.perumal.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;
    }
}
[/code]

[b]4) ContactManager.java[/b]
[code]
package net.perumal.contact.controller;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.classic.Session;
import net.perumal.contact.model.Contact;
import net.perumal.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;
    }
}
[/code]

[b] index.jsp[/b]

[quote]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<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>
[/quote]

[b]web.xml[/b]

[code]
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<filter>
    <filter-name>struts2</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
</web-app>
[/code]

[b]struts.xml[/b]

[code]
<?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="hibernate-default">

        <action name="add"
            class="net.perumal.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.perumal.contact.view.ContactAction" method="delete">
            <result name="success" type="chain">index</result>
        </action>

         <action name="index"
            class="net.perumal.contact.view.ContactAction">
            <result name="success">index.jsp</result>
        </action>
    </package>
</struts>
[/code]

[b]hibernate.cfg.xml[/b]

[code]
<?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">
            net.sourceforge.jtds.jdbc.Driver
        </property>
        <property name="connection.url">
            jdbc:jtds:sqlserver://localhost:1433/perumal
        </property>
        <property name="connection.username">sa</property>
        <property name="connection.password">sql2008</property>
        <property name="connection.pool_size">1</property>
        <property name="dialect">
            org.hibernate.dialect.SQLServerDialect
        </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.perumal.contact.model.Contact" />
     </session-factory>
</hibernate-configuration>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.