Redundant information in JSP bean action

Class Person:
public class Person{
private String name;
public void setName(String p){
name=p;
public String getName(){
return name;
}Code in servlet:
public void doPost(HTTPServletRequest request, HTTPServletResponse response) throws IOException,ServletException{
foo.Person p= new foo.Person();
p.setName("New Guy");
request.setAttribute("person",p);
RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request,response);
}Code in JSP:
<jsp:useBean id="person" class="foo.Person" scope="request">This jsp:useBean tag really is confusing. Why does it need to declare the class="foo.Person"? Why does the JSP need to know that "person" instance is derived from class foo.Person ? (I wonder if I changed this to foo.person --> not Person will result in error). Doesn't the statement request.setAttribute("person",p) from the servlet give enough info already to the JSP? thanks

The "person" in your servlet has nothing to do with your "person" in your JSP bean tag.

Similar Messages

  • How to use jsp:plugin action with type = bean

    Hi everybody,
    I'm new to JSP so it could be a stupid question but I'm wondering how can I use a jsp:plugin action with a type equal to "bean".
    Everyone is talking about type equal to applet so the browser can display this applet but if the type will be a bean so then
    does it mean I can send a javaBean class to the client?
    If yes, then can the javaBean object be executed on a client machine?
    Or maybe I'm wrong. I don't know how it works.
    Please give me a resolution.
    Thanks,
    Rafal.

    its not working.. it shows exception class not found exception.
    i have placed the jsp and applet class in the same folder. but its not working.
    jsp file path : OracleSpatial\mypackage\webmap.jsp
    applet class : OracleSpatial\mypackage\demoApplet.class
    demoApplet class inside package "mypackage".
    code inside JSP is :
    <jsp:plugin type="applet"
    code="mypackage.demoApplet.class" width = "100%" height = "100%" >
    </jsp:plugin>

  • JSP Bean Probs.

    hello,
    at first a short description of my Web App:
    1. HTML sends a value over the method="post" to my servlet-1
    2. servlet-1 sends this value to my servlet-2 ( logic - servlet)
    3. servlet-2 use this value to find the correct sql select query
    after this, a db connection starts and i get the correct db entry
    4. servlet-2 put this entry in one of my beans " loBean.setInfo1(value); "
    (as note: i have one bean class only with SET and GET methods)
    5. servlet-1 code to sends beans to my jsp file:
    req.setAttribute("wiValue",bean);
    String forwardTo = "/JSP/std_start.jsp";
    RequestDispatcher rd = req.getRequestDispatcher(forwardTo);
    rd.forward(req, res);
    6. in my JSP File i use this code to get the information in the bean
    <jsp:useBean id="wiValue" class="masterclasses.BeanWi"
    scope="request"/>
    <%= wiValue.getInfo1()%>
    <%= wiValue.getInfo2()%>
    etc.
    this functions marvelously
    And now my problem:
    Client A requests the data base worth A and B.
    A and B are indicated in the JSP side.
    At the same time Client B requests the data record C
    instead of only C to gotten he gets also A and b.
    Client b is to receive only that worth to C.
    How can I prevent this?
    PS: Excuse for my bad one English.

    Did you check if you have permission to connect to
    that database using this specific specific username?Yes, I have tried all possible permissions. MySql i working fine with php, so I thought this shoud not be a problem. Ive been deling with this problem for a week now, I just can't understand what's wrong.

  • Information about JSP

    Hi everyone,
    I am trying to collect information about JSP and was wondering if anybody could help me?
    I am trying to find something about the history, what kind of compiling language JSP is using and how it works, what kind of runtime and how it works, what kind of uniform class library and how it works.
    I am trying to find general information. I don�t want to go into details like is using Taglibs, Beans ect.
    I would appreciate the help.
    Thanks,
    Michael

    Well, JSP is Java Server Pages. I'm not sure how old it is, offhand. At least 5 years now, I guess. Generally, it uses Java as the language, although, technically, there is a language parameter of a JSP page that suggests there was some thought to supporting other languages (like ASP supports (or used to) VBScript or JScript).
    Why don't you go to the JSP page on Sun's site and read that info.

  • Prob with running jsp Bean

    Hi,
    I am trying to run a bean through a jsp but its giving error at useBean tag of jsp:
    The error is :
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: /Quadratic.jsp(7,0) The value for the useBean class attribute com.brainysoftware.Quadratic is invalid.
         org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
         org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
         org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
         org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1227)
         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:3272)
         org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
         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)
    My jsp is:
    <HTML>
    <HEAD>
    <TITLE> JSP BEAN Quadratic Example </TITLE>
    </HEAD>
    <BODY>
    <%@ page language="java" %>
    <jsp:useBean id="quadratic" scope="session" class="com.brainysoftware.Quadratic" />
    <jsp:setProperty name="quadratic" property="ia" param="a" />
    <jsp:setProperty name="quadratic" property="ib" param="b" />
    <jsp:setProperty name="quadratic" property="ic" param="c" />
    X1= <%= quad.getDx1( ) %>
    X2= <%= quad.getDx2( ) %>
    End of program
    </BODY>
    </HTML>my bean is:
    package com.brainysoftware;
    import java.io.*;
    class Quadratic{
    int ia;
    int ib;
    int ic;
    String dx1;
    String dx2;
    public int getIa( ) {
    return ia;
    public void setIa( int ii) {
    ia=ii;
    public int getIb( ) {
    return ib;
    public void setIb(int ii) {
    ib=ii;
    public int getIc( ) {
    return ic;
    public void setIc(int ii) {
    ic=ii;
    public String getDx1( ) {
    double detA;
    double result;
    detA= ib*ib -4*ia*ic;
    if(detA<0.0)
    return "Real Roots not possible";
    else {
    result= -ib - Math.sqrt(detA/(2 * ia));
    Double Dresult=new Double (result);
    return Dresult.toString( );
    public String getDx2( ) {
    double detA;
    double result;
    detA= ib*ib -4*ia*ic;
    if(detA<0.0)
    return "Real Roots not possible";
    else {
    result= -ib + Math.sqrt(detA/(2 * ia));
    Double Dresult=new Double (result);
    return Dresult.toString( );
    my directory structure is given below:
    C:\tomcat-5.0.28\jakarta-tomcat-5.0.28\webapps\jsp-examples\WEB-INF\classes\com\
    brainysoftware>dir
    Volume in drive C has no label.
    Volume Serial Number is 4C50-9542
    Directory of C:\tomcat-5.0.28\jakarta-tomcat-5.0.28\webapps\jsp-examples\WEB-IN
    F\classes\com\brainysoftware
    05/22/2005 11:15 PM <DIR> .
    05/22/2005 11:15 PM <DIR> ..
    05/22/2005 11:18 PM 134 CalculatorBean.java
    05/23/2005 12:12 AM 216 Counter.java
    05/24/2005 10:48 PM 358 SimpleJavaBean.java
    06/14/2005 11:16 PM 1,205 Calculator.java
    06/14/2005 11:16 PM 1,323 Calculator.class
    06/16/2005 06:44 PM 534 CalculatorBean2.java
    06/17/2005 08:53 AM 703 CalculatorBean2.class
    06/16/2005 07:00 PM 352 CalculatorBean2.html
    06/17/2005 08:51 AM 588 CalculatorBean2.jsp
    06/17/2005 04:29 PM 97 UploadBean.java
    06/17/2005 04:43 PM 527 FileUploadBean.java
    06/17/2005 04:43 PM 834 FileUploadBean.class
    06/18/2005 12:21 PM 863 Quadratic.java
    06/18/2005 12:21 PM 1,093 Quadratic.class
    14 File(s) 8,827 bytes
    2 Dir(s) 8,615,821,312 bytes free
    C:\tomcat-5.0.28\jakarta-tomcat-5.0.28\webapps\jsp-examples\WEB-INF\classes\com\
    brainysoftware>
    The above clearly shows the presence of Bean in the reqd directory but still I am getting an error. Can somebody help me:
    Zulfi.

    class QuadraticThe class is not public. It is only visible to other classes in the same package as itself, so the servlet (JSP) trying to instantiate and reference it can't see it.
    Make it public.

  • How to retrieve information from entity beans?

    Hi all!
    I have a problem while trying to get information from entity beans. Here it goes:
    There are two entity beans with 1:N relationship between them.
    A FacadeSB is used to find a single record in one entity bean, using the findbyPrimaryKey method.
    What is required now is to get information from the other entity bean matching the record found from the first entity bean.
    to become more clear, the db schema is like that:
    vehicle_table
    vehicleid (vehicle_pkey)
    name (type of vehicle i.e. car, bike, atv, etc)
    brand_table
    brandid (brand_pkey)
    name (brand name e.g. ferrari)
    vehicleid (foreign key to vehicle_table)
    a FacadeSB gets the vehicle_table info and passes them to a servlet generated dropdown.
    what is the best way to populate a brand dropdown based on the vehicle dropdown selection?
    thanx in advance
    I hope the problem definition is clear enough for you guys...

    thanx for the reply
    i'm ok with the finder methods you suggested. my main concern in whether to create another FacadeSB to access the brand EJB. I don't believe that's the way to go on i.e. creating a session bean for every EJB created. Shall i use the VehicleFacadeSB to access brand EJB as well?
    I can undestand that such an implementation would be a quick fix as well as not such a resources hungry hack but on the other hand, would it make any sense architecturally?
    any suggestions?
    Zac

  • NEWBIE SUPER EASY JSP / BEAN

    With about half a dozen books sitting around my desk, I can't get a REAL basic jsp to work. I FINALLY got tomcat to NOT give run time errors, however the web page simply outputs "This is output:" I know I am an idiot, but this JSP / bean stuff is upsetting. Any help on the following code would be great.
    basic.jsp is as follows:
    <jsp:useBean id="myBean" class="basic.basicbean" scope="session"/>
    <html>
    <head>
    <title>
    A Simple JSP
    </title>
    </head>
    <body>
    <%
    myBean.setBasicName("Michelle");
    %>
    This is output: <% myBean.getBasicName();%>
    </body>
    </html>
    basicbean.java is as follows:
    package basic;
    import java.beans.*;
    public class basicbean {
    private String BasicName=null;
    /** Creates new basicbean */
    public basicbean() {}
    public String getBasicName() {
    return this.BasicName;
    public void setBasicName(String value) {
    this.BasicName = value;
    Made the .java into the class put it in the basic directory under the classes/basic directory of the WEB-INF. The JSP page loads, but only output is: "This is output:" I am using Tomcat as the JSP server. "Core JSP" "Core Servlets and JavaServer Pages" "Advanced JavaServer Pages" "JSP, Servlets, and MySQL", and "Java Server Pages for Dummies" and I still can't get it. Thanks for helping out an idiot.
    -Jim

    You are very close; just a small error in the line:
    This is output: <% myBean.getBasicName();%>
    The problem is your just simply calling the method and tossing the return value. You have three ways of outputing the bean property:
    This is output: <% out.print(myBean.getBasicName();%>
    or
    This is output: <%=myBean.getBasicName()%>
    or
    This is output: <jsp:getProperty name="myBean" property="BasicName" />
    If you use the <jsp:getProperty> approach, then you must have a <jsp:useBean> somewhere above the getProperty tag.
    - Chris

  • Trigger Backing Bean Action from Java script

    Hello
    I'm quite new to JSF, Would like to know how we can trigger a bcaking bean action method using java script as part of form submit.
    Already I added one commandbutton with an action method defined in backing bean, But our requiremnt is to trigger the same action even if the user submits form by pressing Enter key.
    Targeted device is Windows Mobile IE ( In IE Mobile, we can't track onkeydown, onkeyup, onkeypress, onmousemove, onmousedown and onmouseup event. )
    1. How the JSF binds a backing bean method with JSF commandButton control on runtime. I didn't find any hidden value corresponding to this commandButton.
    2.How we can trigger a bcaking bean action method using java script as part of form submit
    Thanks
    Jobinesh

    thanks a lot for the replies. I'll try it out.
    But one question, just because of curiosity
    1. How the JSF binds a backing bean method with JSF commandButton control on runtime. I didn't find any hidden value/or any other flag corresponding to this commandButton from the genarted html for the correspondant jsf soure.

  • Difference between jsp forward action tag and response.forward()

    hi guys
    i have just started programming using j2ee technology.
    could anyone please tell me what is the difference between the jsp forward action tag and froward method using the response object?

    There really isn't one. The JSP forward tag is a convenience tag for JSP, that uses the response method.

  • Create jsp/bean webapp deploy fine...  add JSTL library wont deploy!

    winxp
    SJSE8
    PROBLEM:
    Using the new project wizard, I create a simple jsp/bean webapp using the embedded tomcat 5.5.7 as server... It deploys and runs with now issue
    Then, I right-click on project name (in project tree)... click properties... add library... select "JSTL 1.1".... do clean/build.... do deploy - which fails!
    message is: "Failed to deploy application at context path /bcd" (where bcd is my project name)
    Why does this happen?
    --------------simple app---------------
    ***jsp1.jsp****
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
        <h1>JSP Page</h1>
        <h1>get stuff JSP Page</h1>
        <jsp:useBean id="a" class="bcdpkg.IndexBean" scope="request"/>
        <h3>after1...</h3>
        <!--jsp:setProperty name="a" property="stuff" value="xxx" /-->
        <jsp:getProperty name="a" property="stuff" />
        </body>
    </html>***IndexBean.java***
    package bcdpkg;
    public class IndexBean
        /** Creates a new instance of IndexBean */
        public IndexBean()
        private String stuff = "this is stuff";
        public String getStuff()
            return this.stuff;
        public void setStuff(String s)
            this.stuff = s;
    }

    well.... I restarted SJSE8 (and tomcat 5.5.7) and now I can right-click on the project and click deploy...successfully.
    (Apologies for the "hair trigger" posting)
    I'll reply once more if it happens again.
    thanx

  • Taglib, bean action

    Hello
    I make a taglib Tree
    I have class UITree extends UICommand. In this class I have method encodeBegin(FacesContext context)
    in this method, at the beginning i have this code:
    String action="#{Bean.actionBean}";
    String actionParameter="10";
                FacesContext context = FacesContext.getCurrentInstance();
                if (UIComponentTag.isValueReference(action)) {
                    MethodBinding mb = context.getApplication().createMethodBinding(action, null);
                    setAction(mb);
                    if (actionParameter != null) {
                        ValueBinding vb = context.getApplication().createValueBinding(action);
                        setValueBinding("actionParameter", vb);
                } else {
                    setAction(Util.createConstantMethodBinding(action));
                 if (UIComponentTag.isValueReference(action)) {
                     MethodBinding vb = FacesContext.getCurrentInstance().getApplication().createMethodBinding(action, null);
                     setAction(vb);
                 } else
                     setAction(Util.createConstantMethodBinding(action));I want to call bean action (actionBean), but this action is not calling.
    why? Please help me

    Plz answer for my question

  • Redirect from jsp bean to jsp or html page

    I am facing a problem in redirecting to a jsp page from jsp bean
    How do i redirect from jsp bean to any other page like jsp or html.
    [email protected]

    Hi
    The solution you suggested we tried it long before only but it is not feasible for us as we have to implement it in all web pages which are in thousands.
    My need is like this.
    We have given specific time to each of our registered user , as user logs to our portal we calculate session time in bean and as he logs out is new time gets updated. (its like dial up connection)
    Now what happens consider user has left only 10 minutes balance, I can calculate and keep track for his time in bean.Now as the time becomes zero I want to redirect him to home page.
    As u said i can get return value zero for bean and can do it ,but our webpages are near about thousands.

  • Javascript array / jsp Bean Collection

    How can you fill a javascript array with the values of the collection?
    <jsp:useBean id="programs" scope="request" class="java.util.Collection"/>
      How can I create this array?
    <script language="JavaScript" type="text/javascript">
    var programData =
    new Array ( new Array "${programs[1].programId}","${programs[1].programName}", "${programs[1].department}"),  
                 new Array "${programs[2].programId}","${programs[2].programName}", "${programs[2].department}"),
    </script>

    I answered myself. If anyone else would like to know how to fill a javascript array with the values of a jsp beans collection.
    function collectionToArray()
    Array[rows] = [4];  
    var cnt = 0;
    <c:forEach var="sp" items="${programs}">
      rows[cnt][0] = ${sp.programId};
      rows[cnt][1] = ${sp.programName};
      rows[cnt][2] = ${sp.department};
      rows[cnt][3] = ${sp.urlLink1};
      rows[cnt][4] = ${sp.urlLink2};
      cnt++;
    </c:forEach>  
    }

  • Passing data from JSP to Action w/o form bean

    I would like to invoke an action using the content of a table cell displayed on
    a JSP as the action parameter. For example, assume the JSP has a table displaying
    the data attributes for an Employee (i.e. name, age, salary, department, etc.).
    I would like clicking the data vale for an attribute to display more detailed
    information about that attribute. So if I click on department, it would invoke
    a getDepartmentDetails action that would get the attributes for that department
    and display them on second JSP. The department attribute on the first JSP would
    be an HTML anchor. Since the getDepartmentDetails action would not have a form
    bean, how could I pass it the department id? I've heard that SP2 will support
    something called page inputs. Will this resolve this problem? Thanks.

    I have a table listing companies...I had a link over the company code to call an
    action selectCompany so that it would display a company info page.
    I did this...
    <td><netui:anchor action="selectCompany"><netui:parameter name="companyId" value="{container.item.companyId}"></netui:parameter><netui:label
    value="{container.item.companyCd}"></netui:label></netui:anchor></td>
    when I highlighted over the html link it would show
    http://localhost:7001/Admin/financialInstitution/selectCompany.do?companyId=27
    in my selectCompany action...to retrieve the parms, i did this...
    String compId = this.getRequest().getParameter("companyId");
    int iCompId = 0;
    // A company object is loaded based on the companyId parameter.
    try {
    iCompId = Integer.parseInt( compId );
    } catch (Exception exc) {
    hope that helps,
    Tom
    "Fred Criscuolo" <[email protected]> wrote:
    >
    I would like to invoke an action using the content of a table cell displayed
    on
    a JSP as the action parameter. For example, assume the JSP has a table
    displaying
    the data attributes for an Employee (i.e. name, age, salary, department,
    etc.).
    I would like clicking the data vale for an attribute to display more
    detailed
    information about that attribute. So if I click on department, it would
    invoke
    a getDepartmentDetails action that would get the attributes for that
    department
    and display them on second JSP. The department attribute on the first
    JSP would
    be an HTML anchor. Since the getDepartmentDetails action would not have
    a form
    bean, how could I pass it the department id? I've heard that SP2 will
    support
    something called page inputs. Will this resolve this problem? Thanks.

  • Sharing a bean information through jsp pages

    Morning,
    I want to use a java bean in two jsp pages, so is it possible to share it (to set its properties in the 1st page and retrieve them in the 2nd)?
    If not, what should I do? Could I use forward and set param?
    Here is my 1st jsp
    ==================
    <%@page language="java" %>
    <jsp:useBean id="doctorConn" scope="session" class="beans.DoctorBean" >
         <jsp:setProperty name="doctorConn" property="*" />
    </jsp:useBean>
    <%
    if(doctorConn.getUserId().equals("") ||doctorConn.getPassword().equals(""))
         response.sendRedirect("notAuthorised.jsp");
    System.out.println("user id : " + doctorConn.getUserId()+ " password : " +doctorConn.getPassword());
    if(doctorConn.isAuthorised(doctorConn.getUserId(), doctorConn.getPassword())) {
    %>
         <jsp:forward page="doctorApp.jsp" />
    <%
    else response.sendRedirect("notAuthorised.jsp");
    %>
    ==================
    my second
    =================
    <%@page language="java" %>
    <%@page import ="java.sql.*" %>
    <%@page import ="java.lang.Exception"%>
    <jsp:useBean id="doctorConn" scope="session" class="beans.DoctorBean" />
    <jsp:useBean id="appointment" scope="session" class="beans.Appointment" >
         <jsp:setProperty name="appointment" property="*" />
    </jsp:useBean>
    ...etc
    ===========================
    I am using Tomcat 4 and in the 2nd page I am getting an error about doctorConn
    Thank you,

    Yes ofcorse. You can do it in many ways.
    Firstly, declare properties of your bean as static that you want to share between pages and create new instance of bean on each page.
    Secondly you can store the same instance of the bean in you session. On th other page, you can retrive same instance of the bean whenever needed.
    Otherwise, you can create a gateway class that maitain static reference of you bean class.

Maybe you are looking for

  • SRM Product / Material creation - Data flow to SAP MDM

    Dear SAP friends, I need your help with 2 issues. Thanks in advance for your collaboration. Our client needs to create products and make them available to purchase almost immediately. The scenario we had working for the last 2 years was: product crea

  • How can I change the color of a object inside a symbol?

    Hello! I'm working on this study and I need to change the color of an object inside a symbol when I click another object. The object is called "bola", wich is inside the symbol "ponto" and the clicking object are the colored pencils (each pencil shou

  • PrintBrm Error 0x80070490

    We have two identical, virtual server windows 2012r2. Both servers have the role of managing printing. I do export printers using utility PrintBrm. The first time, on the second server, when I do the import, the printer drivers are installed properly

  • ITunes crashed mid-download

    I purchased and was in the process of d/l-ing season 1 of "The Office". It looks like I got 4 of the 6 episodes. At the time, I was listening to something from my library and working on other things (outside of iTunes). I'm trying to d/l these for an

  • Can't turn auto rotate off!

    Hi, I got my Xperia Z1 today, and have now checked out everything on my new phone now, and I have just. discovered that I can't turn off the auto rotate feature Not sure if this happened after I updated to 4.3 This is really annoying, I have tried to