File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clarify Mystery in JSP!

 
Kris N
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to call function from Class. First time it worked okay. Then I changed function name and did respective changes in JSP, it did not work. Please Clarify this.
Here is my JSP script:
======================
<%@ page language="java" %>
<html>
<head>
<title>Hello World - Example </title>
</head>
<body bgcolor=white>
<jsp:useBean id="Tot" scope='session' class="AddNum.SumNum" type="AddNum.SumNum" />
<jsp:setProperty name="Tot" property="*" />

<font face=arial color=red size=4><b>Display From The Bean</b></font>
<br><br>

<% int sum = 0;
sum = Tot.addNum(4,5);
out.println("Sum = " + sum);
%>

<br><br>
<font face=arial color=red size=4><b>End...</b></font>
</body>
</html>

Here is my Class:
==================
package AddNum;
public class SumNum {
int S=0;

public SumNum()
{
}
public int addNum(int a, int b)
{
S = a + b;
return S;
}
}
Thanks in advance
Kris
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using this tag:
<jsp:setProperty name="Tot" property="*" />
when the class does not have any setXXX methods?
It is hard to debug JSP if you don't have an error page designated. Setting an error page goes in your page directive:
<%@page errorPage="whoops.jsp"
Where whoops.jsp has isErrorPage="true" in the page directive - on that page you will have a default variable named exception that you can examine. Here is the whoops.jsp I used in my book as an example, where there was specific treatment for a NumberFormatException and general treatment for all others.
<HTML>
<HEAD>
<TITLE>Database Testing Entry</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<FONT FACE=VERDANA>
<H2 ALIGN=CENTER>
Shift Operator Demo Error
</H2><BR>
<%@ page language="java" isErrorPage="true" %>
<% if( exception instanceof NumberFormatException ){
%> Only numeric characters may be entered.<br>
<% } else { %>
<%= exception %>
<% } %>
</form>
</BODY>
</HTML>
Bill

------------------
author of:
 
vikas sahni
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
the reason may be that the bean's class must have been cached,
therefore whatever changes u are making in your bean is not taking effect..u can confirm it by placing the same method in the JSP file(which was there in the earlier bean and now not there),if it would run implies problem is of caching..then change the name of the bean and it would definitely work but remember for first time only.
vikas
 
Kris N
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the problem Vikas. If I change anything in Bean, the effect is not taking place in the JSP. If I reboot the system and start Java Web Server,then it is working fine. How Can we overcome this 'CACHE' problem.
Anybody help me.
Thanks
Kris
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know of any Java servlet engine that checks every possible class file for changes before working on a request. Some will reload the servlet class if it has changed.
You are better off restarting the servlet engine every time you make a change - time consuming but safe.
Bill
------------------
author of:
 
Kris N
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks William Brogden for your reply. If we have to reboot the system for every small change , then it is very time consuming especially at the Development stage.
Is it depends on Server?. Because I am using Java Web Server 2.0.
Is the same problem with TomCat?. If anybody knows ,help me.
Thanks
Kris
 
Frank Carver
Sheriff
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Kris N",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.
Thanks.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You certainly don't have to reboot the system, just stop the server and then start it again. That only takes a few seconds with Tomcat or JRun on my system - I suppose it could be worse if your application does a lot of database initialization.
Bill
 
eric moon
Ranch Hand
Posts: 133
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put tomcat startup and tomcat shutdown in my start menu, so it's extremely quick.
e
 
Kris N
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your responses.
Yes , Frank will follow rules.
Regards
Nirmala

 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic