• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Problem with useBean JSP(view) - Struts(Controller)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

I'm really weird looking this kind of problem.

I'm using JSP file as my view and it submits my form Data to a Struts.

addDrug.jsp:
-------------
<jsp:useBean id="drug" class="DrugDTO" scope="request"/>
<jsp:setProperty name="drug" property="*"/>
<HTML>
<FORM action="./addDrug.do" method="post">
Drug Name:<input type="txt" name="drugName"><BR>
Drug Level:<input type="txt" name="tier"><BR>
Requirements / Limits:<input type="txt" name="requirementsLimits"><BR>
<input type="submit" name="Add Drug">
</FORM>
</HTML>

Here my Form Bean DrugDTO.java:
--------------------------------
public class DrugDTO {

String drugName = null;
String tier = "--";
String requirementsLimits = null;

public String getDrugName() {
return drugName;
}

public String getRequirementsLimits() {
return requirementsLimits;
}

public String getTier() {
return tier;
}

public void setDrugName(String string) {
drugName = string;
}

public void setRequirementsLimits(String string) {
requirementsLimits = string;
}

public void setTier(String string) {
tier = string;
}
}

Action Class AddDrugAction.java
---------------------------------

public class AddDrugAction extends Action{

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


return mapping.findForward("success");
}

}


struts-config.xml:
-------------------
<struts-config>
<action-mappings>
<action path="/addDrug" type="AddDrugAction">
<forward name="success" path="result.jsp"/>
</action>
</action-mappings>
</struts-config>

result.jsp
-----------

<jsp:useBean id="drug" type="DrugDTO" scope="request"/>
<HTML>
<BODY>
<p>
<%= drug.getDrugName() %><BR>
<%= drug.getRequirementsLimits() %><BR>
<%= drug.getTier() %><BR>
</P>
</BODY>
</HTML>

Now my problem is i'm getting all Null values if i specify scope as session in both addDrug.jsp and result.jsp. And server throws an exception if i specify scope as "request".
[10/16/05 0:28:54:262 PDT] 6b14e69c WebGroup E SRVE0026E: [Servlet Error]-[bean drug not found within scope ]: java.lang.InstantiationException: bean drug not found within scope
at org.apache.jsp._test._jspService(_result.java:89)
at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:357)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:675)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:773)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:948)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:530)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:176)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at FormularySearchActionServlet.process(FormularySearchActionServlet.java:92)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:948)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:530)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:176)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:201)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:114)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:610)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:435)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))

I is really appreciate if any one Help. Thanks in advance.

-murthy
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you submit the form from addDrug.jsp to your struts action, I do not see any explicit code that populate your bean with the submitted form data or any declaration in your struts-config.xml that associate the request with an ActionForm instance.

If you want to use struts facility to populate your bean, following is a sample. Note that your bean need to implement struts ActionForm to use the facility.



Read up some materials on struts would be useful.

Otherwise, you need want to send the request to a servlet/jsp that populate the bean for you.
[ October 16, 2005: Message edited by: Eddy Lee Sin Ti ]
 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to the Struts forum.
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nowhere in your action did you set the 'drug' reference to a 'DrugDTO' and place that into either the request or session, hence the 'null' for session scope and 'bean not found' when specified request scope.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic