The moose likes Struts and the fly likes Not sure why I am not able to insert my data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Not sure why I am not able to insert my data" Watch "Not sure why I am not able to insert my data" New topic

Not sure why I am not able to insert my data

howard franklin

Joined: Sep 09, 2012
Posts: 20
I am new to struts and I am trying to put a sample application together.

I can not figure out why I an not able to insert data using the following action. Everything works except that. What happens is after I click save I get a blank screen.

Below I have included code for the following files.

address table sql

Anurag Blore
Ranch Hand

Joined: Jan 15, 2003
Posts: 74
Please do following and check:
1. In class AddAddressAction, Print exception in catch block in method execute.
2. In class AddressData , add a catch block in your method before finally.

Above will give you where the exception is. Also check the forward mapping again as on success it will go to next page but on failure is that handled?

Thank you
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 297

Hi Howard,

Have you checked what happens once click on submit button.

is it reaching to the action class? Because sometimes it may happen that request dosent reach to the action class due to configuration issues
.Please check this and let us know.also print stack trace if you are getting execptions.

Eswar Nec
Ranch Hand

Joined: May 02, 2010
Posts: 105
Hide all your db related code,
Check : After click save button then your application goes to result page or blank page.

If you got blank page, then check your configuration.
Then you will do write further implementation code.

Here i give you one similar sample. I follow this technique

1. First you don't write any logic, Check your all configuration is correct .
That means, Either the success page is displayed or not, when click the save button
2. After that write your full logic.

Wake up! Don't let your smile be snatched away by anybody!
Regards, Eswar
howard franklin

Joined: Sep 09, 2012
Posts: 20
Thanks everyone. Remove everything from the action and found out that my code never made it there. I change the code to the following.

I am new trying to understand. thanks

package input;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import login.LoginBean;

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.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;

public class AddAddressAction extends Action {

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

// Default target to success
String target = new String("success");

if ( isCancelled(request) ) {

// Cancel pressed back to employee list
return (mapping.findForward("success"));

if (request.getParameter("add") != null)

/* start */

try {

Address address = new Address();
AddressForm addressform = (AddressForm) form;

// address.setType(addressform.getType());
// address.setUsername(addressform.getUsername());

AddressData.addAddress(address, getDataSource(request, "address"));

//= new LoginBean(getDataSource(request, "address"));
catch ( Exception e ) {

System.err.println("Setting target to error");
target = new String("error");
ActionErrors errors = new ActionErrors();

new ActionError("errors.database.error", e.getMessage()));

// Report any errors
if ( !errors.isEmpty() ) {

saveErrors(request, errors);

/* end */

target = new String("add");
return (mapping.findForward("add"));


// Forward to the appropriate View
target = new String("missed");
return (mapping.findForward("missed"));
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 297

Hi Howard,

If still there is a problem you need to look into the configuration of action.

I agree. Here's the link:
subject: Not sure why I am not able to insert my data
jQuery in Action, 3rd edition