Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

No action is occured when i click the delete link to delete the ite

  Asked By: Michael    Date: Aug 29    Category: Java    Views: 988
  

error is described at the bottom of the page.pls see

here is my struts-config.xml


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

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

<struts-config>

<form-beans>
<form-bean name="addItemForm"
type="com.edhand.example1.AddItemForm"/>
</form-beans>

<action-mappings>

<action
path="/actions/items"
type="org.apache.struts.actions.ForwardAction"
parameter="/pages/AddItem.jsp"/>

<action
path="/actions/addItem"
type="com.edhand.example1.AddItemAction"
name="addItemForm"
scope="request"
validate="true"
input="/pages/AddItem1.jsp">
<forward name="success" path="/pages/AddItem1.jsp" />
</action>


<action
path="/actions/itemDel"
type="com.edhand.example1.DeleteItemAction"
name="addItemForm"
scope="request"
validate="true"
input="/pages/DeleteItem.jsp">
<forward name="success"
path="/pages/loginerror.jsp" />

</action>


</action-mappings>

<message-resources parameter="resources.application"
null="false"/>

</struts-config>

DELETEITEM.JSP

<%@ page import="com.edhand.example1.ItemService" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator"%>

<html>
<head>
<title>Example 1</title>
</head>
<body bgcolor="white">

<h3>Example 1</h3>

<%
/*
* This code will generate a list of objects from the
* database and place a reference to this list in the
* request object.
*
*/
List itemList = ItemService.getInstance().getItemList();
Iterator iter = itemList.iterator();
%>
<p>List of items in <code>item</code> table of database
<code>test</code>.</p>

<table>

<tr>
<td> Item Name </td> <td> Item Description
</td> <td> Delete Records </td>

</tr>


<%

while (iter.hasNext()) {

com.edhand.example1.Item item =
(com.edhand.example1.Item) iter.next();
String name=item.getName();
String des=item.getDescription();
Long id=item.getId();


%>


<tr>
<td><%= name%></td> <td><%= des%></td> <td><a href='itemDel.do?id=<%
= id%>'>

delete </a></td>
</tr>


<%
}
%>

</table>
</body>
</html>


here is the output of
http://localhost:8080/hibernate/actions/itemDel.do

Example 1
List of items in item table of database test.

Item Name Item Description Delete Records
fg fgf delete
fsdf erw delete
gimhan weddaaa delete
gimhan priyantha delete
grger ger delete


DELETEITEMACTION.JAVA

package com.edhand.example1;

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;

/**
* Processes user's request to delete an <code>Item</code> from the
database.
*
* Copyright 2004 Gimhan Priyantha
* @author Gimhan Priyantha
*
*/
public class DeleteItemAction extends Action
{

/**
* execute() processes a user's request to add an
<code>Item</code> to the database,
* given the data in the AddItemForm. Forwards the user back
to the input page.
*
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{

/*
* Cast generic form to the AddItemForm.
*/
AddItemForm addItemForm = (AddItemForm) form;

/*
* If the user has typed a name into the form,
*
* Create an item with the name and description
contained
* in the form.
*
* Using the ItemService, add the item to the
persistence
* layer.
*
* Clear the form so that the two fields will be empty
* upon the next load.
*/



String newid=request.getParameter("id");
ItemService.getInstance().deleteItem(Long.getLong(newid));




/*
* Always return to the "success" forward, currently
* configured in struts-config.xml to return the user
* to the AddItem.jsp.
*/
return mapping.findForward("success");

}


ADDITEMFORM.JAVA

package com.edhand.example1;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

/**
* Stores information related to an <code>Item</code>
* within the Struts framework. Also provides validation on the
Item's name.
*
* Copyright 2004 Gimhan Priyantha
*
* @author Edward Hand
*
*/
public class AddItemForm extends ActionForm
{
private String name;
private String description;
private Long id;

/**
* validate() ensures the user's item is valid and returns the
appropriate <code>ActionErrors</code>
* object, if any errors are generated.
*
* @return <code>ActionErrors</code> A collection of errors
generated by validation process.
*
*/
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request)
{
/*
* Create new ActionErrors object to hold any errors
we discover
* upon validation of the form's fields.
*
*/
ActionErrors errors = new ActionErrors();

/*
* Check the name field to ensure that it is neither
empty nor
* contains a zero length string.
*
*/
if (name == null || name.length() < 1)
{
/*
* Create a new ActionError item, using
the "errros.required" property
* found in application.properties:
*
* errors.required={0} is required.
*
* The "Name" string will replace the {0} tag
found in the properties.
*
* The AddItem.jsp page will be reloaded, and
the <html:errors /> tag
* will be replaced with a list of errors.
The first item will be:
*
* Name is required.
*
*/
errors.add("name", new ActionError
("errors.required", "Name"));

}

return errors;
}

/**
* Clears the object prior to each request.
*
*/
public void reset(ActionMapping mapping, HttpServletRequest
request)
{
this.clear();
}

/**
* getDescription() retrieves <code>description</code> field.
*
*/
public String getDescription()
{
return description;
}


but the error is when i click the delete link no action is occured

could u pls help me to solve the question

Share: 

 

No Answers Found. Be the First, To Post Answer.

 




Tagged: