• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Not sure why I am not able to insert my data

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

AddAddressAction.java
Address.java
AddressData.java
AddressForm.java
addAddress.jsp
struts-config.xml

address table sql


table
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Regards
Jatan
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


LoginAction.java



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.
 
howard franklin
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 java.io.IOException;
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.setfName(addressform.getfName());
address.setLname(addressform.getLname());
address.setStreet(addressform.getStreet());
address.setCity(addressform.getCity());
address.setState(addressform.getState());
address.setZip(addressform.getZip());
// 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();

errors.add(ActionErrors.GLOBAL_ERROR,
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
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Howard,

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

Regards
jatan
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic