Using bean methods within JSP declaration

Is it true that bean methods will not work in JSP Methods ?
For example:
// get the bean
<jsp:useBean id="FormValidate" scope="session" class="fsm.frontendCtr.FormValidate" />
// build a new method in jsp
<%!
boolean validate(HttpServletRequest req, String submitFlag) {
FormValidate.checkMandatory("ADRNACHNAME");
%>ServletExec return:
Undefined Variable or class name: FormValidate
If i use the bean Methods outside the method it worx.
Is there a trick with which I can use BeanMethods in a JSP Method?

Is it true that bean methods will not work in JSP
Methods ?
For example:
// get the bean
<jsp:useBean id="FormValidate" scope="session"
class="fsm.frontendCtr.FormValidate" />
// build a new method in jsp
<%!
boolean validate(HttpServletRequest req, String
submitFlag) {
FormValidate.checkMandatory("ADRNACHNAME");
%>ServletExec return:
Undefined Variable or class name: FormValidate
If i use the bean Methods outside the method it worx.
Is there a trick with which I can use BeanMethods in a
JSP Method?FormValidate is this Object. If you need others, pass them from parameters. Try to understand the structure of servlet generated by your JSP.
<%!
boolean validate(HttpServletRequest req, String submitFlag) {
this.checkMandatory("ADRNACHNAME");
%>
hope this helps,
yang

Similar Messages

  • How to use bean:write inside jsp:include ?

    I got a problem about JSP's syntax. The following is my code:
    <%@ include file="<bean:write name="HelloForm" property="target" />"%>
    The double quotes inside bean:write is my problem. Could you please teach me how to use bean:write within JSP's include? Thank you!

    http://java.sun.com/products/jsp/syntax/1.2/syntaxref12.html
    Include Directive vs <jsp:include>
    The include directive <%@include %> is done at page translation/compile time.
    It effectively pastes in a static file, and then compiles the JSP as if it was all one file.
    As such, you cannot provide a runtime expression to it.
    To do runtime inclusion, you need to use the <jsp:include> tag which does except runtime parameters.
    <%String test = request.getParameter("pageInfo");%>
    <%String link = test + ".jsp"; %>
    <jsp:include page="<%= link %>" %>Unfortunately you can't use the tag with a bean:write tag as well, you can only use runtime expressions, not tag. So you have to do the include with
    <jsp:include page="<%= HelloForm.getTarget() %>" />
    Cheers,
    evnafets

  • How to use protected method in jsp code

    Could anyone tell me how to use protected method in jsp code ...
    I declare a Calendar class , and I want to use the isTimeSet method ,
    But if I write the code as follows ..
    ========================================================
    <%
    Calendar create_date = Calendar.getInstance();
    if (create_date.isTimeSet) System.out.println("true");
    %>
    ============================================================
    when I run this jsp , it appears the error wirtten "isTimeSet has protected access in java.util.Calendar"

    The only way to access a protected variable is to subclass.
    MyCalendar extends Calendar
    but I doubt you need to do this. If you only want to tell if a Calendar object has a time associated with it, try using
    cal.isSet( Calendar.HOUR );

  • Problems using GET method in JSP

    Hi,
    I had some problems using GET method in JSP.
    I'm using Apache web server 1.3 and Tomcat 3.3.1 in windows 2000.
    And I'm using language English and Korean.
    When I send messages using POST method, all is good
    But when I send message using GET method, English is good, but Korean is not good.
    I tried to encode using
    URLEncode.encode(str, "UTF-8")
    and decoding it using
    URLDecode.decode(request.getParameter(tag), "UTF-8")
    but it didn't work.
    How can I receive request including Korean using GET method in JSP?
    If anyone have solutions, please let me know.
    thanks.

    Hi,
    I had some problems using GET method in JSP.
    I'm using Apache web server 1.3 and Tomcat 3.3.1 in
    windows 2000.
    And I'm using language English and Korean.
    When I send messages using POST method, all is good
    But when I send message using GET method, English is
    good, but Korean is not good.
    I tried to encode using
    URLEncode.encode(str, "UTF-8")
    and decoding it using
    URLDecode.decode(request.getParameter(tag), "UTF-8")
    but it didn't work.
    How can I receive request including Korean using GET
    method in JSP?
    If anyone have solutions, please let me know.
    thanks.This problem appears, when one use UTF-16 encoding in JSP - am I right?
    If so there are two solutions:
    1) Temporary: Use "UTF-8" - or any other 8 bit encoding scheme and
    encode Korean symbols with "&1234;" kind of escapes - though it
    may not work
    2) Absolute: get my piece of code, which I have managed to write
    just a month ago resolving absolutely similar problem with UTF-16
    in code using Chinese/Russian/English encodings
    But I wouldn't say that it's costs 10 DDs :) - it's much more
    expensive... So try 1st variant if it wouldn't help - let me know.
    I'll figure :)
    Paul

  • Javazoom UploadBean - using UploadBean properties within jsp tags

    I am working on a jsp web application and integrating the UploadBean from javazoom.net into it. I am using a MySQL database to capture all informaion about mp3 files being uploaded - filename, date, filetype, etc.
    Can someone guide me as to whether it is possible to reference the properties of the UploadFile class within a jsp tag?
    What I am trying to do is this - I want to capture the filename of the file I upload and store it in a MySQL database. Within the SimpleUpload.jsp page, the filename is accessed within scriplet code as follows:
    file.getFileName();
    (Where file is a variable representing an instance of the UploadFile class, and getFileName() is a method in this class that returns the file name you are uploading).
    What I would like to do is use this method so that this same filename can be used in a a sql:update tag to populate a database with the filename and with the other details of the file which is uploaded.
    Can anyone advise as to if this is possible and how? I tried to create a sql:update statement to populate the database with the result of file.getFileName();
    The problem is that the sql:update jsp tag can't see the file.getFileName() object and method - it doesn't know about this object and method.
    Thanks!

    I'd still appreciate an answer to this if anyone can help.
    Thanks.

  • How can we call java control source methods within jsp

    Hi guys!
              How can we access java control source methods that are defined in java control projects within jsp.I am getting error when I tried to call java control source's methods in scriptlet of JSP page.Any help/suggestion is appreciated.
              Thanks
              -Chandu

    Uh, what?
    (And you are sure that it's not a Weblogic-specific question?)

  • Accessing java class and methods within JSP

    Hi All,
    I am writing a JSP page, and need to instantiate an object of a certain class within my package, in my JSP page.
    How do I do that? Do i use the <%import = "Whatever.class" %>
    Any help would be greatly appreciated.
    Kal.

    Hi.. Thanks for ur reply.
    I am actually having a problem with the import statement. So the part where you have mypackage.Myclass, it is not working for me.
    I am using Sun Forte.. and the directory is myprojects/test/Classes/MyClass.java
    so how would the import statement look like?
    Thanks
    Kal.
    Using directive for import statements:
    <%@ page
    import="java.util.*,java.sql.*,mypackage.MyClass" %>
    Then use scriptlet:
    <%! MyClass c= new MyClass(); %>
    <%! private void method() {...} %>
    <%= c.getxxx() %>
    ...and so on

  • Using class method in JSP

    Is it possible to use method from ordinary .class file in jsp file?
    If it is, please explain.

    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
         org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

  • Writing methods within JSP that have HTML

    Hi!
    I'm programming a jsp that has a script method which iterates a vector retrived from the session and buid a menu with links.
    The HTML code interrupts the script
    <%
    script...
    %>
    <a href= ...
    <%
    more script...
    %>
    I'm getting the error:
    scriptlet close brace '}' unbalanced at line 75 which breaks scope '_base_service_scope_'
    How can I correct this?
    It looks like the HTML interruption causes the server to loose track of the brackets. Is this possible?
    Thanks and best regards
    Carlos

    no just keep tabs with the java code...and make sure whenever you introduce html code u put in a %> before the html code and before u revert back to java u put a <% before it

  • Using Beans in jsp

    hi all,
    i am using bean in my jsp page.but it is not working it shows error. i have run this with even Tomcat or WebLogic. even i have just Copy paste code from net.
    the code is
    index.jsp
    <%@ page errorPage="errorpage.jsp" %>
    <jsp:useBean id="counter" scope="session" class="beans.Counter" />
    <html>
    <head>
    <title>Session Bean Example 1</title>
    </head>
    <body>
    <H3>Session Bean Example 1</H3>
    <center><b>The current count for the counter bean is: </b>
    <%=counter.getCount() %></center>
    </body>
    </html>
    Bean -Counter.java
    package beans;
    import java.io.Serializable;
    public class Counter implements Serializable{
    int count = 0;
    public Counter(){
    public int getCount() {
    count++;
    return this.count;
    public void setCount(int count) {
    this.count = count;
    and error on browser is
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: /index.jsp(3,0) The value for the useBean class attribute beans.Counter is invalid.
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    org.apache.jasper.JasperException: /index.jsp(3,0) The value for the useBean class attribute beans.Counter is invalid.
         org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
         org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
         org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
         org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
         org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
         org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
         org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
         org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
         org.apache.jasper.compiler.Generator.generate(Generator.java:3320)
         org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
    Please let me know how can i handle this situation

    Try this
    After<hsp:useBean>
    <jsp:setProperty name="counter" property="setCounter" value=1 />
    <jsp:getProperty name="counter" property="getCounter" />

  • Calling managed bean method using ajax on jsp page loading

    Hello,
    I am using jsf1.1 i want to call managed bean method when page gets loaded using ajax.
    Thanks
    K.Ramu

    Use an ajaxical JSF framework, for example Ajax4jsf (part of RichFaces).
    But why don´t you just use the constructor of the bean class to do some stuff prior to page loading?

  • Calling a external Java method from JSP - using Tomcat server

    Hi all,
    I am trying to call a method in an external Java file from my JSP. I am using Tomcat server.
    I have my class within the package package "mypackage" and it is called myclass.class. It has only one static method mymethod() which reads from a file and writes to a file.
    I compiled the java class and I put the class file under webapps/ROOT/web-inf/classes/mypackage/myclass.class
    I am trying to say something like this from my JSP file(which is under webapps/ROOT) :
    <%@ page import = "mypackage.myclass"%>
    <% myclass.mymethod(); %>
    I am not instatiating the class as its a static method.
    This is what I get while accessing my jsp file :
    javax.servlet.ServletException: try to access class mypackage.myclass from class org.apache.jsp.index_005ftest_jsp
    To put my problem in a nutshell, Can someone guide me how to access a method of an external class from a JSP page? I have a bunch of pages doing the same operation so I thought I would have it in a method and call it from every page. Even though I tried to put the file under web-inf/classes, The JSP is not able to see the class.
    Please help.
    Thanks
    -Uday

    I have a situation that is a bit similar. I have successfully used beans for storing methods used in JSPs and used by other methods in the same class as was suggested above. Now I would like to break some methods into another (utility) class since they are lower level and can be used by lots of things. They are for database operations (given a String query and String dbname, it queries and returns ResultSet for example). I want to have them in a separate class for reusability and OOP.
    I am having problems calling those public static methods in the public class from my bean that communicates with the JSP. I can't compile the class that calls the method in the database ops class. I get an error like :
    loginHelper.java:45: cannot find symbol
    symbol : variable sqlHelper
    location: class dbHelperBean.loginHelper
    and when I include the package name in the call I get
    loginHelper.java:45: cannot find symbol
    symbol : class sqlHelper
    location: package dbHelperBean
    That's strange since the package of both classes is dbHelperBean and the class is indeed called sqlHelper. I tried to compile it in the same directory as sqlHelper as well. What am I doing wrong?
    Thanks for any help.

  • Cant find bean class from jsp page using Tomcat 4

    Hi
    I have searched numerpus forums and seen many posts from people who seem to have the same problem however none of the solutions seem to work for me.
    I have a jsp page which is trying to call a bean method however I get an error
    saying that the class for the bean cannot be found. I have :
    1. put the class in a package called kolaBean under
    C:\Program Files\Apache Tomcat 4.0\webapps\ROOT\begjsp-ch01\WEB-INF\classes\kolaPackage
    2. included the package statement in the java file for the bean
    3. included an empty constructor in the java file for the bean
    4. I have declared the above constructor as public (is this necessary?)
    5. used the full package name:
    kolaPackage.kolaBean bakedBean = new kolaPackage.kolaBean();
    6. imported import java.beans.*; (is this necessary ?)
    7. still got the same error...
    Any pointers really really appreciated
    Thanks
    Kola

    in reply to David Rons email:
    Is this a fresh install of tomcat? If so, it could be a configuration
    problem.Yes it is
    Is the class public in the package (I forget that all the time)?Yes it is. I have also declared the constructor to be public is this
    necessary?
    What's the error message?here is the error message:
    An error occurred between lines: 11 and 14 in the jsp file:
    /begjsp-ch01/kolaBean.jsp
    Generated servlet error:
    C:\Program Files\Apache Tomcat
    4.0\work\localhost\_\begjsp-ch01\kolaBean$jsp.java:59: Class
    kolaPackage.kolaBean not found.
         kolaPackage.kolaBean bakedBean = new
    kolaPackage.kolaBean();
         ^
    2 errors
    Thanks in advance
    Kola

  • Jsp:useBean and definition of bean inside jsp:declaration

    I use the following code where I define a bean in jsp:declaration
    Its name is localBean. the problem is that jsp:useBean causes
    a crash and my page is not working without understanding why.
    When I replace the localBean in the jsp:useBean with another Bean
    which is an actual class that resides in the system I have not a problem.
    Any suggestions???
    <HTML>
         <jsp:declaration>          
              static public class localBean {
                   private String value;
                   public String getValue() {
                        return value;
                   public void setValue(String value) {
                        this.value = value;
         </jsp:declaration>
         <jsp:useBean id="localBean" scope="page" class="localBean">
              <jsp:setProperty name="localBean" property="value" value="World"/>
         </jsp:useBean>
         <%-- Whatever HTTP parameters we have, try to set
              an analogous bean property -- %>          
         <jsp:setProperty name="localBean" property="*"/>
         <head>
              <title>Hello World JavaBean</title>
         </head>
         <body>
              <center>
                   <p><h1>
                        Hello
                        <jsp:getProperty name="localBean" property="value"/>
                   </h1></p>
                   <form method="post">
                        Enter a name to be greeted:
                        <input type="text" size="32" name="value"
                        value="<jsp:getProperty name='localBean' property='value'/>">
                        <br>
                        <input type="submit" value="submit"/>
                   </form>
              </center>
         </body>
    </html>          

    Thanks,
    I have added scope="application". It still show "null" indicating that the bean is not initialized with the properties. I would like a quicker way to initialize a bean property than invoking the setProperty tag for each property.
    Here is a simple example that demonstrates the problem:
    <%@ page language="java" %>
    <%@ page import="com.tests.*" %>
    <jsp:useBean id="monBean" class="com.tests.MonBean" scope="application"/>
    <%
    MonBean mb = new MonBean();
    mb.setName("toto");
    monBean= mb;
    %>
    <html>
    <head>
    <title>Lomboz JSP</title>
    </head>
    <body bgcolor="#FFFFFF">
    <jsp:getProperty name="monBean" property="name"/>
    </body>
    </html>And the bean
    package com.tests;
    public class MonBean {
    private String name;
    public String getName() {
         return name;
    public void setName(String name) {
         this.name = name;
    }This show "null".
    Any other idea why this is not working?
    Thanks,
    Julien

  • Using an attribute set in a servlet as a bean in a JSP

    Say, I have saved an attribute in any scope in a servlet or its helper class using setAttribute("xyz", someObject).
    * Would I be able to access this attribute in a subsequent JSP using <jsp:getProperty name="xyz" property"someProperty" /> *
    The reverse works true ie. setting the attribute first as a bean in a jsp and den accessing it using getAttribut

    Lakshminarayanan,
    Actually, there are 2 ways to share data between WD components:
    1. Context mapping
    2. Combo of parameters to methods / parameters in events.
    Say, you want to synchronize your 2 toolbars. You may declare some method(s) to alter state in "toolbar" component interface and some event(s) about state update. Now main component has to subscribe to this event from every component usage and invoke method in other component usage to synchronize state.
    With context mapping you may achieve state synchronization automatically. Also method/event pair will look plain ugly if you have a lot of parameters or complex structures.
    Valery Silaev
    EPAM Systems
    http://www.NetWeaverTeam.com

Maybe you are looking for