Servlet passing values to JSP and ClasscastException

I am using weblogic 5.1 to run my Servlets.
          I want to know when I forward from a servlet to a JSP how do I pass
          values especially Java Objects (Sometimes Objects of User written Java
          classes).
          Uptil now I have been putting all values in the session from where the
          JSP picks them up, but somehow I have a feeling that this is not the
          right way.
          In a code I am putting a Java Object (It contains two attributes of
          Java.util.Vector type) in the session so that the JSP to which I am
          forwarding it to can use it I have put my class in the ServletClasses.
          Intertestingly it runs well till the contents of the Vector are changed.
          As the contents of the vector are changed, it throws ClassCastException
          The StackTrace is as follows:
          java.lang.ClassCastException
          at
          jsp_servlet._select_95_account_95_profile._jspService(_select_95_account_95_pro
          file.java, Compiled Code)
          at weblogic.servlet.jsp.JspBase.service(JspBase.java, Compiled
          Code)
          at
          weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java,
          C
          ompiled Code)
          at
          weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.j
          ava:143)
          at
          com.logistics.optistopasp.servlet.AccountSelectServlet.doPost(AccountSelectServ
          let.java, Compiled Code)
          at
          com.logistics.optistopasp.servlet.AccountSelectServlet.doGet(AccountSelectServl
          et.java:35)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
          at
          weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java,
          C
          ompiled Code)
          at
          weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.j
          ava, Compiled Code)
          at
          weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.j
          ava, Compiled Code)
          at
          weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextMan
          ager.java, Compiled Code)
          at
          weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java,
          Compile
          d Code)
          at
          weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java,
          Compiled Code
          at weblogic.kernel.ExecuteThread.run(ExecuteThread.java,
          Compiled Code)
          Can anybody please Help!!!!.
          Thanks
          Pankaj
          

Only can confirm your finding - the jsp is using a different class loader to the servlet that originally instantiated the object. There's the rub. I haven't figured out yet how to fix that. I can get the classloader but don't know how to get the runtime to use that class loader to perform cast.
          

Similar Messages

  • Passing values between jsp and php

    hi there, is it possible to pass values between jsp and
    php? i really need to find out the way if there is
    any. thanks in advance
    -azali-

    Yes, there are a few ways to do this.
    1) Think about using Cookies.
    2) Maybe use a Redirect passing the values in the Query string.
    3) Retain the data in a repository in the back end.
    4) Using Hidden fields within your pages.
    I am sure you can use these Idea's for a base to develop other methods on how to pass values back and forth from JSP -> PHP and vice versa.
    -Richard Burton

  • Servlet passing Values to JSP

    I want to know when I forward from a servlet to a JSP how do I pass
              values especially Java Objects (Sometimes Objects of User written Java
              classes).
              Uptil now I have been putting all values in the session from where the
              JSP picks them up, but somehow I have a feeling that this is not the
              right way.
              Suppose my servlet is forwarding to a jsp . What should it do in case an
              exception happens in the servlet and wants to forward it to the jsp.
              Putting the Exception object in the session is an alternative but I
              wonder that is the best approach.
              If someone knows a better way od doing it, please help.
              Pankaj
              

    You could probably use setAttribute
              ..before forwarding the control to JSP.
              req.setAttribute("message", "Hello, world");
              ServletContext app = getServletContext();
              RequestDispatcher disp;
              disp = app.getRequestDispatcher("Dispmessage.jsp");
              Cheers,
              Naggi
              pankaj wrote:
              > I want to know when I forward from a servlet to a JSP how do I pass
              > values especially Java Objects (Sometimes Objects of User written Java
              > classes).
              > Uptil now I have been putting all values in the session from where the
              > JSP picks them up, but somehow I have a feeling that this is not the
              > right way.
              > Suppose my servlet is forwarding to a jsp . What should it do in case an
              > exception happens in the servlet and wants to forward it to the jsp.
              > Putting the Exception object in the session is an alternative but I
              > wonder that is the best approach.
              > If someone knows a better way od doing it, please help.
              >
              > Pankaj
              

  • Passing values between JSP and Bean

    I am trying to validate a date entered by the user on a form. I need to do an "alert" when the user enters a date outside of the valid range depending on a value entered in a drop down.
    Am doing this in checkform function. Here is what I want to do:
    1. Send the the value from the drop down and the date to bean to do the calculations. Call the EJB function from checkform.
    2. Get a string values back into the jsp from the bean
    3. Blow an error to the user to enter a valid date.
    Any help in this case would be greatly appreciated.
    Thanks.

    I only see some design requirements.
    What's the exact coding question? Where are you stucking while coding those requirements accordingly?

  • Passing value from JSP to JApplet

    Hello,
    I am stuck up with a problem, can anyone please tell me how do i pass a value from a JSP page
    to a JApplet,
    and the parameter passed through JSP should be displaed in the JTextArea.
    It would be kindful if any of you could help.
    Thanks
    Sanam

    hello,
    thanks for reply.
    I know how to pass parameters from html,
    I want to pass values from jsp page,
    and i dono how to do it, may be we cann pass values through url connection but i dono how.
    if anone knows plz help me in solving this.
    i hvae posted my applet code.
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.JToolBar;
    import javax.swing.JButton;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.JPanel;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    <applet code = "DocApplet" width = 500 height =5000>
    </applet>
    public class DocApplet extends JApplet
         private JPanel jp;
         private Container cp;
         private JTextArea jt;
         private JToolBar tb;     
         private JScrollPane sp;
         private String annotation;
         private String url;
         private Connection con;
         private Statement stmt;
         public void init()
              jp = new JPanel();
              cp = getContentPane();
              jt = new JTextArea();
              tb = new JToolBar();
              sp = new JScrollPane(jt);
              repaint();
         public void start()
              jp.setLayout(new BorderLayout());
              jp.add(tb, BorderLayout.NORTH);
              jp.add(sp, BorderLayout.CENTER);
              jt.setBackground(Color.BLACK);
              jt.setForeground(Color.WHITE);
              setContentPane(jp);
              addButtons(tb);
              repaint();
         public void run()
              repaint();
         public void paint()
         private void addButtons(JToolBar tb)
              JButton button = null;
              button = new JButton("Save");
              button.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
              tb.add(button);
    }

  • Use context to pass value between JPF and Java Control

    hi,
    Can we use context to pass value between JPF and Java Control? It works if i m using InitialContext in the same machine but i dun think it will works if i put Web server and application server in different machine. Anyone have an idea how to do it?
    I also want to get the method name in the onAcquire callback method. Anyone knows how to do this?
    thks
    ?:|

    Hi.
    Yoy can the next options for make this:
    1. Pass your values in http request.
    example: http://localhost/index.jsp?var1=value1&var2=value2&var3....
    2. You can use a no visible frame (of height or width 0) and keep your variables and values there using Javascript, but of this form, single you will be able to check the values in the part client, not in the server. Of this form, the values of vars are not visible from the user in the navigation bar.
    Greeting.

  • How can I pass value in status and reason for rejection using BAPI_LEAD_CREATEMULTI when creating multiple lead

    Hello,
    I want pass value in STATUS and Reason for rejection according to requirement when i am creating multiple lead using BAPI_LEAD_CREATEMULTI. Please help me how can i pass value. Please give some sample code that in which table i have to pass values and please also tell me INPUT_FIELDS values. Please help me
    Regards,
    Kshitij Rathore

    Hello,
    Please help me for solve this problem. I am trying to solve problem from last 4 days but i didn't get any solution.
    Regards,
    Kshitij Rathore

  • How to pass value from jsp to java bean

    I have huge problem . How to pass value from jsp value to java bean.Please replay me soon

    Use the <jsp:setProperty> tag. There are several ways to use it. The one you probably want is:
    <jsp:setProperty name="bean_name"  property="property_name"  value="the_value_you_want_to_set"/>

  • Passing parameters between JSP and Servlet

    The scenario is as follows:
    There is a JSP page that sends a string as a hidden parameter to a servlet:
    <input type="hidden" name=<%= Book.NAME %> value=<%= book.getName() %> >
    In the servlet there is a print statement that checks the parameter value:
    System.out.println("Book name: "+request.getParameter(Book.NAME));
    The problem is as follows: if the name of the book consists of more than one word
    such as "Servlets and JSP", the print statement will print only Servlet.
    If the JSP page passes a string directly as shown here:
    <input type="hidden" name="Test" value="Test String" >
    The servlet will print the complete string: Test String
    The same problem appears if the string is passed between two JSP pages.
    Any help is greatly appreciated.
    Regards,
    Basil Mahdi

    You might want to try
    <input type="hidden" name="<%= Book.NAME %>" value="<%=URLEncode.encode(book.getName(), "UTF-8")%>" >This will take care of any wierd un-url friendly charcters that might appear in the book titles such as the ' or " which may be the problem.

  • Passing value from JSP to scriptlet

    Hi
    I am trying to find a way to pass a value from jsp to the scriptlets, i.e.
    <c:set var="testValue" value="123" />
    <%
    System.out.println(testValue);
    %>
    the above code just demonstrates what I was trying to achieve, by passing the value from the jsp into the scriptlet.
    Can someone tell me if there's an easy way to do this?
    Thank you.

    Note, using scriptlet code on your page is generally something to be avoided. 99% of what you should be doing on a JSP page can be done with EL/JSTL. If you can't do it with EL/JSTL then it probably belongs in a servlet/bean.
    I always aim for 100% scriptlet free jsp pages.
    Having said that, I can still answer your question: EL attributes are stored in the scope - page, request, session, application
    ${testValue} is equivalent to pageContext.findAttribute("testValue").
    The <c:set> tag example doesn't specify a scope, so therefore you could get it like this:
    <c:set var="testValue" value="123" />
    <%
    String testValue = (String)pageContext.getAttribute("testValue");
    System.out.println(testValue);
    %>alternatively exploit the feature of the useBean tag that creates a scriptlet variable:
    <c:set var="testValue" value="123" />
    <jsp:useBean id="testValue" type="java.lang.String"/>
    <%
    System.out.println(testValue);
    %>Note that the EL variable and the Scriptlet variable are initially pointing at the same String.
    But changing the string in scriptlet code will change the value it is pointing at, while leaving the EL variable untouched.
    If you have a List in scope, and sharing it between EL and scriptlet variables then any changes to the list would be reflected because they both point at the same List object.
    cheers,
    evnafets

  • Passing value from JSP to JSPDynPage onclick of link

    Hi,
    I have extracted a value in the JSP page and i want to send this value back to the JSPDynPage on click of a link(the link is dependent on the value).
    How can i do that?

    hi Sujoy,
    you can pass values by using beans and display the passed data in a new jsp page.
    firstly create a jsp page,that accepts user data,say for example i am placing a text box and a button,
    next,create a jspdyn page---
    private final static int INITIAL_STATE = 0;
        private final static int FINAL_STATE = 1;
        private int state = INITIAL_STATE;
        private final static String BEAN_KEY="nameBean";
        public void doInitialization(){
          IPortalComponentRequest request=(IPortalComponentRequest) this.getRequest();
          IPortalComponentContext ctxt=request.getComponentContext();
          displayNameBean mybean = new displayNameBean();
          ctxt.putValue(BEAN_KEY,mybean);
    public void doProcessAfterInput() throws PageException {
             InputField myInputField = (InputField) getComponentByName("user_name");
    if (myInputField != null) {
    IPortalComponentRequest request=(IPortalComponentRequest) this.getRequest();
    IPortalComponentContext ctxt = request.getComponentContext();
                 displayNameBean mybean1=(displayNameBean)ctxt.getValue(BEAN_KEY);
                   mybean1.setName(myInputField.getValueAsDataType().toString());
        public void doProcessBeforeOutput() throws PageException {
          switch (state){
               case INITIAL_STATE:
               this.setJspName("loginPage.jsp");
               break;
               case FINAL_STATE:
               this.setJspName("successloginPage.jsp");
               break;
        public void onButtonClick(Event event) throws PageException {
             state=FINAL_STATE;       
    finally display this value in a new jsp page as follows--
    <jsp:useBean id="nameBean" scope="application" class="NewProject.bean.displayNameBean" />
    <%@ taglib uri= "tagLib" prefix= "hbj"%>
    <hbj:content id="myContext" >
      <hbj:page title="PageTitle">
       <hbj:form id="myFormId" >
    <hbj:textView
         id="welcome_note"
         design="HEADER2">
         <% 
         welcome_note.setText
         (nameBean.getName());
         %>
    as simple as that!!
    regards
    SwarnaDeepika
    P.S:Please reward points for helpful answers.

  • Passing values between jsp pages

    Hi all,
    I am a newbie to jsp. I am trying to pass value from one jsp to another.
    Let me post the code here and make my point clear. I have 3 jsp pages and am trying to get the value into my 3rd page that was in the first page.
    This is my Test.jsp page:
    <%@page contentType="text/html"%>
    <html>
    <head><title>Test JSP Page</title></head>
    <body>
    <%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
    <%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
    Testing.. JSP Page
    <FORM action='Response.jsp' method="POST">
    <input type='Text' name='get_name'>
    <input type="submit" value="Click Me">
    </FORM>
    </body>
    </html>
    This is my response.jsp page:
    <%@page contentType="text/html"%>
    <%@page import = "sun.jdbc.rowset.CachedRowSet" %>
    <html>
    <head><title>Response Page</title></head>
    <body>
    <%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
    <%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
    Thank you... <%=request.getParameter("get_name") %>
    // I want to pass this get_name to my next page, but since request.getParameter returns an object and not a string, how will I capture the value and pass it to my next page.
    </body>
    </html>
    The 3rd jsp page is:
    <%@page contentType="text/html"%>
    <html>
    <head><title>JSP Page</title></head>
    <body>
    // I am trying to get the value of the name here in this page.
    <%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
    <%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
    </body>
    </html>
    Your help is appreciated.
    Thanks

    Hi,
    Thanks for the reply, it works. I was wondering whether this is an efficient way of doing this. What I want to do further is to setup a connection to a database and use the value I got from my previous page to query the DB and get the results and display.
    I have see some code in the java website and a lot of people do by writting a bean /class(believe bean is just a class) and then importing it and do the things that way. I have good knowledge of OO and Java as a language and would definitely love to do it this way.
    What i think i am missing is the basic idea to doing this way. So if you could let me know how to do this using java classes I would really appreciate it. If its too much to explain can u point to some good source(URL's) that explain's this. I have searched on this and all i find is code with no good explaination.
    Thanks a lot

  • Pass value between JSP pages

    I would like to pass values between pages.
    I don't want showing up on the url. Ex: some.jsp?param=value
    I don't feel it's safe.
    It's not coming from form either....
    How can I hide the value and pass it to next page?
    I want to pass the value when the user click on a hyperlink
    Thanks In Advance.
    Message was edited by:
    Theepan

    Client side information is never safe no matter what you do. If the values don't end up in the url, they are always present SOMEWHERE in the html content.
    If you don't want the values to end up in the url, rework the page so it DOES do a post form submit. You could turn the hyperlink into a javascript call that submits the form for you.

  • Passing value to jsp page by clicking a hyperlink

    I have a hyperlink in a jsp page1. The hyperlink is for another jsp page2. I have a string value in JSP page1, which I want to pass to jsp page2 when user clicks the hyperlink. Can anyone tell me what will be the suitable way to do this? Thanks.

    here's the source to two very simple jsps that do what you want..
    <HTML>
    <HEAD>
    <TITLE>
    ForwardValue
    </TITLE>
    </HEAD>
    <BODY>
    <H1>
    Go To GetValue.jsp
    </H1>
    </BODY>
    </HTML>
    <HTML>
    <HEAD>
    <TITLE>
    GetValue
    </TITLE>
    </HEAD>
    <BODY>
    <H1>
    <%= request.getParameter("value") %>
    </H1>
    </BODY>
    </HTML>

  • Passing values to JSP using HTML

    I have 2 jsp�s (First.jsp, second.jsp).
    I have one a:href on First.jsp where it goes to Second.jsp , and also it needs to take some ID values from First.jsp to Second.jsp.
    Below is my code (First.jsp):
    <h:inputHidden id =�employeeId� value = �#{employee.employeeID}�
    <h:inputHidden id =�applicationId� value = �#{employee.appliationID}�
    Below iy my href:
    <a href = �/jsp/Second.jsp� > Add Application </a>
    How can I send values of employeeId and applicationID to Second.jsp , on clicking Add Application on first.jsp
    Any suggestions

    That's JSF.
    You may find this article useful: http://balusc.xs4all.nl/srv/dev-jep-com.html

Maybe you are looking for

  • Problem with accounting in group currency ( tbb1 )

    Dear all, to use the group currency, we created a new valuation area. In case of a new exchange rate we need to account transactions in the correct way; to do this we applied sap notes: -          1526242 u2013 TBB1: Incorrect amount in valuation -  

  • [svn:fx-trunk] 5115: Adding SpriteVisualElement, a light-weight, Sprited-based implementation of IVisualElement.

    Revision: 5115 Author: [email protected] Date: 2009-02-27 13:27:41 -0800 (Fri, 27 Feb 2009) Log Message: Adding SpriteVisualElement, a light-weight, Sprited-based implementation of IVisualElement. This will be used for some FXG compiler optimizations

  • Calling function defined in one package

    Hi, I have a package ABC. In that I have a function xxx(param1,param2,param3) I have a 2nd package XYZ. I need to use the above functionxxx in package XYZ and assign it to a vriable. How do i do it Please guide me. Thanks

  • Icons disappearing  from my desktop

    Ok so i have some icons on my desktop, one is macintosh HD and a couple of photo icons. they keep disappearing and reappearing every time i turn on my macbook, and i dont know why? help plz.

  • JTree disable turner

    Hello, I'm trying to disable the default turner (the switch that describes wheter the subtree is opened or not). There are functions for disabling nodes (setOpenIcon(null), setClosedIcon(null)) and leafs and changing color but I did'nt find something