Solved

Can I define a funtion in .jsp file?

Posted on 2004-04-22
7
242 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java.util.concurrent.locks in java 3 185
How to Make JSP Pages Responsive ? details are below 3 567
Can't access image with tomcat/html 6 95
countXY challenge 28 142
Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

948 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

20 Experts available now in Live!

Get 1:1 Help Now