Using Beans in Servlets
Im using a servlet that accesses a java bean within a session in order to display all the contents within the bean. The code is shown below:
HttpSession session = request.getSession();
ItemBean bean = new ItemBean();
bean.setProductID(results.getString("ProductID")); bean.setProductDescription(results.getString("ProductDescription")); bean.setProductName(results.getString("ProductName")); bean.setProductPrice(results.getString("ProductPrice"));
bean.setQuantity(Quantity);
ItemBeans item = (ItemBeans)session.getAttribute("basket");
item.addItemBean(bean);
I use a jsp page that uses this bean to display the items. Once all the items have been displayed on the page, the user clicks on a button and this calls another servlet which should take all the items in the bean and store them in a database. Does anyone know how to do this?
Thanks.
How do I actually store the information in the bean
to my database?
For example, the bean holds details of product name,
description, price etc. How do I get all these
details and store them on the database?
All my other servlets simply retrieve one pair of
information using request.getParameter(); and then
run a query which adds this parameter to the
database. But how do I do it for a bean?Very similar. Instead of using request.getParameter, you get the session. You get the bean from the session. You get<properyName>() from the bean. You run the query.
Similar Messages
-
I have my JavaBean's full path in my system classpath and am trying to import the bean, but I am unable to access it in a servlet.
If I have the bean in the com directory under WEB-INF, wouldn't the import be import com.mybean.class; ?
I'm finding very little on using beans with servlets. What else do I need to do to access the beans methods?
Thanks.I thought about that, but I wasn't sure of the
implications once I again use the bean in the JSP
pages that pickup processing from the servlet. Will I
then have to use the object name to reference the
session bean?If you are carrying/sharing this bean state with a jsp then, you could do something like this..
1. Instantiate the bean in your servlet class and do the processing you need to do on it
2. set this bean as an attribute in request or session
3. in JSP, use this bean and share the state using the <jsp:useBean .. tag. PafBean myBean = new PafBean();
myBean.setMgrNum(username);
myBean.setSomethingElse(request.getParameter("somethingElse"));
// here i am setting to request. but you could set it in session also
request.setAttribute("myBean", myBean);
getServletConfig().getServletContext().getRequestDispatcher
("/jsp/test.jsp").forward(request, response);The JSP page Bean1.jsp can then process fBean, after first extracting it from the default request scope via the useBean action.
<jsp:useBean id="myBean" class="com.PafBean" scope="request"/>
//if you are using session
<jsp:useBean id="myBean" class="com.PafBean" scope="session"/>Hope this helps! -
Hi,
I have a problem in getting the values from simple bean to servlet. The project has one html form. When the user click on the submit button one jsp will be invoked which calls a bean program to validate the user data for required fields. Based on the result, jsp program forward the control to a servlet which stores the data in a database. Otherwise another jsp is called to inform the user to fill in the required data.
My problem is how to send the data from bean to servlet?
The snippet of jsp that calls bean is like this :
<%!
%>
<jsp:useBean id="formHandler" class = "subFormBean" scope="request">
<jsp:setProperty name="formHandler" property="*"/>
</jsp:useBean>
<%
if (formHandler.validate()) {
%>
<jsp:forward page="subscriberRegistration"/>
<%
} else {
%>
<jsp:forward page="retry.jsp"/>
<%
%>
And the snippet of the bean is like this :
public boolean validate() {
boolean bool=true;
if (subname.equals("")) {
errors.put("subname","Please enter your Name");
subname="";
bool=false;
public subFormBean() {
subname="";
public String getSubName() {
return subname;
public void setSubName(String sname) {
subname =sname;
The servlet which is to receive the data is like this :
public class subscriberRegistration extends HttpServlet{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
subFormBean sfb = new subFormBean();
sfb.setSubName(subname);
But I'm getiing error while trying to compile the servelet saying that no variables found - sfb, subname etc.
Please let me know how to invoke the bean from servlet. I want to use servlet to instead of jsp to insert records into database. How can i do this? Please help me. Thanks in advance.Hi Tolls,
Sorry, I'll give a bigger snippet of the prog.code below :
public class subscriberRegistration extends HttpServlet{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
subFormBean sfb = new subFormBean();
sfb.setSubName(subname);
sfb.setSubAddress(subaddress);
sfb.setSubCity(subcity);
sfb.setSubState(substate);
sfb.setSubCntry(subcntry);
sfb.setSubPin(subpin);
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection(connectionURL,"scott","tiger");
stmt = connection.createStatement();
rs = stmt.executeQuery("SELECT subid_seq.NEXTVAL FROM DUAL");
while(rs.next()) {
String subno = rs.getString("NEXTVAL");
PreparedStatement pst = connection.prepareStatement("insert into eps_subscriber(eps_subno, eps_subname, eps_subaddress, eps_subcity, eps_substate, eps_subcntry, eps_subpin, eps_subphno, eps_subemailid, eps_subuserid, eps_subpwd) values(?,?,?,?,?,?,?,?,?,?,?)");
pst.setString(1,subno);
pst.setString(2,sfb.subname);
pst.setString(3,sfb.subaddress);
pst.setString(4,sfb.subcity);
pst.setString(5,sfb.substate);
pst.setString(6,sfb.subcntry);
pst.setString(7,sfb.subpin);
I'm validating the form data in beans program. Servlet is used to insert records into the database. So, i'm trying to capture data from the bean. How to capture the data from the bean to servlet? Or should I get it from the form fields directly? The servlet worked well when data was captured directly from html form fields. Please help me to fix this. Thanks in advance. -
How to implement use bean tag in servlet technology
hello,
i want to use application scope for variables in application . i know about use bean tag but i want to use servelet technology. how could this be doneThe application scope corresponds to the servlet context. From your servlet, use getServletContext().getAttribute() and getServletContext().setAttribute().
-
How to populate the List for second LOV using bean
hi how can i pass selected value of LOV to second LOV using bean,so can have cascading lov,my lov are as followss,am in jdeveloper 11.1.1.6.0
<td width="50%" height="22"><af:selectOneChoice
label="#{bindings.LutOrganisationtypesView1.label}"
required="true"
shortDesc="#{bindings.LutOrganisationtypesView1.hints.tooltip}"
id="soc2" simple="true"
autoSubmit="true"
immediate="true"
binding="#{pageFlowScope.orgDetailsBean.orgCat}"
value="#{pageFlowScope.orgDetailsBean.orgCat}"
attributeChangeListener="#{pageFlowScope.orgDetailsBean.listener}"
rendered="true" valuePassThru="true">
<af:forEach items="#{bindings.LutOrganisationtypesView1.iteratorBinding.allRowsInRange}"
var="row">
<af:selectItem id="tiltco2" label="#{row.description}"
value="#{row.organisationtypecode}"/>
</af:forEach>
</af:selectOneChoice>
</td>
</tr><tr>
<td width="50%" height="22">
<af:outputLabel value="Type" id="ol5" showRequired="true"/>
</td>
<td width="50%" height="22"><af:selectOneChoice
label="#{bindings.LutOrgsubtypesView1.label}"
required="true"
shortDesc="#{bindings.LutOrgsubtypesView1.hints.tooltip}"
id="soc1" simple="true"
autoSubmit="false"
partialTriggers="soc2"
immediate="false"
binding="#{pageFlowScope.orgDetailsBean.orgSubtype}"
value="#{pageFlowScope.orgDetailsBean.orgSubtype}"
rendered="true">
<af:forEach items="#{bindings.LutOrgsubtypesView1.iteratorBinding.allRowsInRange}"
var="row">
<af:selectItem id="tiltcos2" label="#{row.orgsubtypename}"
value="#{row.orgsubtypecode}"/>
</af:forEach>
</af:selectOneChoice>
</td>when i select my list i only get one list in second lov it does not show the other selection
Edited by: adf0994 on 2012/11/08 12:49 PM
Edited by: adf0994 on 2012/11/08 12:55 PMi have this value change listner but still no luck
private String orgSubtype;
public void setOrgSubtype(String orgSubtype) {
this.orgSubtype = orgSubtype;
public String getOrgSubtype() {
return orgSubtype;
public void GetOrg(ValueChangeEvent valueChangeEvent) {
orgSubtype = valueChangeEvent.getNewValue().toString();
refereshpage();
public void refereshpage(){
FacesContext facesContext = FacesContext.getCurrentInstance();
String Refreshpage = facesContext.getViewRoot().getViewId();
ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
UIViewRoot viewroot = viewHandler.createView(facesContext, Refreshpage);
viewroot.setViewId(Refreshpage);
facesContext.setViewRoot(viewroot);
}i get this error
Caused By: java.lang.IllegalArgumentException: Cannot convert PRIV of type class java.lang.String to class javax.faces.component.UIComponent
at com.sun.el.lang.ELSupport.coerceToType(Unknown Source)
at com.sun.el.ValueExpressionImpl.getValue(Unknown Source)
at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:250)
at javax.faces.webapp.UIComponentELTag.createComponent(UIComponentELTag.java:222)
at javax.faces.webapp.UIComponentClassicTagBase.createChild(UIComponentClassicTagBase.java:513)
at javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassicTagBase.java:782)
at javax.faces.webapp.UIComponentClassicTagBase.doStartTag(UIComponentClassicTagBase.java:1354)
at org.apache.myfaces.trinidad.webapp.UIXComponentELTag.doStartTag(UIXComponentELTag.java:71)
at oracle.adfinternal.view.faces.unified.taglib.input.UnifiedSelectOneChoiceTag.doStartTag(UnifiedSelectOneChoiceTag.java:51)
at oracle.jsp.runtime.tree.OracleJspBodyTagNode.executeHandler(OracleJspBodyTagNode.java:50)
at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:261)
at oracle.jsp.runtime.tree.OracleJspNode.execute(OracleJspNode.java:89)
at oracle.jsp.runtime.tree.OracleJspClassicTagNode.evalBody(OracleJspClassicTagNode.java:87)
at oracle.jsp.runtime.tree.OracleJspBodyTagNode.executeHandler(OracleJspBodyTagNode.java:58)
at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:261)
at oracle.jsp.runtime.tree.OracleJspClassicTagNode.evalBody(OracleJspClassicTagNode.java:87)
at oracle.jsp.runtime.tree.OracleJspIterationTagNode.executeHandler(OracleJspIterationTagNode.java:45)
at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:261)
at oracle.jsp.runtime.tree.OracleJspClassicTagNode.evalBody(OracleJspClassicTagNode.java:87)
at oracle.jsp.runtime.tree.OracleJspBodyTagNode.executeHandler(OracleJspBodyTagNode.java:58)
at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:261)
at oracle.jsp.runtime.tree.OracleJspNode.execute(OracleJspNode.java:89)
at oracle.jsp.runtimev2.ShortCutServlet._jspService(ShortCutServlet.java:89)
at oracle.jsp.runtime.OracleJspBase.service(OracleJspBase.java:29)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:422)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:810)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:119)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:442)
at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:524)
at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:444)
at weblogic.servlet.jsp.PageContextImpl.include(PageContextImpl.java:163)
at weblogic.servlet.jsp.PageContextImpl.include(PageContextImpl.java:184)
at oracle.adfinternal.view.faces.taglib.region.IncludeTag.__include(IncludeTag.java:442)
at oracle.adfinternal.view.faces.taglib.region.RegionTag$1.call(RegionTag.java:153)
at oracle.adfinternal.view.faces.taglib.region.RegionTag$1.call(RegionTag.java:128)
at oracle.adf.view.rich.component.fragment.UIXRegion.processRegion(UIXRegion.java:503)
at oracle.adfinternal.view.faces.taglib.region.RegionTag.doStartTag(RegionTag.java:127)
at oracle.jsp.runtime.tree.OracleJspBodyTagNode.executeHandler(OracleJspBodyTagNode.java:50)
at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:261)
at oracle.jsp.runtime.tree.OracleJspClassicTagNode.evalBody(OracleJspClassicTagNode.java:87)
at oracle.jsp.runtime.tree.OracleJspBodyTagNode.executeHandler(OracleJspBodyTagNode.java:58)
at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:261)
at oracle.jsp.runtime.tree.OracleJspClassicTagNode.evalBody(OracleJspClassicTagNode.java:87)
at oracle.jsp.runtime.tree.OracleJspBodyTagNode.executeHandler(OracleJspBodyTagNode.java:58)
at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:261)
at oracle.jsp.runtime.tree.OracleJspClassicTagNode.evalBody(OracleJspClassicTagNode.java:87)
at oracle.jsp.runtime.tree.OracleJspBodyTagNode.executeHandler(OracleJspBodyTagNode.java:58)
at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:261)
at oracle.jsp.runtime.tree.OracleJspNode.execute(OracleJspNode.java:89)
at oracle.jsp.runtimev2.ShortCutServlet._jspService(ShortCutServlet.java:89)
at oracle.jsp.runtime.OracleJspBase.service(OracleJspBase.java:29)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:422)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:810)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:179)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:524)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:253)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:410)
at org.apache.myfaces.trinidad.context.ExternalContextDecorator.dispatch(ExternalContextDecorator.java:44)
at org.apache.myfaces.trinidad.context.ExternalContextDecorator.dispatch(ExternalContextDecorator.java:44)
at oracle.adfinternal.view.faces.config.rich.RecordRequestAttributesDuringDispatch.dispatch(RecordRequestAttributesDuringDispatch.java:44)
at org.apache.myfaces.trinidad.context.ExternalContextDecorator.dispatch(ExternalContextDecorator.java:44)
at org.apache.myfaces.trinidad.context.ExternalContextDecorator.dispatch(ExternalContextDecorator.java:44)
at org.apache.myfaces.trinidad.context.ExternalContextDecorator.dispatch(ExternalContextDecorator.java:44)
at org.apache.myfaces.trinidadinternal.context.FacesContextFactoryImpl$OverrideDispatch.dispatch(FacesContextFactoryImpl.java:267)
at com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:469)
at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:140)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:189)
at org.apache.myfaces.trinidadinternal.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:193)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._renderResponse(LifecycleImpl.java:911)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:367)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:222)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:205)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:106)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)
at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:271)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:177)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:179)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:119)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:442)
at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:139)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
SUBSYSTEM = HTTP USERID = <WLS Kernel> SEVERITY = Error THREAD = [ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)' MSGID = BEA-101017 MACHINE = srd-ws23042 TXID = CONTEXTID = f43e1d034e2e3af8:-7fc86077:13ae01cb0a4:-8000-0000000000000056 TIMESTAMP = 1352380663628
WatchAlarmType: AutomaticReset
WatchAlarmResetPeriod: 30000
>
my LOV IS
<af:selectOneChoice
label="#{bindings.LutOrganisationtypesView1.label}"
required="true"
shortDesc="#{bindings.LutOrganisationtypesView1.hints.tooltip}"
id="soc2" simple="true"
autoSubmit="true"
immediate="true"
binding="#{pageFlowScope.orgDetailsBean.orgCat}"
value="#{pageFlowScope.orgDetailsBean.orgCat}"
rendered="true"
valueChangeListener="#{pageFlowScope.orgDetailsBean.GetOrg}">
<af:forEach items="#{bindings.LutOrganisationtypesView1.iteratorBinding.allRowsInRange}"
var="row">
<af:selectItem id="tiltco2" label="#{row.description}"
value="#{row.organisationtypecode}"/>
</af:forEach>
</af:selectOneChoice>Edited by: adf0994 on 2012/11/08 1:34 PM
Edited by: adf0994 on 2012/11/08 4:15 PM
Edited by: adf0994 on 2012/11/08 4:49 PM -
hi all,
i am using bean in my jsp page.but it is not working it shows error. i have run this with even Tomcat or WebLogic. even i have just Copy paste code from net.
the code is
index.jsp
<%@ page errorPage="errorpage.jsp" %>
<jsp:useBean id="counter" scope="session" class="beans.Counter" />
<html>
<head>
<title>Session Bean Example 1</title>
</head>
<body>
<H3>Session Bean Example 1</H3>
<center><b>The current count for the counter bean is: </b>
<%=counter.getCount() %></center>
</body>
</html>
Bean -Counter.java
package beans;
import java.io.Serializable;
public class Counter implements Serializable{
int count = 0;
public Counter(){
public int getCount() {
count++;
return this.count;
public void setCount(int count) {
this.count = count;
and error on browser is
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /index.jsp(3,0) The value for the useBean class attribute beans.Counter is invalid.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
org.apache.jasper.JasperException: /index.jsp(3,0) The value for the useBean class attribute beans.Counter is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3320)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
Please let me know how can i handle this situationTry this
After<hsp:useBean>
<jsp:setProperty name="counter" property="setCounter" value=1 />
<jsp:getProperty name="counter" property="getCounter" /> -
Strange behavior with entity beans and servlets in a cluster
We have 2 WebLogic 4.5.1 servers in a cluster with none of the Service
Packs installed. When a client uses the deployed entity beans or
servlets they work every other time. The times they do not work nothing
happens. No exceptions, no responses to the client ( i.e. HTTP 404s ),
nothing. I suspect something in the cluster setup since we do not have
these same problems on non-clustered entity beans or servlets. We have
made sure all the entity beans have the Shared Database flag set on and
added the delayUpdatesUntilEndOfTx false to the enviroment of the DD.
That didn't fix the problem. Any ideas?
Thanks in advance,
Dallas Dempsey
DEM - Houston, TX
Do you have log files?
- Prasad
Chris Dempsey wrote:
> We have 2 WebLogic 4.5.1 servers in a cluster with none of the Service
> Packs installed. When a client uses the deployed entity beans or
> servlets they work every other time. The times they do not work nothing
> happens. No exceptions, no responses to the client ( i.e. HTTP 404s ),
> nothing. I suspect something in the cluster setup since we do not have
> these same problems on non-clustered entity beans or servlets. We have
> made sure all the entity beans have the Shared Database flag set on and
> added the delayUpdatesUntilEndOfTx false to the enviroment of the DD.
> That didn't fix the problem. Any ideas?
>
> Thanks in advance,
> Dallas Dempsey
> DEM - Houston, TX
-
Should I use JSP,JSTL,SERVLETs without a framework?
Hi Guys
I'm making a multi player browser game. The game will have some forms to setup data into the database and the player will be able to check other players data.
I will load the players data from the DB into a Bean when the application starts and then just get the other players information from DB when and if asked.
I'm planing on doing it as MVC2 using JSP, JSTL, SERVLETs, BEANs
Would you recommend me to use Struts for example? should I just use it without any framework?
I read a lot about Struts and can't really see what it can bring to an application like mine. I can use the i18n easily with JSTL and for few validation of forms I don't know if it's worth it.
What do you think? (-:
Thanks in advance
(-:If your going to use MVC2 then I would use a framework, otherwise where are you going to get your MVC from, were you planning on writing an MVC yourself?
-
Send data from bean to servlet and get results back to bean
Hi,
I'm new to this helpful forum and, as long as I'm practicing with JFS and Java Beans and Servlets, I really need some help about the following crappy issue.
I made a JSP login page called "LoginPage.jsp" (using "Visual Web JSF Page" tool in NetBeans 6.0), and the action associated to the "Login" button pression is defined in the associated Java Bean "LoginPage.java":
Code from "LoginPage.jsp":
<webuijsf:button actionExpression="#{LoginPage.loginButton_action}" binding="#{LoginPage.loginButton}" id="loginButton" primary="true" style="height: 24px; left: 383px; top: 192px; position: absolute; width: 96px" text="Login"/>
Code from "LoginPage.java":
public String loginButton_action()
if (usernameField.equals("guest") && passwordField.equals("guest")) // this control should be done by a servlet, not here!
return "loginOK"; // this is the outcome for faces-config.xml that will lead to a "Welcome.jsp" page
else
return "loginERROR"; // this is the outcome for faces-config.xml that will lead to a "Error.jsp" page
...Now, the problem is that the username and password control should not be done by the bean itself, but by a servlet (call it "LoginServlet.java").
In a few words, what I mean is that once the user writes username and password and presses the "Login" button, the called "loginButton_action()" forwards all the needed data to the servlet "LoginServlet.java", the servlet does the complete checks about login validity then prepares the result (it could be a string reporting "OK" or whatever else) and send it back to the bean "LoginPage.java", so that the flow can continue.
My problem is that I absolutely don't know how to make a bean and a servlet communicate in both ways and respectively exchange data.
Thanks in advance for any help, it will really be appreciated.Google for passing values in request and session.
-
Access of JSF Beans from Servlet Filter
Is there any way how can I access session JSF beans from servlet filter?
I need to check certain value of JSF bean stored in session scope in my filter.
Thanks
ferdoFrank,
I am not sure about phase listener, this is the whole situation:
as I am not using Container Managed Security with my JSF, after I do sucessfull login into application, I need to store some information into the session scope (user etc) and in the servlet filter I need to find out if the user is connected.
I was trying to put such info into Servlet Session directly in my bean via External Context and reading the info in Filter.
This is working fine when my application is running locally (jdev oc4j) but once deployed into Application server, when user login first time, user information is somehow removed from the session, and cannot figure out why.
So I was thinking to try another approach, to find out from servlet filter if JSF bean value is set or not.
Any other suggestions? Do not want to swicth to Container Manages Security now.
ferdo
null -
How to upload more than 100mb in using com.oreilly.servlet package
hi all,
I use com.oreilly.servlet package to upload and i use the following code to upload
MultipartRequest mr = new MultipartRequest(request,"/tmp/saved",0x10000000);My problem is i can't upload more than 25mb, uploads upto 25mb and shows page cannot displayed err in IE,
Pls helpIn the webserver there is most likely a configuration option for the maximum size that a request may have. So search through the manual of your particular webserver on how to change that.
-
i create one form based on emp. then i create beanarea and set its "Implementation Class Property"
to oracle.forms.demos.Calendar.
i copied calendar.jar from D:\oracle\ds9i\forms90\demos\jars to this lacation
D:\oracle\ds9i\forms90\java
after i write D:\oracle\ds9i\forms90\java\calendar.jar
in the below registry paths:
forms90_classpath
forms90_builder_classpath
forms90_path
but not working.i am new in oracle plz help. i want to know how to use bean in forms1. \forms\server\formsweb.cfg
archive_jini=frmall_jinit.jar,FormsProperties.jar
2. regedit
HKEY_LOCAL_MACHINE => FORMS_BUILDER_CLASSPATH
C:\DevSuiteHome_1\forms\java\frmbld.jar;C:\DevSuiteHome_1\jlib\importer.jar;
C:\DevSuiteHome_1\jlib\debugger.jar;C:\DevSuiteHome_1\jlib\utj.jar;
C:\DevSuiteHome_1\jlib\dfc.jar;C:\DevSuiteHome_1\jlib\help4.jar;
C:\DevSuiteHome_1\jlib\oracle_ice.jar;C:\DevSuiteHome_1\jlib\jewt4.jar;
C:\DevSuiteHome_1\jlib\ewt3.jar;C:\DevSuiteHome_1\jlib\share.jar;
C:\DevSuiteHome_1\forms\java\frmwebutil.jar;C:\DevSuiteHome_1\forms\java\frmall.jar;
C:\DevSuiteHome_1\forms\java\FormsProperties.jar;
3. Untuk Jdev.. include..Libraries [THE WAY I AM CREATING A BEAN..NO NEED TO READ THIS]
ORacle Forms
C:\DevSuiteHome_1\jdev\lib\ext\frmjdev_pjc.jar -
How can i upload a image file to server by using jsp or servlet.
Hi,
I m gurumoorthy. how can i upload a image file to server by using jsp or servlet without using third party API. pls anyone send me atleast outline of the source code.
Pls send me anyone.
Regards,
Gurumoorthy.I'm not an applet programmer so I can't give you much advice there.
If you want to stream the file from the server before it's entirely uploaded, then I don't believe you can treat it like a normal file. If you're just wanting to throw it up there and then listen to it, then you can treat it like a normal file.
But again, I'm not entirely certain. You might be able to stream the start of the file from the server while you're still uploading the end of it, but it probably depends on what method you're using to do the transfer. -
Problem in exchange data using Bean
Hi all,
I have a problem when creating a portal application.
I've done through the steps described in this link:
http://www.ajvic.es/irj/portalapps/com.sap.portal.pdk.htmlb.htmlbmanuals/docs/dynpage-01.html
In this example, I use bean to exchange data.
In the function <b>doInitialization()</b> in JSPDynpage.java:
public void doInitialization()
// create the bean and set a default text value "unknown user
IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();
IPortalComponentContext myContext = request.getComponentContext();
IPortalComponentProfile myProfile = myContext.getProfile();
// new bean object
UserNameContainer = new DynPageNameBean();
// set default name
UserNameContainer.setName("unknown user");
// store bean in profile for the JSP
myProfile.putValue("UserNameBean", UserNameContainer);
// Now we set the state so that we can decide what action to do next
state = INITIAL_STATE;
The code: <b>myProfile.putValue("UserNameBean", UserNameContainer);</b> give a warning: "The methode getValue(String) from the type IPortalComponentProfile is deprecated" and I see that the value of UserNameContainer is <b>not</b> assigned to "UserNameBean".
If I use this code:
UserNameContainer = (MyBeanClass) myContext.getValue("MyB");
UserNameContainer.setName(name);
The result is the same.
Do you know how to solve this problem ?
Thank you in advance & kindly regards.
TweetyHi
Here is what you should do.
First The Bean
public class UserBean implements Serializable {
private String name;
public String getName() {
return name;
public void setName(String string) {
name = string;
Next the Dynpage DoInitialization Method .
IPortalComponentRequest request =
(IPortalComponentRequest) this.getRequest();
UserBean myBean = (UserBean) request.getComponentSession().getValue("myBean");
if (myBean == null) {
myBean = new UserBean();
myBean.setName("Unknown User");
request.getComponentSession().putValue("myBean",myBean);
this.state = INITIAL_STATE;
Next the JSP
<%@ taglib uri="tagLib" prefix="hbj" %>
<jsp:useBean
id="myBean"
scope="session"
class="UserBean"
/>
<html>
<hbj:content
id="myContext">
<hbj:page
title="PageTitle">
<hbj:form
id="myFormId">
<hbj:textView
id="s1" >
<%
s1.setText(myBean.getName());
%>
</hbj:textView>
</hbj:form>
</hbj:page>
</hbj:content>
</html>
Regards
Rajendra -
How to create a pie graph in 10g or 9i forms using beans??
Hi..
Please can anyone show me how to use pie graphs in oracle 10g or 9i forms using bean?
i also want to know how to put data in pie graph.. as u know in column graph for example we have an x-axis and y-axis,and in pie there is no x-axis and y-axis.. so how i can put the same data in pie graph.. and also i may need more than one value for the x-axis or the y-axis to use in pie graph so how can i do it??
i use set_custom_property to call properties in beans.
I would so thankful for how can answer me.. please its urgent
Thanks.there are some other posts to this topic - How to create a pie graph in 10g or 9i forms using beans?? and so on.
use the search function of this forum. this may the fastest way for your urgent question
Maybe you are looking for
-
I have had Illustrator 10 installed on my PC with Vista for about a year now with no problems, but now all of a sudden it won't work! I can't really afford CS3 (the only version "officially" supported by Vista) and I need Illustrator for both work an
-
Work flows - SWW_SRV_MAIL_SEND
Hi , Please help me with the below query. Could you please explain me on how to use the Remote Function Module SWW_SRV_MAIL_SEND. This is the Function module used in the 'Send Mail step ' of the work flow. Task -- TS90000115 In particular i want to k
-
Hi, I am working with a NI 9871 (serial RS485) an I seems to have a problem with sending a command to a instrument. The instrument is connected to the NI 9871 with 2 wires, which is connected to pin 4 og 8(+) and pin 5 og 9(-) on a DB-9 connector. Is
-
HT1491 I want to download c210k running app to an ipod shuffle is this possible
I want to download C210k running app to an ipod shuffle is this possible
-
I recently bought new Ni-MH batteries for my player thinking the originals had seen their day. Unfortunately, when I installed the batteries and plugged the jukebox in with the AC adapter, nothing happened. I think I remembered seeing a battery icon