Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can I define a funtion in .jsp file?

Posted on 2004-04-22
7
Medium Priority
?
247 Views
Last Modified: 2010-04-01
For example, in this simple page.
----------------------------------------------------------------------------
<%@ page contentType="text/html;%>
<html>
<body>
<%
    String name = "test name";
    doSomeThing(name);  // <<------------------ question line.
    out.println(name);
 %>
</body>
</html>
----------------------------------------------------------------------------
I want to create a function and call it, such as doSomething(name).

Can I define a function in .jsp file?

such as :
-------------------------------
void doSomeThing(name){
   out.println("name" + name);
}
-------------------------------

Where should I declare function in .jsp file?

Thank you.
0
Comment
Question by:tsongwei
[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
7 Comments
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10890608
<!%
public void doSomething(String me)
{
me=something;
}
  %>

Rest of jsp
0
 

Author Comment

by:tsongwei
ID: 10891845
I have this. but it says:
Method getThis() not found in class org.apache.jsp.test$jsp.getThis();
----------------------------------------------------------------
<!%
    public void getThis(){
        out.println("oojoij");
    }
%>
<%@ page contentType="text/html"%>
<html>
<body>
<%
     getThis();
%>
</body>
</html>
-----------------------------------------------------------------
0
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 200 total points
ID: 10891937
ooops my fault....:-)

<!%
 should be...

<%! sorry abt that....

and one more thing..


out.println("oojoij");
will throw the error in the method for the simple reason that out is jsp variable and hence will not be available to the method....
you will  have to right it like


<%!
    public void getThis(JspWriter out){
        out.println("oojoij");
    }
%>
<%@ page contentType="text/html"%>
<html>
<body>
<%
     getThis(out);
%>
</body>
</html>


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:PaulS_III
ID: 10894876
I have had the same problem. Remove the "public" from the function definition. The function is scoped to the JSP as it is, so public isn't needed.

Hope that helps

Paul
0
 
LVL 28

Expert Comment

by:rrz
ID: 10895578
The exception needed to handled in oder for compilation.

<%!
    public void getThis(JspWriter out) throws java.io.IOException{
        out.println("oojoij");
    }
%>
<%@ page contentType="text/html"%>
<html>
<body>
<%
     getThis(out);
%>
</body>
</html>
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 11131307
Well I thought I gave the answer there..
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

719 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