Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How to get particular method of DAO class through struts-config.xml and Action clas.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i am stucked to get the method of DAO class to delete the value in a table. i have given another one action tag in Struts-config.xml to get the return value of Action class. There is a delete button on a jsp(display.jsp) page that call the "delete.do" and also it display the table value from database through java bean class. In DAO class all method works fine...

have a look .......
"struts-config.xml"
<action-mappings>
<action path="/deleted" type="com.myapp.struts.StrutsAction" scope="session" name="StrutsActionForm">
<forward name="deleted" path="/display.jsp"/>
</action>

<action input="/form.jsp" name="StrutsActionForm" path="/go" scope="session" type="com.myapp.struts.StrutsAction">
<forward name="success" path="/display.jsp"/>
</action>

"Action.java"

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws NullPointerException, ServletException, IOException, SQLException{
String name = request.getParameter("name");
String address = request.getParameter("address");
StrutsActionForm saf = (StrutsActionForm) form;

saf.setName(name);
saf.setAddress(address);
try {

EmployeeDao.addEmployee(saf);// DAo method to insert the value in a table
int val=Integer.parseInt(request.getParameter("action"));
if(val==1){
EmployeeDao.removeEmployee(); //Dao method to delete the table vlaue
return mapping.findForward(DELETED);
}

} catch (Exception e) {

}

return mapping.findForward(SUCCESS);
}

All request are working fine but when i click on "delete" button then it goes to "delete.do" and finally it gives the NullPointerException. but the things is all exception has been covered. so please post the solution .....???
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by prashantsharma kumar:




Never ever Ever EVER do this! If you get an exception you'd never know it. At the very least, print the stack trace.
As for your code, I'm a bit lost as to why you would insert a value into the database then delete a value from the database (how do you determine which value to delete if you don't pass anything to the delete method?).
If you are getting an exception, you need to show us the stack trace and the code where the exception occurs.
 
prashantsharma kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thnks for reply,

but the fact is i am new to DAO. so i was doing some research on it.
but here doesnt matter to "which value to delete if you don't pass anything to the delete method". i just want to use to DAO method, later i will complete my process. but i will show you the stack trace.

when i dont write name="StrutsActionForm" in action then it throws exception.


Aug 19, 2008 6:32:38 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet action threw exception
java.lang.NullPointerException
at com.myapp.struts.StrutsAction.execute(StrutsAction.java:44)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)


when i write name="StrutsActionForm" then its being displayed as blank.

[ August 19, 2008: Message edited by: prashantsharma kumar ]
[ August 19, 2008: Message edited by: prashantsharma kumar ]
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

when i dont write name="StrutsActionForm" in action then it throws exception.



I take it the code above which you've labeled "Action.java" is actually com.myapp.struts.StrutsAction and line #44 is the line containing "saf.setName(name);" (please read our FAQ, How To Ask Questions, especially Post Real Code)
If you don't tell Struts which form to use it can't create and initialize that form and that's what name="StrutsActionForm" in the action tag does.
 
prashantsharma kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Joe,

Still i am in problem. i am not getting return value from action either my Dao class method is not accessing right, but when i have gone this program through simple "MVC" pattern then its work fine using of "ServetContext" in servlet class where the table value is being displayed and deleted at the same jsp page with help of Dao class method. what is going wrong with me...


here is my Dao class.
 
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic