Solved

bean class code embended in JSP page wont work

Posted on 2004-03-29
7
199 Views
Last Modified: 2010-04-01
i am using Sun Java System Application Server.

i found that my bean class code that embended in JSP page wont work,
--------------------------------------------------------------------------
<HTML>
<jsp:declaration>
// this is a local "helper" bean for processing the HTML form
static public class localBean
{
private String value;
public String getValue() { return value;}
public void setValue(String s) { value = s; }
}
</jsp:declaration>
<jsp:useBean id="localBean" scope="application" class="localBean" >
<%-- Every time we create the bean, initialize the string --%>
<jsp:setProperty name="localBean" property="value" value="World" />
</jsp:useBean>
<%-- Whatever HTTP parameters we have,
try to set an analogous bean property --%>
<jsp:setProperty name="localBean" property="*" />
<HEAD><TITLE>HelloWorld w/ JavaBean</TITLE></HEAD>
<BODY>
<CENTER>
<P><H1>Hello
<jsp:getProperty name='localBean' property='value'/></H1></P>
<FORM method=post>
Enter a name to be greeted:
      <INPUT TYPE="text" SIZE="32" NAME="value"
VALUE="<jsp:getProperty name='localBean' property='value'/>">
<BR>
<INPUT TYPE="submit" VALUE="Submit">
</FORM>
</CENTER>
</BODY>
</HTML>
--------------------------------------------------------------------------
i need to explicitly create a C:\Learning\JSP\WEB-INF\classes folder, extract out the embended bean code from JSP page, compile it to class file and put it in the previous folder that created explicitly. then only it will work.

may i know how can i keep continue to make the bean class code embended in JSP page work without explicitly create a class file?

thank you.

regards
yan cheng
0
Comment
Question by:yccheok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 7

Expert Comment

by:searlas
ID: 10705281
So, you're saying if you extract out the localbean declaration and compile to localbean.class it works?
The problem is that your class="localbean" attribute assumes your localbean is not defined in a package.  However, when your JSP gets compiled it is put into a package as thought it had "package jsp_servlet.subdir.subdir.subdir;" - depending on the path to your JSP.

0
 

Author Comment

by:yccheok
ID: 10705909
ya, that's it. then, how do i make my JSP noe the code is embended into the JSP file?
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10710757
no, you cannot!
0
 
LVL 7

Accepted Solution

by:
searlas earned 30 total points
ID: 10712204
I'd say, you should not - and I've never seen anyone sick enough to try.  But it is possible.

I do have a proof of concept; but it suffers from the problem that if you edit the jsp (and cause it to recompile) the instance of the inner class stored in the session no longer casts to the correct class, and so the <jsp:useBean....> throws an Exception.  Addtionally, I suspect the implementation is app-server depenedent.

Basically, yccheok, don't do this.  If you want advice on how to better structure your JSP's and bean class there's plenty of experts around here who can do that.  To continue down this track for anything other than an experiment is madness.

0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10716181
you are right searlas.
>> I suspect the implementation is app-server depenedent
I affirm it. I should have been more clearly but that's why I said no.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's recap what we learned from yesterday's Skyport Systems webinar.
This article outlines the struggles that Macs encounter in Windows-dominated workplace environments – and what Mac users can do to improve their network connectivity and remain productive.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question