Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

bean class code embended in JSP page wont work

Posted on 2004-03-29
7
Medium Priority
?
201 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
  • 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 120 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Take a look at these 6 Outlook Email management tools which can augment the working and performance of Microsoft Outlook to give you a more rewarding emailing experience.
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Screencast - Getting to Know the Pipeline
Suggested Courses

926 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