Returning ResultSet to jsp from servlet

Hi,
I am trying to return a ResultSet (generated in servlet) to a jsp page, but get a "java.lang.ClassCastException" error. Here is my description of what i'm doing....
I have a search screen (SearchInventory.jsp) that the user goes to to perform the search based on a few variables. When the search button is clicked, i go to a servlet (SearchInventory.java) which gets a ResultSet. In the servlet, i am storing the ResultSet into a bean object, and finally use the RequestDispatcher to redirect to the .jsp page. (and get the "java.lang.ClassCastException" error).
Here is the relevant code from all parts of the app:
SearchInventory.java:---------------------------------------------------------------------
SearchBean sbean=new SearchBean();
String QueryStr="select ProdName from products";
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(QueryStr);
sbean.setSearchRS(rs);
req.getSession(true).setAttribute("s_resbean",sbean);
HttpSession session=req.getSession(true);
session.setAttribute("s_resbean",rs);
req.setAttribute("sbean",rs);
String url="/SearchInventory.jsp";
RequestDispatcher dispatcher=getServletContext().getRequestDispatcher(url);
dispatcher.forward(req,res);
SearchBean.java:
public class SearchBean extends HttpServlet{
private int searchFlag=0;
private static ResultSet searchRS;
     public void setSearchRS(ResultSet rs){
          this.searchRS=rs;
And finally, the .jsp page..SearchInventory.jsp:
<%@ page language="java" import="java.lang.*,java.sql.*,javax.sql.*,PopLists.PopInvLists,beans.SearchBean"%>
<jsp:useBean scope="session" id="s_resbean" class="beans.SearchBean" />
ResultSet search=(ResultSet)request.getAttribute("s_resbean");
If i don't cast it to type ResultSet, i get the following error, which leads me to believe that i should be casting it to a Result Set.
C:\Apache\tomcat_4.1.29\work\Standalone\localhost\DBTest\SearchInventory_jsp.java:75: incompatible types
found : java.lang.Object
required: java.sql.ResultSet
ResultSet search=request.getAttribute("s_resbean");
Please help...
Thanks in advance,
Aditya.

Yikes...i realized some of my many problems...i'm using setAttribute multiple times here...(shown by arrows at the end)
sbean.setSearchRS(rs);
req.getSession(true).setAttribute("s_resbean",sbean);//<--
HttpSession session=req.getSession(true);
session.setAttribute("s_resbean",rs);//<--
req.setAttribute("sbean",rs);//<--
I've tried using one at a time since, and it still doesn't work. How exactly should i be setting the attribute. I don't think any of the methods listed above are completely correct...cause it's never worked!:(
Is anything that i've done correct? (ie. bean/jsp). I'm really starting to doubt myself now. I've been reading up on this, and some people say that one shouldn't return a ResultSet to the jsp, but instead return an ArrayList. Is this correct? If so, how do i convert an ResultSet to an ArrayList?
-Aditya.

Similar Messages

  • Applet in jsp from servlet, but error: ClassNotFoundExcep

    The problem that I'm having is already mentioned a couple of times in this forum, but unfortunately I haven't found a solution, in thread http://forum.java.sun.com/thread.jspa?forumID=33&threadID=239405 is proposed solution but it's not working for me.
    I'm developing a project in IBM's Websphere Developer Studio 5.1.1. and JRE that I'm using for this project is 1.4.2. I have created servlet "CompanyDocument.java" and applet "SimpleApplet.java". Applet was created as single project and then imported into this one, that means that it's contained in current project as "SimpleAppletPackage.jar". I have placed jar in folder "Applets", Websphere automatically creates folder "simpleAppletPackage" and in it's root complied "SimpleApplet.class".
    When I put following code in the jsp page applet works correctly when application is runed.
    <APPLET code="simpleAppletPackage/SimpleApplet.class" codebase="Applets" archive="SimpleAppletPackage.jar" width="250" height="250"></APPLET>
    But I wanted to create jsp from servlet. So I used this code within servlet:
    out.print("<APPLET code=\"simpleAppletPackage/SimpleApplet.class\" codebase=\"Applets\"");
    out.print("archive=\"SimpleAppletPackage.jar\" width=\"250\" height=\"250\"></APPLET>");
    But I get an error (when running, no error when compiling). The error is copied from Java console:
    load: class simpleAppletPackage/SimpleApplet.class not found.
    java.lang.ClassNotFoundException: simpleAppletPackage.SimpleApplet.class
    at sun.applet.AppletClassLoader.findClass AppletClassLoader.java:162)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:123)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:566)
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:619)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:548)
    at sun.applet.AppletPanel.run(AppletPanel.java:299)
    at java.lang.Thread.run(Thread.java:534)
    Caused by: java.io.IOException: open HTTP connection failed.
    at sun.applet.AppletClassLoader.getBytes(AppletClassLoader.java:265)
    at sun.applet.AppletClassLoader.access$100(AppletClassLoader.java:43)
    at sun.applet.AppletClassLoader$1.run(AppletClassLoader.java:152)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:149)
    ... 9 more
    In the same time I'm creating some more code from servlet and it works with no errors and is shown in browser properly (it consists of connection to Oracle, formatting table, and presenting data within that table).
    Any idea? I'm totally stuck.

    In your browser, look at the HTML code that gets sent to the browser and see if there is something wrong with it.
    Specifically, I would look at the code near the <APPLET ..></APPLET> tags, both before and after and look for stray quotes, brackets, or what not.
    Finally, I would look inside the <APPLET ...> tag. It appears to me that the output will probably be:
    <APPLET code="simpleAppletPackage/SimpleApplet.class" codebase="Applets"archive="SimpleAppletPackage.jar" width="250" height="250"></APPLET>See, you may be missing a space between the "Applets" and the archive=. Try making the second out.print look like this:
    out.print(" archive=\"SimpleAppletPackage.jar\" width=\"250\" height=\"250\"></APPLET>"); See the extra space at the start of the output?

  • Getting to next JSP from Servlet

    I am getting a 404 when I try to redirect from my servlet to an error page. The code that I am testing is....
    catch (SQLException es)
    LOG.error("Unexpected error in Login.createUser.Error
    message = " + es);
    session.setAttribute(Constants.MESSAGE, es.getMessage());
    session.setAttribute(Constants.ERROR_TITLE, "Login error: " + Constants.SQL_ERROR);
    resp.sendRedirect(Constants.ERROR_PATH);
    I have a compiled java class called Constants where the ERROR_PATH is defined as
    /** Constant name used in obtaining the path to the error page. */
    public static final String ERROR_PATH = "/Jsp/error.jsp";
    My JSP pages are located at the root...
    myapp
    ....Jsp
    ....WEB-INF
    ........classes
    My web.xml looks like this
    <servlet>
    <servlet-name>errorPage</servlet-name>
    <jsp-file>/Jsp/errorPage.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
    <servlet-name>error</servlet-name>
    <url-pattern>/Jsp/error.jsp</url-pattern>
    </servlet-mapping>
    Can anyone point me in the right direction....Thanks

    I tend to use a utility method called redirectToResource in particular to redirect from any servlet to any JSP :
    /** This method will still work when the server is configured to
    *   listen to  port 80 rather than port 8080 (default in Tomcat)
    public void redirectToResource (HttpServletRequest req,
                                     HttpServletResponse resp,
                                  String resourceName)
                         throws ServletException, IOException
       int serverPort    = req.getServerPort();
       String scheme     = req.getScheme();
       String serverName = req.getServerName();
       StringBuffer urlBuffer = new StringBuffer(40);
       urlBuffer.append(scheme + "://" + serverName);
       urlBuffer.append(":" + serverPort);
       urlBuffer.append(resourceName);
        String location = resp.encodeRedirectURL(urlBuffer.toString());
        resp.sendRedirect(location);
    }

  • How to call JSp from Servlet??

    Hello,
    I want to call JSP page from servlet.I am using Visual Age For java 3.4. What is wrong in my code??
    if (userExists) {
    f.setErrors("userName","Duplicate User: Try a different username");
    getServletConfig().getServletContext().
    getRequestDispatcher("/jsp/forms/retry.jsp").
    forward(request, response);
    I am not able to get the o/p. Pls help.

    I can't see anything obvious, but did you take any steps towards doing output before this code (like openning an output stream)?
    Not clear what f.setErrors does - presumably stuffs the error message in an attribute of the request.

  • Returning ResultSets to jsp

    Hi,
    I'm using a javabean that returns a resultset from oracle and i need that resultset to execute another query so i can return the data to a jsp. My problem is it will only execute through a while loop once as i have passed it to a String. Does anyone have any idea how i could go about this? So far I've been using while loops eg.
         result = select.executeQuery("select * from score where stu_score = 10 and level_id = 1");
              while(result.next())      
    String s = result.getString("stu_id");
    System.out.println(s);
    result = select.executeQuery("Select stu_name from Student where stu_id = '"+s+"'");
    while(result.next())
         String r = result.getString("stu_name");
         System.out.println(r);
    This will return one stu_id and one stu_name. Any ideas?

    Hi,
    You are getting results from the database and storing them in result. Inside your outermost while loop you are overwriting the same object i.e. result, by saying
    result = select.executeQuery("Select stu_name from Student where stu_id = '"+s+"'");
    That is why you only get one stu_id and one stu_name. Outside the first while loop, declare another ResultSet object, call it result2, and use that one inside.
    However, I strongly recommend not to run such code in a jsp. Do this in a servlet, and set your results that you get through the resultsets in a data transfer object, store it in the request or session, and then get it in the jsp. Also, remeber to close your resultset, statment, and connection objects, otherwise you will suffer from the open cursors problem - eventually! And above all, that is the right way of doing stuff.
    Hope this helps.

  • How to go to new jsp from servlet.

    In the results page, if a button is clicked, i go to servlet, then come back to display data from database in another page. It works fine but the problem is that I wnat to open up a new browser and display the target page there and not the results page.
    results.jsp --> click button --> go to servlet --> display data on resultDetails.jsp (same browser window).
    I want resultDetails.jsp in a new browser window.
    my code in results.jsp is:
    <input type = \"button\" onclick = \"location.href = 'Controller.wss?page=RESULT_DETAILS_PAGE&cmd_id="+cmdId+"'\" value = \"see details..\">
    how can i change this. I am using java in jsp and out.println for any html content.
    Thank you in advance. Any help (with/without) examples would be appreciated.
    Bhavna.

    1. Create a jsp (popup.jsp) file with the content you want for the pop up window (eventually read some parameters from the request, if you need)
    2. when creating the resultDetails.jsp generate a JavaScript that opens the pop-up jsp file using someting like:
    <script>
    window.open("popup.jsp?param1=<%=param1%>&param2=<%=param1%>");
    </script>

  • Passing vectors into JSP from Servlet and passing data back to Servlet

    I have been building an MVC application.
    It has a controller which instantiates classes and evokes methods to
    populate vectors. These vectors are then passed into a JSP. This part of the application works fine.
    What I am having trouble with is a new JSP I have designed; this will
    display the data that is actioned by the FORM action. This is actioned
    based on the Search criteria entered by the user. Based on this a further vector is populated and brought back to the JSP as a vector
    and this is rendered via the TABLE tag. Again this works fine.
    Against each of the rows displayed, I have a print checkbox which can be checked by the user. On checking the records they want to print, they should then hint a Print button which should go back to the Servlet and print the data. THIS IS WHERE I HAVE THE PROBLEM. On going
    back to the servlet the checkbox values are not displayed, rather
    the values that initially populate the JSP. How do I get these new values back into the vector and hence accessible from the Servlet.
    Any help with be very much appreciated.
    Chris

    Thanks for this.
    Just to clarify I am not using Struts.
    What I am having difficulties with is the fact that:
    I can't get the checked values back to the Servlet - they keep the values they have in the bean - so as part of instantiating the bean class I set the value of the item to 'off'. The user will then check
    the checkbox which should presumbably set the value to 'on'. This isn't happening because the setter method of the bean is not evoked again
    because I don't come into this JSP again - the Servlet has finished here
    and now needs to print the records. It can't do this because as
    far as it is concerned nothing has changed since it last passed through
    the vector to the JSP.
    Even when I do the following:
    Enumeration paramNames = request.getParameterNames();
    String param = null;
    while (paramNames.hasMoreElements())
    param=(String)paramNames.nextElement();
    System.out.println("parameter " + param + " is " +
    request.getParameter(param));
    what comes back is the valus of 'off' as opposed to 'on'.
    The other thing is that 'request.getParameterNames()' only works
    with the first record in the vector, i.e. it doesn't fetch any other
    records that are rendered in the <TABLE> tag.
    In desperation is there anybody out there who can help me.
    Thanks
    Chris
    I am going to assume you are using a MVC framework
    like Struts or very similar (I am assuming that from
    the language you are using).
    When the servlet passes the vector back to the JSP
    page and you render the HTML that is passed back the
    client your Vector is gone. The Vector is not
    available at the HTML level that is being viewed at
    the browser.
    When the user selects the checkboxes and submits the
    page (by clicking the print button) the controller
    servlet (called ActionServlet in Struts, yours maybe
    called something else) forwards the request to the
    appropriate JavaBean and Servlet to process the
    request. Either the JavaBean has to recreate the
    Vector (not recommended) or the processing Servlet can
    (better). You can do this by recreating the Vector
    from scratch for the HttpRequest parameters or, at the
    time of the initial request, saving Vector to a
    session and then updating with the data you get back
    from the client (again from the HttpRequest
    parameters).
    Either way you have to work with
    HttpRequest.getParameter().

  • How to send a message from Servlet to JSP

    Dear all,
    I have JSP, with JavaScript (AJAX). If the user click on the button, the text will be sent to a Servlet parsed by doGet() and the user get a response to his input, without reloading a page.
    How can I send a message to the users (JSP) from Servlet, if he didn't clicked any button and to other visitor of the page also? Is it possible? I think like a chat, the server sends a message to all users who are subscribed.
    I don't know, what should I get from user, maybe session, that I could send him personal or common messages in his textarea. I should also invoke some JavaScript function to update his page. I have met some chats, you don't do nothing and get messages. It is also without a JavaScript timer, which invokes doGet() method. Asynchronous, only when there is a message.
    Please help me with a problem.
    Thanks in advance.

    Hai ,
    You can send any message through response.sendRedirect();
    here is the coding try it
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class SimpleCounter extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();
    String username="java";
    res.sendRedirect("http://localhost:8080/yourprojectname/jspfile.jsp?username="+username);
    }

  • Can't pass bean or request attribute from servlet to JSP

    Hi,
    I have a web app that starts with a file upload page that uses commons io fileUpload, passes the info on to a servlet. Then the servlet passes its info on to a JSP.
    I can upload the file onto the web app successfully. I also can call that uploaded file directly from the JSP (i.e. bypassing the servlet) without problem. But if I try to chain all 3 together while passing the url for the file directly as an attribute or as a bean containing file's url, I get premature end of file or can't find the property in the bean. I'm not sure what I'm doing wrong.
    the error message:
    org.apache.jasper.JasperException: javax.servlet.jsp.JspException: Premature end of file.
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
         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)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
         servlet.UploadServlet.processRequest(UploadServlet.java:329)
         servlet.UploadServlet.doPost(UploadServlet.java:363)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
         com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
         com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
         com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
         com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    root cause
    javax.servlet.ServletException: javax.servlet.jsp.JspException: Premature end of file.
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:854)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
         org.apache.jsp.clinTrialsEditor_jsp._jspService(clinTrialsEditor_jsp.java:144)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
         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)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
         servlet.UploadServlet.processRequest(UploadServlet.java:329)
         servlet.UploadServlet.doPost(UploadServlet.java:363)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
         com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
         com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
         com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
         com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    root cause
    org.xml.sax.SAXParseException: Premature end of file.
         org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
         org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
         org.apache.taglibs.standard.tag.common.xml.ParseSupport.parseInputSource(ParseSupport.java:227)
         org.apache.taglibs.standard.tag.common.xml.ParseSupport.parseInputSourceWithFilter(ParseSupport.java:193)
         org.apache.taglibs.standard.tag.common.xml.ParseSupport.parseReaderWithFilter(ParseSupport.java:199)
         org.apache.taglibs.standard.tag.common.xml.ParseSupport.parseStringWithFilter(ParseSupport.java:206)
         org.apache.taglibs.standard.tag.common.xml.ParseSupport.doEndTag(ParseSupport.java:138)
         org.apache.jsp.clinTrialsEditor_jsp._jspx_meth_x_parse_0(clinTrialsEditor_jsp.java:189)
         org.apache.jsp.clinTrialsEditor_jsp._jspService(clinTrialsEditor_jsp.java:88)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
         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)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
         servlet.UploadServlet.processRequest(UploadServlet.java:329)
         servlet.UploadServlet.doPost(UploadServlet.java:363)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
         com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
         com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
         com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
         com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    Code from the servlet:
    String dName = "http://localhost:8084/fileUploadApp/faces/";
    url = dName + fileName;
    beans.FileInfo.setFileName(fileName);
    request.setAttribute("fileInfo", new FileInfo());
    beans.FileInfo.setDName(dName);
    beans.FileInfo.setDirName(dirName);
    beans.FileInfo.setUrl(url);
    File saveTo = new File(dirName + fileName);
    //if I use the next 2 lines I get "can't resolve symbol - create field, local var or parameter FileInfo"
    FileInfo fileInfo = new beans.FileInfo();
    request.setAttribute("fileInfo", FileInfo); //error here
    request.setAttribute("myUrl", url);
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/clinTrialsEditor.jsp");
    dispatcher.forward(request, response);
    on JSP
    <jsp:useBean id="fileInfo" class="beans.FileInfo" scope="request"/>
    <jsp:setProperty name="fileInfo" property="*"/>
    <%--<c:import url="http://localhost:8084/fileUploadApp/faces/lowVision.xml" var="url" /> --%> <c:import url="${myUrl}" var="url" />
    <x:parse xml="${url}" var="clin" />
    etc...x:set with xpath expressions
    Can anyone spot my error(s)?
    Thanks for the help!

    Thanks for your reply, Ram.
    I made the change but I get an error "Unable to find a value for "fileName" in bean of type beans.FileInfo"
    Here's the bean:
    package beans;
    public class FileInfo {
    private static String fileName;
    private static String dirName;
    private static String dName;
    private static String url;
    /** Creates a new instance of FileInfo */
    public FileInfo() {
    public static void setFileName(String fn){
    fileName = fn;
    public static String getFileName(){
    return fileName;
    public static void setDirName(String dn){
    dirName = dn;
    public static String getDirName(){
    return dirName;
    public static void setDName(String d){
    dName = d;
    public static String getDName(){
    return dName;
    public static void setUrl(String u){
    url = u;
    public static String getUrl(){
    return url;
    Pertinent parts of servlet:
    String dirName = "C:/MyNBProjects/fileUploadApp/web/"; //save file to web app then convert to url so it can be called to show it on next page
    String dName = "http://localhost:8084/fileUploadApp/faces/";
    url = dName + fileName;
    FileInfo fileInfo = new FileInfo();
    fileInfo.setFileName("fileName");
    fileInfo.setDName("dName");
    fileInfo.setDirName("dirName");
    fileInfo.setUrl("url");
    request.setAttribute("fileName", fileName);
    request.setAttribute("url", url);
    request.setAttribute("fileInfo", fileInfo);
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/clinTrialsEditor.jsp");
    dispatcher.forward(request, response);
    jsp:
    <jsp:useBean id="fileInfo" class="beans.FileInfo" scope="request"/>
    <jsp:setProperty name="fileInfo" property="*"/>
    url = <c:out value="${url}" />
    //works; not part of bean
    fileName = <c:out value="${fileName}" />
    //works; not part from the bean
    fileInfo.fileName = <jsp:getProperty name="fileInfo" property="fileName" />
    //doesn't work
    <%--fileName = <c:out value="${fileInfo.fileName}" /> //doesn't work
    Can you spot the error(s)?
    Thanks for your help.

  • Urgent....How can i redirect to my jsp page from servlet in init() method..

    How can i redirect to my jsp page from servlet in init() method..Becoz that servlet is calling while server startsup..so im writing some piece of code in init() method..after that i want to redirect to some jsp page ...is it possible?
    using RequestDispatcher..its not possible..becoz
    RequestDispatcher rd = sc.getRequestDispatcher("goto.jsp");
    rd.foward(req,res);
    Here the request and response are null objects..
    So mi question can frame as how can i get request/response in servlet's init method()..

    Hi guys
    did any one get a solution for this issue. calling a jsp in the startup of the servlet, i mean in the startup servlet. I do have a same req like i need to call a JSP which does some data reterival and calculations and i am putting the results in the cache. so in the jsp there in no output of HTML. when i use the URLConnection i am getting a error as below.
    java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:707)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:705)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
    nection.java:519)
    at com.toysrus.fns.alphablox.Startup.callJSP(Unknown Source)
    at com.toysrus.fns.alphablox.Startup.init(Unknown Source)
    at org.apache.tomcat.core.ServletWrapper.doInit(ServletWrapper.java:317)
    so plz do let me know how to call a jsp in the start up of a servlet.
    Thanks
    Vidya

  • Error message from servlet to jsp

    Hi again,
    I have servlet and check error on this servlet then i would like
    to send error message to jsp page.Every error message will send to
    same JSP page.So JSP must receive message from Servlet.Can i do this?
    Please give me details and some sourcecode.I will appreciate for your helps.

    you could do something like this..
    request.setAttribute("error", stringErrormessage);
    Then in the jsp just do
    <%= request.getAttribute("error") %>
    That will print an errormessage.
    Basically, by setting anything on the request and then redirecting to that page you cn display it...
    //Johan

  • Accessing String assigned in a JSP from a Servlet?

    Hello all, I was wondering if there is a way to access a String object that was assigned by an HttpSession object in a JSP from a Servlet. What happens is, in my application a user logs in, an HttpSession object is instantiated and all of the user credentials are assigned within a JSP like:
    HttpSession httpSession = request.getSession( false );
    String userName = httpSession.getAttribute("userName);
    ...{code}
    Next, I have a Servlet (which is really just a Proxy to a different server), that I need to log some information with, namely the userName String. Is there a way I can access that String without instantiating another HttpSession object? Because when the timeout occurs (or when the user clears his cache I have found), the HttpSession becomes invalidated (even if I use  +HttpSession#getSession( true )+) and the +HttpSession#getAttribute+ call fails (userName is just null). So is this possible to do?
    Thanks in advance!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    dnbphysicist wrote:
    I understand you cannot recover attributes from a dead session, this is why I wanted to be able to access a variable that is pulled from the Session immediately after login so I can still get to it even once the session is dead.
    Normally a session doesn't go dead after login.
    I imagine that by using application scope the app would confuse the userName with other users that are logged in?Certainly. It was just an example. But your data clearly belongs in the session, so just keep it in the session. If the session get invalidated while it should not get invalidated, then your problem truly lies somewhere else.
    I am definitely not arguing you latter point either :) A lot of this code I inherited unfortunately from previous developers and we are in desperate need of a redesign.I wish you much luck with that.

  • How to create thumbnail images on the fly from JSP or servlet?

    Hi all,
    Iam new to this forum. I need a solution for the problem iam facing in building my site. Ihave groups and briefcase section in my site. I allow users to upload files and pictures.
    When they upload pictures i need to create thumbnail for them on the fly.
    Is there any taglibs or java source to do this from JSP or servlets.
    It would be very greatful if i can get an early answer.
    Please let me know if there is any other forum where i can get better answer, if not here?
    thnx.

    Here is how you can create dynamic images:
    http://developer.java.sun.com/developer/JDCTechTips/2001/tt0821.html#tip2
    However, if you want to create gifs/jpegs and save them to the disk it depends from where you want to create the images. It is different if you are creating from another image or just drawing one from scratch etc.. But in the end you will probably need to use one of the imageencoder classes and write the result to the disk with the file io classes.

  • How to send the values from servlet to jsp

    hi folks,
    I need to send a lot of values from servlet to jsp so that i can display the values in jsp. Any sollution for this. Its very urgent.
    Thanks in advance

    Hi lieo,
    Can u send me the sample code for that.
    Thank q

  • Generating the JSP from the Servlet source file

    Hi,
    Does anyone out there know if there is any utility/class/program which will generate a JSP from the Servlet Source file (.java file) or indeed from the compiled Servlet file (.class file)
    If its possible to decompile a .class file into a .java file, surely it must be possible to convert the .java souce file into the .jsp file that created it.
    any comments would be appreciated
    Richard

    I am the author of the original JSP!
    But I want to run a script on the generated Servlet source file,
    changing its contents, and then generate the JSP that would have created the new Servlet source file.
    but I need to know if theres anything that will reverse engineer a Servlet source into the generating JSP.
    its a kind of of Jeopardy type thing!

Maybe you are looking for

  • How to fund an itunes account for a child

    I've setup an unfunded itunes account for my 10 year old son. I'd like to fund it with $5 per month. seems there's no way to do that - the allowance is limited to a minimum of $10 per month and buying a gift card - even a "digital / e-mailed" one, th

  • Crossfade no longer works in iTunes version 11.0.1.12

    Anyone else experiencing issues with iTunes 11.0.1.12 Crossfade working ?      Seems this newest version has brought back a very old problem.   Sorry Apple, need to check your regression tessting processes that old problems are not reintroduced on ne

  • How to Re-install Photoshop CC

    My CC app says it is installed but I get the following message when I open it: You can't open the application "Adobe Photoshop CC" because it may be damaged or incomplete. I've tried deleting it, but it does nothing while CC say it is still installed

  • Problems with my VGA

     I have taken the MX440 AGP out and replaced it with an ATI radeon7000 PCI.I have enabled the VGA adapter in the start up menu and installed it with little difficulty. however, when I go to use the television feature the monitor goes blank and the co

  • Alert log.xml or alert.log errors do not appear in EM

    Little puzzled here. Using 11.1.0.6 to test if alert errors will appear on 11.1.0.1 EM Grid pages. Simple ORA-1653 triggered via sql insert and then waited and waited. Nothing. I can use EM to open log file and to display the errors but no alerts are