• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp and beans

 
Chanpreet Julka
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • 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.
 
abhi zulu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
  • 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: 1511
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!