Solved

Can I define a funtion in .jsp file?

Posted on 2004-04-22
7
240 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
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 50 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 27

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now