• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

jsp and beans

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a class that I have to make into a bean and then run it with a jsp. How would I go about doing this(the basics)? How do I compile the jsp then. Thanks
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You really need a book or tutorial to cover all the details, but in a few sentences, the process is:
You compile the Bean code separately and place the class file under WEB-INF\classes for the application, just like you would for a servlet.
In the JSP you then refer to the bean with a
<jsp:useBean class="my.package.MyBean"
etc. style tag. The JSP compiler understands this syntax and compiles the JSP page into a servlet when the JSP page is addressed by a browser. You MUST put the bean code in a package.
Bill
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Verify that your class comforms to the Javabeans specs. eg. A no-arg constructor, attribute accesors (getters & setters if needed), etc.
As said by Bill, you will be better off consulting one of the books out there for more details.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the way u work depends in which sever(javawebserver,weblogic5.1,6.1) you want to place your JSP file.
for javawebserver just put the *.class version of
your bean in classes folder.
put your jsp file in public_html & call it.
 
Chanpreet Julka
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK here is where I have reached.
I have
<HTML>
<BODY>
<%!
(then I have a method defined called PrintAntennaList() in here which does some stuff and prints out something with
System.out.println)
%>
<br/><%PrintAntennaList();%><br/>

</body>
</html>
When I call the method nothing prints out. Does anyone know what the problem might be. Thank you very much.
 
Bosun Bello
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure what the <br/> tag is. You can remove it and try this.
<%=PrintAntennaList()%>
You also mentioned that you were printing some things using System.out. Just remember that that will display on the console.
Based on your questions, it seems like you do not have access to a book. I suggest you try to get one.
 
Chanpreet Julka
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the book "PURE JSP" but it doesnt seem to be helping to much. Here is my code
<%!
public static void PrintAntennaList()
{
System.out.println("in method");
}

%>
<html>
<head><title>AntennaLister2</title></head>
<body>
<h1>AntennaLister2</h1>
<br/>
<%=PrintAntennaList()%><br/>

</body>
</html>
When I run the JSP I am getting an error which says
Unable to compile class for JSP/export/home/local/tomcat/work/localhost_8080%2Fngsapps/_0002fhtdocs_0002fJSP_0002fcjulka_0002fAntennaTest_00032_0002ejspAntennaTest2_jsp_0.java:73: Incompatible type for method. Can't convert void to char[].
out.print(PrintAntennaList());
Anyone have any idea what that means or what is going on? Thanks for the help.
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are using the expression notation ( <%= %> ) which takes whatever expression is within it and converts it to text to emit as part of the response output. Since your method has no return value, it cannot be used in this context. If you are merely trying to invoke the method, you want to use the scriptlet notation ( <% %> note no equal sign).
I'd also recommend following convential Java naming conventions and start your method with a lower case letter.
hth,
bear
[ May 30, 2002: Message edited by: Bear Bibeault ]
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic