Jsp:useBean vs page import in JSP
Hi,
What is the difference between jsp:useBean vs page import in JSP?
By using page import also I can call the method of the class, apart from jsp:useBean does have scope associated with it. I don't think there is any change between both the 2. Yes by using jsp:useBean we can set the property and get the property as well.
Is there any major differences between the 2 and when to use which ? Please clarify.
Thanks.
797836 wrote:
Hi,
What is the difference between jsp:useBean vs page import in JSP?
By using page import also I can call the method of the class, apart from jsp:useBean does have scope associated with it. I don't think there is any change between both the 2. Yes by using jsp:useBean we can set the property and get the property as well.
Is there any major differences between the 2 and when to use which ? Please clarify.
Thanks.Yes there is a difference.
If you use import, then you have to create/use the reference object to use the class methods. And you can't define the scopes like session, page .. etc. Apart from this you will be using scriptlets <% %>.
if you are using jsp:useBean , then you can skip the above activities. useBean takes care of it.
or you can say jsp has provided a utility to access the beans without creating its object or using scriptlets.
Similar Messages
-
Jsp:useBean giving error while compiling JSP's in JDeveloper
Hello,
I am having another problem with JSP's in JDeveloper 10.1.3. jsp:useBean and jsp:setProperty are all giving problems. I am not sure what I need to do to get rid of this error
Thanks,
LakshmisriYour original post mentions issues with jsp:useBean and jsp:setProperty, now you're talking about tag libraries and directives. Can you be more specific about what you're trying to do? Are you having problems getting JDev to recognize a tag library or are you having problems with the tag library when running the app? What directive are you trying to use that causes the termination error?
-
Javabean-Installation for jsp:usebean
Hi!
I have made a simple JavaBean. I wont use it with
<jsp:usebean> but i get:
/index.jsp(6): class 'myBean' could not be loaded
probably occurred due to an error in /index.jsp line 6:
<jsp:useBean id="my" class="klaus"/>
how must i install me Bean (not an EJB)
thanks Klaus
1. Did you weid your weblogic.properties file as:
weblogic.httpd.webApp.<AppNameHere>=<AbsolutePath>
2. Do you have the proper directory structure?
If you set the <AbsolutePath> above to C:\Temp, you'll need the following:
C:\Temp\WEB-INF\classes
You'll also need to import the bean in the code, in addition to the
jsp:usebean tag.
If the bean uses a package, (eg com.company), you'll also need
C:\Temp\WEB-INF\classes\com\company
Your .jar/.class files go in the one of the directories above, depending how
the bean was written. The <Whatever.jsp> file would go in C:\Temp in the
above example.
3. Make sure the <AbsolutePath> is in your weblogic class path.
4. Access the bean http://<server>/<AppNameHere>/<Whatever.jsp>
Chad
"klaus werner" <[email protected]> wrote in message
news:3b990f4b$[email protected]..
>
> Hi!
> I have made a simple JavaBean. I wont use it with
> <jsp:usebean> but i get:
>
> /index.jsp(6): class 'myBean' could not be loaded
> probably occurred due to an error in /index.jsp line 6:
> <jsp:useBean id="my" class="klaus"/>
>
> how must i install me Bean (not an EJB)
>
> thanks Klaus
-
Hello,
I am trying to initialize a session scope bean using the <jsp:useBean ..>
Init Code </jsp:useBean>
syntax. This works fine for the initial page load -- the information in the
bean
is there and everything looks fine. However, when I do a reload of the page,
then all of the information on the bean disappears. The setter methods of
the
bean are not getting invoked, nor are the beans constructers.
However, one thing that I do notice is that after I modify the page, then
in the WL output I see constructors called for the beans that I am using,
then I see the compilation directive for the changed JSP. It almost looks
like WL is creating some beans with the default constructors, then
when my page loads, it creates some other beans using the initialization
code.
After a reload, it then stops using the beans that have been initialized and
then uses those that have been created with the normal default constructors.
This is on WL5.1 sp6 on Solaris 8. I also tried with sp8 but there
was no difference in behavior.
If anyone has any pointers I would appreciate it. I had thought that 5.1
was up to the 1.1 JSP spec, but maybe I was mistaken. FWIW,
here is the init code I am using:
<jsp:useBean id="myFoo" scope="session" class="com.foo">
FooDAO dao = new FooDAO();
ArrayList listOfFoos = dao.getAllFoos(1);
myFoo = (Foo) listOfFoos.get(0));
</jsp:useBean>
This snippet is being statically included with a <%@ include file %>
by the page that I am invoking.
Regards,
Nathan
[email protected]
.... add the session binding interface to assist in your debugging. Post
your results. It sounds like you are losing the session, but who knows ...
Peace,
Cameron Purdy
Tangosol, Inc.
http://www.tangosol.com
+1.617.623.5782
WebLogic Consulting Available
"Nathan Cuka" <[email protected]> wrote in message
news:[email protected]...
> Hello,
>
> I am trying to initialize a session scope bean using the <jsp:useBean ..>
> Init Code </jsp:useBean>
> syntax. This works fine for the initial page load -- the information in
the
> bean
> is there and everything looks fine. However, when I do a reload of the
page,
> then all of the information on the bean disappears. The setter methods of
> the
> bean are not getting invoked, nor are the beans constructers.
>
> However, one thing that I do notice is that after I modify the page, then
> in the WL output I see constructors called for the beans that I am using,
> then I see the compilation directive for the changed JSP. It almost looks
> like WL is creating some beans with the default constructors, then
> when my page loads, it creates some other beans using the initialization
> code.
> After a reload, it then stops using the beans that have been initialized
and
> then uses those that have been created with the normal default
constructors.
>
> This is on WL5.1 sp6 on Solaris 8. I also tried with sp8 but there
> was no difference in behavior.
>
> If anyone has any pointers I would appreciate it. I had thought that 5.1
> was up to the 1.1 JSP spec, but maybe I was mistaken. FWIW,
> here is the init code I am using:
>
> <jsp:useBean id="myFoo" scope="session" class="com.foo">
> FooDAO dao = new FooDAO();
> ArrayList listOfFoos = dao.getAllFoos(1);
> myFoo = (Foo) listOfFoos.get(0));
> </jsp:useBean>
>
> This snippet is being statically included with a <%@ include file %>
> by the page that I am invoking.
>
> Regards,
>
> Nathan
> [email protected]
>
>
-
Jsp:useBean not work when I install aplication!!
Hi
I developing an application with UIX JSP on Jdeveloper 9.0.2 and i using something like this:
<jsp:useBean id="cbean" class="oracle.jsp.dbutil.ConnBean" scope="session" />
<jsp:setProperty name="cbean" property="dataSource" value="jdbc/BiblosConnectionCoreDS" />
</jsp:useBean>
<%
try{
cbean.connect();
This code work fine in standalone mode, but when i install this application on 9IAS, with an archive War, the code <jsp:useBean, not work.
What is missing for? o What is the reason for this situation
Thanks for some help?many thanks for your reply, and I have download new updates driver from your website (http://consumersupport.lenovo.com/en/DriversDownloads/drivers_show_890.html) and Installer it on my Y410 but it still does not work!!!
the firstly: when I star up with win7, I can see a speaker icon right down near the clock, when I click mouse on it, I can see: Volume Mixer - Speaker with Device(Speaker Hight definition Audio Device, Digital Audio(S/PDIF) ( Hight definition Audio Device) ).
Look in devicemanger I can see "Sound , video and game controll " has already installer with 'Hight definition Audio Device ' & 'Unimodem Hafl-Duplex Audio Device' below... but I cannot hear the sound when I play music, video, games...etc...
the second: when laptop wakeup after 'sleep' mode, I can hear sound on speaker! but headphone jack does not work when I plug my headphone jack into it (I cannot hear sound with headphone), however I still hear sound from speaker, in this case!
Can you help me or tell me how I can do ?!
Thanks and Best Regards,
jupitervn -
I'm a newbie in JSP, and I found uses <@ page import=.....> to run the java (*.class) is similar as uses <jsp:useBean id.....>, can anyone tell me what's the different between them??
Thx a lot~I didn't find any necessary to use "import" tag before use "<jsp:useBean...>" when I used "Weblogic 5.1/6.0", "JRun 3.0/3.1". But I'm sure "Tomcat4.0" have to "import" first. Some documents showed the "import" tag was not necessary in "Tomcat" before version "4.0". I don't know the special feature from this version is good or not. Could someone tell me whether it's the future feature in JSP?
-
Jsp:usebean, @page import & CLASSPATH
I hav given jsp:usebean for using the classes and then used import package mypack.* in my jsp file. But this is not recognised. I tried putting mypack (which has the class files) in webapps/ROOT/WEB-INF/classes. Still it is not working. My jsp working directory is /usr/tomcat405/webapps/examples/jsp/mydir wher my jsp file resides. I tried giving this dir in CLASSPATH and exported it in my .bashrc file in my linux system. Still the import is not working. What could b the reason?
If you put your jsp in the examples context, then put your classes into
/usr/tomcat405/webapps/examples/WEB-INF/classes/mypack
This should work even without the import line because the "classes" directory is in Tomcat's classpath.
Also be aware of case sensitivity.
hav given jsp:usebean you should use
<jsp:useBean (upper case B) -
Which one better to use - jsp:useBean or import statement
Hi,
I just want to know that which one is better to use jsp:useBean or import statement .
I can instantiate and call method of myclass -
1) by importing the class through import tag in jsp as <%@page import="myclass"%. or
2). by using <jsp:useBean tag....
i have these two option to do the same thing. i know that basically useBean is used to call setter and getter method of bean class and but it can be used to call a normal java file that have some logic .
so what should i used , which one is better and why?
useBean provides scope and object instance so no need to create object by new operator. and with import you have to create an instance .
but which tag should i use in my jsp?
i am confused???ok, means i can use jsp:useBean tag for all my
classes that are not actually bean. so it will be
instantiated at run time and provide efficiency .No. Jsp:useBean is used for java bean components.
>
but when should i use import statement in my jsp and
it happen at translation time so will it create any
type of burden for my code if i import multiple
classes.For non-java beans, you need to import the classes, period.
It's not a burden, it's a necessity. -
Trying to page import directive in a JSP access a class in default package
I am trying to import a class the is in my default package directory for Tomcat 4.1.18 (context-root\web-inf\classes\*.java). I am getting the following error
This is error using Tomcat 4.1.18
org.apache.jasper.JasperException:Unable to compile class for JSP
C:\Program Files\Tomcat4.1\work\Standalone\localhost\csc297\HTML\SearchByName_jsp.java:9: '.' expected
import Product;
C:\Program Files\Tomcat4.1\work\Standalone\localhost\csc297\HTML\SearchByName_jsp.java:10: '.' expected
import Category;
This is error using Tomcat 4.0.6
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
C:\forte4j\tomcat401\work\localhost\C_3A_5Cforte4j_5Ctomcat401_5Cwebapps_5Ccsc297\HTML\SearchByName$jsp.java:5: Class Product not found in import.
import Product;
^
C:\forte4j\tomcat401\work\localhost\C_3A_5Cforte4j_5Ctomcat401_5Cwebapps_5Ccsc297\HTML\SearchByName$jsp.java:6: Class Category not found in import.
import Category;
Here is snippet of code from my JSP:
<%@ page import= "java.util.*"%>
<%@ page import= "java.text.DecimalFormat"%>
<%@ page import="Product"%>
<%@ page import="Category"%>
Remember these classes are in my default package of my context-root
Any ideas would greatly appreciatedWeird error. Never seen this one before.
Try packaging your classes eg:package myClasses;and import them:<%@page import="myClasses.*"%>Should fix the problem.
Anthony -
Importing visual jsf page into another jsp page
Hi
I am developing a web application using jsp and struts. I want to embed a visual jsf page that Ive created into another jsp page (which is a normal jsp page, not a jsf one.)
Ive tried quite a few things but nothing seems to work..
<jsp:include page="Page2.jsp">
Ive surrounded the code in the f:subview tags. still doesnt work.
Ive tried using <jsp:useBean id="Page2" scope="page" class="visualwebapplication.Page2" > .. It does not give me an error, but does not embed the page as well. Do I need to some other code after this to use the above bean to display the page.
Any help would be greatly appreciated.
Regards
Sparsh AgarwalHi
This is the error message that is generated in the tomcat log once i try to load the homePage.do
Jul 31, 2008 2:27:47 PM org.apache.catalina.core.ApplicationContext log
SEVERE: Cannot forward after response has been committed
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:302)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:408)
at com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:442)
at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:115)
at com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.renderView(ViewHandlerImpl.java:320)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
at com.sun.faces.extensions.avatar.lifecycle.PartialTraversalLifecycle.render(PartialTraversalLifecycle.java:106)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:557)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:481)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
at org.apache.jsp.view.main_005fright_jsp._jspService(main_005fright_jsp.java:54)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:557)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:481)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:609)
at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:99)
at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:135)
at org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:760)
at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:892)
at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:462)
at org.apache.jsp.view.templates.layoutBase_jsp._jspx_meth_tiles_005finsert_005f5(layoutBase_jsp.java:255)
at org.apache.jsp.view.templates.layoutBase_jsp._jspService(layoutBase_jsp.java:120)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:239)
at org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:341)
at org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:572)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:221)
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.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:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Jul 31, 2008 2:27:47 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:302)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:408)
at com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:442)
at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:115)
at com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.renderView(ViewHandlerImpl.java:320)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
at com.sun.faces.extensions.avatar.lifecycle.PartialTraversalLifecycle.render(PartialTraversalLifecycle.java:106)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:557)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:481)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
at org.apache.jsp.view.main_005fright_jsp._jspService(main_005fright_jsp.java:54)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:557)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:481)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:609)
at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:99)
at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:135)
at org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:760)
at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:892)
at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:462)
at org.apache.jsp.view.templates.layoutBase_jsp._jspx_meth_tiles_005finsert_005f5(layoutBase_jsp.java:255)
at org.apache.jsp.view.templates.layoutBase_jsp._jspService(layoutBase_jsp.java:120)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:239)
at org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:341)
at org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:572)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:221)
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.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:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Jul 31, 2008 2:27:47 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:302)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:408)
at com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:442)
at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:115)
at com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.renderView(ViewHandlerImpl.java:320)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
at com.sun.faces.extensions.avatar.lifecycle.PartialTraversalLifecycle.render(PartialTraversalLifecycle.java:106)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:557)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:481)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
at org.apache.jsp.view.main_005fright_jsp._jspService(main_005fright_jsp.java:54)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:557)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:481)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:609)
at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:99)
at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:135)
at org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:760)
at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:892)
at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:462)
at org.apache.jsp.view.templates.layoutBase_jsp._jspx_meth_tiles_005finsert_005f5(layoutBase_jsp.java:255)
at org.apache.jsp.view.templates.layoutBase_jsp._jspService(layoutBase_jsp.java:120)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:239)
at org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:341)
at org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:572)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:221)
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.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:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Jul 31, 2008 2:27:47 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: ServletException in '/view/main_right.jsp': Cannot forward after response has been committed
at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:923)
at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:462)
at org.apache.jsp.view.templates.layoutBase_jsp._jspx_meth_tiles_005finsert_005f5(layoutBase_jsp.java:255)
at org.apache.jsp.view.templates.layoutBase_jsp._jspService(layoutBase_jsp.java:120)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:239)
at org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:341)
at org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:572)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:221)
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.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:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Jul 31, 2008 2:27:47 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet action threw exception
javax.servlet.jsp.JspException: ServletException in '/view/main_right.jsp': Cannot forward after response has been committed
at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:923)
at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:462)
at org.apache.jsp.view.templates.layoutBase_jsp._jspx_meth_tiles_005finsert_005f5(layoutBase_jsp.java:255)
at org.apache.jsp.view.templates.layoutBase_jsp._jspService(layoutBase_jsp.java:120)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:239)
at org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:341)
at org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:572)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:221)
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.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:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619) -
I'm running JSPs and servlets under Netscape (Tomcat) web server and am getting errors with my jsp file's first line:
[%@page import="java.util.*, myclass" %]
Netscape server throws an error saying that it can't import myclass. I've put the myclass.class file in various locations in the server but it still can't find it. Does anyone know a foolproof way to make the server find such a class when it's compiling jsp's?
Thanks,
DavidI think you have to specify package name of your class & not your calss name.
-
How can i load A gui JTable bean through jsp:useBean tag in a jsp page
Hi,
i am chiranjit , i am in a jsp project . i am desparately looking a solution for below stated problem:
i want to make a jsp page for master entry , that why i want to load a GUI Java bean in my jsp page.This GUI Bean contaning a JTable in which allow grid type data entry in the jsp page. But i am unable load that bean in the jsp page through jsp:useBean tag in my page.So if you have any solution then send in the forum as early as possible.
Thank you
chiranjitNo can do. JSPs can only output plain HTML (and javascript...) They are not used like normal Java classes.
If you need a complex GUI then you might use an Applet instead. If you want to use a JSP then you are stuck using normal HTML components, like <table> <form...> <input type="text"> etc... -
Hi,
i've got a problem with importing java classes into my jsp file. i use the following method:
<%@ page import="Person" %>
Person is originally a selfwritten class which lies in the subdirectory WEB-INF/classes of my webapps directory of my tomcat server. when i use the above method i get the following error output:
org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 125 in the jsp file: /ShowPersonsView.jsp Generated servlet error:
[javac] Compiling 1 source file 3 3 /usr/local/tomcat/work/Standalone/localhost/address/ShowPersonsView_jsp.java:7: '.' expected
import Person;
^
/usr/local/tomcat/work/Standalone/localhost/address/ShowPersonsView_jsp.java:231: cannot resolve symbol
symbol : class Person
location: class org.apache.jsp.ShowPersonsView_jsp
Person tempperson;
^ An error occurred at line: 125 in the jsp file: /ShowPersonsView.jsp Generated servlet error:
/usr/local/tomcat/work/Standalone/localhost/address/ShowPersonsView_jsp.java:238: cannot resolve symbol
symbol : class Person
location: class org.apache.jsp.ShowPersonsView_jsp
tempperson = (Person)it.next();
^
3 errors at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:120)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:313)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:324)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:474)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:184)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
at ShowPersonsPrepare.doGet(ShowPersonsPrepare.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:380)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:533)
at java.lang.Thread.run(Thread.java:536)
Thus, the Person class can not be found but i dunno why. Where do I have to make an entry? I already tried to set a classpath to this file, but it doesn't work. Has anyone an idea?
ThanxPut the class in a package and call it accordingly. Example:
WEB-INF
|
--- classes
|
--- example
|
--- Person.java
//then in Person add:
package example;
//and in jsp
<%@ page import="example.Person" %> -
Jsp:useBean and assigning a value to that bean
Hello,
I have a type called Country and I have declared a bean using the "jsp:useBean" syntax.
I then try to assign a value to that bean in a scriptlet. Eventually I try to retrieve the values using "jsp:getProperty". The problem is that it appears to null.
Here is the code of the jsp
<%@ page language="java" %>
<%@ page import="com.parispano.latinamericaguide.*" %>
<%
/* We retrieve the Countries object from the servlet context. */
ServletContext sc = getServletContext();
Countries cs = (Countries)sc.getAttribute("countries");
%>
<jsp:useBean id="country" class="com.parispano.latinamericaguide.Country"/>
<%
/* If the request contains a country id, then we set the variable. */
country = cs.getCountryFromId(Integer.parseInt(request.getParameter("countryID")));
%>
<html>
<head>
<title>Country details</title>
</head>
<body>
<table>
<tr><td>Name</td><td><jsp:getProperty name="country" property="name"/><!-- This is not working--></td></tr>
<table>
<%
out.println(country.getName());//This is working
%>
</body>
</html>This is the code for the bean
package com.parispano.latinamericaguide;
* @author Julien Martin
* Represents a country.
public class Country implements Comparable {
private int id;
private String name;
private int landArea;
private String capital;
private String currency;
private String flag;
private String internet_domain;
private String dialling_code;
private float literacy;
private float male_life_expectancy;
private float female_life_expectancy;
private String map;
private int population;
private int population_year;
private float birth_rate;
private int birth_rate_year;
private float death_rate;
private int death_rate_year;
private int gdp;
private int gdp_per_head;
private int gdp_year;
private float unemployment_rate;
private int unemployment_rate_year;
public Country() {
public Country(
int id,
String name,
int landArea,
String capital,
String currency,
String flag,
String internet_domain,
String dialling_code,
float literacy,
float male_life_expectancy,
float female_life_expectancy,
String map,
int population,
int population_year,
float birth_rate,
int birth_rate_year,
float death_rate,
int death_year_rate,
int gdp,
int gdp_year,
float unemployment_rate,
int unemployment_rate_year) {
this.id = id;
this.name = name;
this.landArea = landArea;
this.capital = capital;
this.currency = currency;
this.flag = flag;
this.internet_domain = internet_domain;
this.dialling_code = dialling_code;
this.literacy = literacy;
this.male_life_expectancy = male_life_expectancy;
this.female_life_expectancy = female_life_expectancy;
this.map = map;
this.population = population;
this.population_year = population_year;
this.birth_rate = birth_rate;
this.birth_rate_year = birth_rate_year;
this.death_rate = death_rate;
this.death_rate_year = death_year_rate;
this.gdp = gdp;
this.gdp_year = gdp_year;
this.unemployment_rate = unemployment_rate;
this.unemployment_rate_year = unemployment_rate_year;
public float getBirth_rate() {
return birth_rate;
public int getBirth_rate_year() {
return birth_rate_year;
public String getCapital() {
return capital;
public String getCurrency() {
return currency;
public float getDeath_rate() {
return death_rate;
public int getDeath_rate_year() {
return death_rate_year;
public String getDialling_code() {
return dialling_code;
public float getFemale_life_expectancy() {
return female_life_expectancy;
public String getFlag() {
return flag;
public int getGdp() {
return gdp;
public int getGdp_per_head() {
return gdp / population;
public int getGdp_year() {
return gdp_year;
public int getId() {
return id;
public String getInternet_domain() {
return internet_domain;
public float getLiteracy() {
return literacy;
public float getMale_life_expectancy() {
return male_life_expectancy;
public String getMap() {
return map;
public String getName() {
return name;
public int getPopulation() {
return population;
public int getPopulation_year() {
return population_year;
public int getLandArea() {
return landArea;
public float getUnemployment_rate() {
return unemployment_rate;
public int getUnemployment_rate_year() {
return unemployment_rate_year;
public void setBirth_rate(float f) {
birth_rate = f;
public void setBirth_rate_year(int i) {
birth_rate_year = i;
public void setCapital(String string) {
capital = string;
public void setCurrency(String string) {
currency = string;
public void setDeath_rate(float f) {
death_rate = f;
public void setDeath_rate_year(int i) {
death_rate_year = i;
public void setDialling_code(String string) {
dialling_code = string;
public void setFemale_life_expectancy(float f) {
female_life_expectancy = f;
public void setFlag(String string) {
flag = string;
public void setGdp(int i) {
gdp = i;
public void setGdp_per_head(int i) {
gdp_per_head = gdp/population;
public void setGdp_year(int i) {
gdp_year = i;
public void setId(int i) {
id = i;
public void setInternet_domain(String string) {
internet_domain = string;
public void setLiteracy(float f) {
literacy = f;
public void setMale_life_expectancy(float f) {
male_life_expectancy = f;
public void setMap(String string) {
map = string;
public void setName(String string) {
name = string;
public void setPopulation(int i) {
population = i;
public void setPopulation_year(int i) {
population_year = i;
public void setlandArea(int i) {
landArea = i;
public void setUnemployement_rate(float f) {
unemployment_rate = f;
public void setUnemployment_rate_year(int i) {
unemployment_rate_year = i;
public String toString() {
return name;
public int compareTo(Object o) {
Country c = (Country)o;
int cmp = name.compareTo(c.name);
System.out.println(cmp);
return cmp;
}Can anyone please help?
Thanks in advance,
Julien.Thanks,
I have added scope="application". It still show "null" indicating that the bean is not initialized with the properties. I would like a quicker way to initialize a bean property than invoking the setProperty tag for each property.
Here is a simple example that demonstrates the problem:
<%@ page language="java" %>
<%@ page import="com.tests.*" %>
<jsp:useBean id="monBean" class="com.tests.MonBean" scope="application"/>
<%
MonBean mb = new MonBean();
mb.setName("toto");
monBean= mb;
%>
<html>
<head>
<title>Lomboz JSP</title>
</head>
<body bgcolor="#FFFFFF">
<jsp:getProperty name="monBean" property="name"/>
</body>
</html>And the bean
package com.tests;
public class MonBean {
private String name;
public String getName() {
return name;
public void setName(String name) {
this.name = name;
}This show "null".
Any other idea why this is not working?
Thanks,
Julien -
Why do we need jsp:useBean???
Hi All,
I am going over both the J2EE tutorial and JSP1.2 spec.
As far as I read, it seems to me that "jsp:useBean" is a way of creating a bean object.
<jsp:useBean id="local" scope="application" class="Mylocales">
If I put the class file in the import statement, can I create the object in the scriptlet
<% Mylocales local = new Mylocales(); %>
and set/get properties by calling
local.setName(); // assume these methods are in the class
local.getName();
without using "jsp:setProperty" and "jsp:getProperty".In this way, isn't it a redundancy to have "jsp:useBean" in JSP spec? We can always create any kind of objects in the scriptlets.
Since "jsp:useBean" has been there for years, I believe something must be wrong with my rationale. However, both the spec and the tutorial couldn't answer this question. Can anyone clear it up to me?
Thx in advance.
KevinThere's nothing wrong with your rationale; useBean IS a redundant tag, but it does provide some compact functionality without having to write extra code.
http://java.sun.com/products/jsp/tags/11/syntaxref1115.html covers the syntax of this tag; one advantage of using this tag is the 'scope' attribute, that allows you to define, at object creation, just how long the object will be around. You can limit an object's scope to the page that declared it, or allow it to be accessed by any page that shares the same session, or request, or application.
I do believe that the main point of this tag comes in at the design level; one of the strongest reasons to use JSPs at all is to separate out the application logic from the page presentation. This means that anyone who can use HTML should be able to maintain the JSP pages in the application. Instead of having to teach a non-programmer a little bit of code, just demonstrate the use of a single tag that can be reused throughout the application. The logical extension of this idea is the tag library.
Myself, I mix and match as needed, but there are never more than a few lines of scriptlet code in my JSP pages. If there's more code than HTML in my JSP page, I'll go ahead and use a servlet instead.
Anyway, I guess my point is that JSP pages are flexible, you can pick the functionality that you want to use, and the useBean tag isn't quite superfluous.
Maybe you are looking for
-
I want to find out how to add my mixed CD's under the folder of the artist. I want to save them on my computer in itunes. I want to NAME the album, but so far I haven't been able to do that. I named ONE and then ALL the rest of the CD's I am tryin
-
Lightroom, Photoshop, Premiere on a Lenovo laptop running XP professional
have no idea why or how and not going to buy a support to report or resolve a problem with the software I paid hundreds of $$ for already after switching from 20 years using JASC/Corel Paintshop Pro, Ulead Studio, etc. Problem or Question 1: C++ runt
-
There is something that has come as part of 8.1.1 that I wonder how many are aware of it or how nice it is. Traditionally or historically we have been accustom to Desktop & Taskbar. Not long ago came the ability to Pin things to Taskbar. Recently, th
-
Why do I get "error" on all print attempts after installed a new HP print driver?
I installed a new HP print driver today and now I get an "error" message on ALL print jobs - even to printers I have used without problems for months. Any idea what got changed on my Mac?
-
Context Element Issue In OVS Usage
Hi Experts, I have a table to which there has been an OVS declared for a Paticular column. The ovs is working fine but the problem arises when i click on some value in the ovs the selected value goes and sits in the first row as that is the lead