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.

Similar Messages

  • Pass data from servlet to jsp using sendRedirect

    Hi,
    I am passing data from servlet to jsp using forward method of request dispatcher but as it doesn't change the url it is creating problems. When ever user refreshes the screen(browser refresh) it's re-loading both servlet and jsp, which i don't want to happen. I want only the jsp to be reloaded.
    Can I pass data from servlet to jsp using sendRedirect in this case. I also want to pass some values from servlet to jsp but without using query string. I want to set some attributes and send to jsp just like we do for forward method of request dispatcher.
    Is there any way i can send data using attributes(without using query string) using sendRedirect? Please let me know

    sendRedirect is meant as a true redirect. meaning
    you can use it to redirect to urls not in your
    context....with forward you couldn't pass information
    to jsps/servlets outside your own context.Actually, you can:
    getServletContext().getContext("/other").getRequestDispatcher("/path/to/servlet").forward(request, response)I think the issue here is that the OP would like to have RequestDispatcher.forward() also update the address in the client's browser. That's not possible, AFAIK. By the time the request is forwarded, the browser has already determined the URL of the servlet, and the only I know of way to have the browser change the URL to the forwarded Servlet/JSP is to send a Location: header (i.e. sendRedirect()). Remember that server-side dispatching is transparent to the client. Maybe there's some tricky stuff you can do with JavaScript to change the address in the address bar without reloading the page?
    Brian

  • Parameter passing from servlet to jsp page

    Hi
    I m facing problem of parameter passing from servlet to jsp ..
    plz help me...
    I m using as ...
    in servlet code I m using ...
    request.setAttribute("string",parameter);
    and in jsp..
    request.getParameter("string");
    regard's
    JAI KUMAR

    Hi Jaykumar
    You should use
    <%= request.getAttribute("sting") %> or
    ${string}
    in your jsp. I think you are trying to retrive the parameter instead of attribute.
    Thanks

  • 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

  • Populating bean attributes from servlet Request

    I know that in a JSP, you can use
    <jsp:setProperty name="p_filters" property="*"/>To populate the properties of a bean from parameters in a request.
    Is there a reliable programmatic way to do this? Since I am using Tomcat, I could use
    JspRuntimeLibrary.introspect(p_filters, request);But that relies on the servlet container's internal classes.
    There really should be a way of doing this easily in a servlet as well as in a JSP! It should be part of the servlet standard, and the JSP standard <setProperty> tag should use that!

    Well, that was buggy. Also, I've added common data types
         private static SimpleDateFormat[] df =
              new SimpleDateFormat("dd-MMM-yy"),
              new SimpleDateFormat("dd-MMM-yyyy"),
              new SimpleDateFormat("yyyyMMdd"),
              new SimpleDateFormat("dd/MM/yy"),
              new SimpleDateFormat("dd/MM/yyyy")
         public static Date parseDate(String d)
              Date result = null;
              for (int i = 0; i < df.length; i++)
                   try
                        result = df.parse(d);
                        if (result != null)
                             return result;
                   catch (Exception e) // Ignore
              return result;
         Sets all attributes of a bean using available parameters from HTTP request
         attributes without a matching parameter in the request are cleared.
         public static void populateBeanFromRequest(Object bean, HttpServletRequest request)
              Object[]     setParam = new Object[1];
              Method[]     methods = bean.getClass().getMethods();
              String          empty = "";
              Boolean          boolZero = new Boolean(false);
              Byte          bZero = new Byte((byte)0);
              Short          sZero = new Short((short)0);
              Integer          iZero = new Integer(0);
              Long          lZero = new Long(0);
              Float          fZero = new Float(0);
              Double          dZero = new Double(0);
              Date          dateZero = new Date(0);
              for (int i = 0; i < methods.length; i++)
                   Class[] paramClass = methods[i].getParameterTypes();
                   if (paramClass.length == 1)
                        String methodName = methods[i].getName();
                        if (methodName.substring(0, 3).equals("set"))
                             String propertyName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4);
                             Logger.debug("Found property " + propertyName);
                             String paramValue = request.getParameter(propertyName);
                             if (paramValue == null)
                                  Logger.debug("No matching parameter found");
                             else
                                  Logger.debug("Found parameter value " + paramValue);
                             try
                                  if (paramClass[0] == String.class)
                                       setParam[0] = (paramValue == null) ? empty : paramValue;
                                  else if (paramClass[0] == Integer.TYPE)
                                       setParam[0] = (paramValue == null) ? iZero : new Integer(paramValue);
                                  else if (paramClass[0] == Date.class)
                                       setParam[0] = (paramValue == null) ? dateZero : parseDate(paramValue);
                                  else if (paramClass[0] == Byte.TYPE)
                                       setParam[0] = (paramValue == null) ? bZero : new Byte(paramValue);
                                  else if (paramClass[0] == Short.TYPE)
                                       setParam[0] = (paramValue == null) ? sZero : new Short(paramValue);
                                  else if (paramClass[0] == Boolean.TYPE)
                                       setParam[0] = (paramValue == null) ? boolZero : new Boolean(paramValue);
                                  else if (paramClass[0] == Long.TYPE)
                                       setParam[0] = (paramValue == null) ? lZero : new Long(paramValue);
                                  else if (paramClass[0] == Float.TYPE)
                                       setParam[0] = (paramValue == null) ? fZero : new Float(paramValue);
                                  else if (paramClass[0] == Double.TYPE)
                                       setParam[0] = (paramValue == null) ? dZero : new Double(paramValue);
                                  else
                                       continue;
                                  Logger.debug(methodName + "(" +
                                       ((paramClass[0] == String.class) ? "\"" : "") +
                                       setParam[0].toString() +
                                       ((paramClass[0] == String.class) ? "\"" : "") + ")");
                                  methods[i].invoke(bean, setParam);
                             catch (Exception e)
                                  Logger.error("Error populating bean", e);
                                  continue;

  • How can i pass a variable's value from PR to PFR

    Dear all,
    hope you are fine.
    i would like to pass a variable's value from PR to PFR.
    how can i do that.
    please suggest.
    in PR:
    String transactionId = (String) vo_trans.first().getAttribute("Getnexttrans");
    i would like to get this value to PFR.

    Mofizur,
    You can achieve the same using Session variable.
    If u are not executing the VO after PR. Then you will be able to get the same value as u are using in PR
    String transactionId = (String) vo_trans.first().getAttribute("Getnexttrans");
    Note - You have a few of the threads left open, mark it as answered if solved.
    Regards,
    Gyan

  • Set request attributes from the request attributes

    Using struts chaining actions.
    When using chaining the requestAttributes are lost.
    Is there a way to get all the request attributes and set them back to the request again?
    if so how to do this?
    Thanks.

    Looks like nobody knows :(
    It seems odd that nobody's tried to get InputSelectLOV or DataHandler working with a Struts app...
    ... anyway, on to finding out why the thing's throwing my releasemode away. This really is very like swimming through treacle :(

  • How can i pass more than 1 param to servlet to show blob image

    Hi
    my servlet expects 2 param to SELECt an image from a blob column
    public class ImageBlobServlet extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    public void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException,
    IOException {
    response.setContentType(CONTENT_TYPE);
    String ImageId = request.getParameter("id");
    String TipImg = request.getParameter("tip");
    OutputStream os = response.getOutputStream();
    Connection conn = null;
    try {
    Context ctx;
    ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/rhDS");
    conn = ds.getConnection();
    PreparedStatement statement = conn.prepareStatement("select FIT from " +
    "RHH_FOTOS IMG " +
    "where IMG.IDASSO = ? and IMG.TIM_COA = ?");
    statement.setInt(1, new Integer(ImageId));
    statement.setString(2, TipImg);
    To display the image i tried to use:
    <af:image id="ot1"
    *source="/imageblobservlet?id=#{bindings.Con.inputValue}?tip=#{"EMP"}"*
    shortDesc="Foto"/>
    but i receive all content in the get of first param.
    String ImageId = request.getParameter("id");
    How can i pass one more then 1 param in EL.
    Thanks in advance

    Hello,
    seems to me you're using wrong separator for the second param into your URL:
    <af:image id="ot1" source="/imageblobservlet?id=#{bindings.Con.inputValue}
    tip=#{"EMP"}" shortDesc="Foto"/>
    I think it should be:
    <af:image id="ot1" source="/imageblobservlet?id=#{bindings.Con.inputValue}
    tip=#{"EMP"}" shortDesc="Foto"/>
    Jack

  • How do I lookup an EJB 3.0 Session bean from servlet or JSP?

    Does anyone knows how can I invoke an EJB from a servlet or JSP ?
    I deployed a simple EJB on a Oracle Application Server 10g release 10.1.3 and I'm working with JDeveloper 10.1.3. I deployed the files via JDeveloper, and I didn´t specify any orion-ejb-jar.xml or ejb-jar.xml file
    After deployment, the orion-ejb-jar.xml look like this in the server:
    <?xml version="1.0" encoding="utf-8"?>
    <orion-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-ejb-jar-10_0.xsd" deployment-version="10.1.3.0.0" deployment-time="10b49516c8f" schema-major-version="10" schema-minor-version="0" >
    <enterprise-beans>
    <session-deployment name="HolaMundoEJB" location="HolaMundoEJB" local-location="HolaMundoEJB_HolaMundoEJBLocal" local-wrapper-name="HolaMundoEJBLocal_StatelessSessionBeanWrapper6" remote-wrapper-name="HolaMundoEJB_StatelessSessionBeanWrapper7" persistence-filename="HolaMundoEJB.home_default_group_1">
    </session-deployment>
    </enterprise-beans>
    <assembly-descriptor>
    <default-method-access>
    <security-role-mapping name="<default-ejb-caller-role>" impliesAll="true" />
    </default-method-access>
    </assembly-descriptor>
    </orion-ejb-jar>
    I'm trying to invoke the ejb in a servlet by doing the following:
    public void doGet(HttpServletRequest request, ....
    Context context = new InitialContext();
    HolaMundoEJB helloWorld =
    (HolaMundoEJB)context.lookup("java:com/env/ejb/HolaMundoEJB");
    String respuesta = helloWorld.sayHello("David");
    When i invoke the servlet I catch a NamingException whose message says something
    like this ....java:com/env/ejb/HolaMundoEJB not found in webLlamaEJB
    I tried different paths for the lookup but nothing....
    Can anyone help me with this topic? Thank you.

    Please try the following code:
    HelloEJBBean.java:
    @Stateless(name="Hello")
    @Remote(value={Hello.class})
    public class HelloEJBBean implements Hello {  ... }
    hello.jsp:
    Context ctx = new InitialContext();
    Hello h = (Hello)ctx.lookup("ejb/Hello");
    web.xml:
    <ejb-ref>
    <ejb-ref-name>ejb/Hello</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <remote>fi.kronodoc.test.model.Hello</remote>
    </ejb-ref>
    i think you should also define jndi mappings for the references in orion-ejb-jar.xml and orion-web.xml but for some reason it seems to be working also without these.

  • Please help how to pass a JavaBean from servlet to jsp?

    Hi there,
    I have got a dispatch servlet and I want the dispatch servlet to get the data and store it in a JavaBean before dispatching to the appropriate JSP page. However, I don't know how to pass the javabean to the JSP when the servlet forward the request to the JSP. Is ServletContext.setAttribute() the only way to pass the javabean to the JSP page?
    Thank you very much!
    Edmund

    You can use HttpServletRequest.setAttribute(String name, Object javabean) to set the javabean into the HTTP request that you are forwarding to the JSP.
    In the JSP, you can access the Javabean using request.getAttribute(String name) and cast it to the right class.

  • Returning ResultSet from servlet to jsp - java.lang.NullPointerException

    Hey all, i've been stuck on this for too long now...just trying to return a ResultSet from a servlet to jsp page.
    Had a bunch of problems earlier...which i think were fixed but...now i get a "java.lang.NullPointerException" in my jsp page when i try to get elements from the ResultSet object.
    Here is the latest version of my code:
    Servlet:
    String QueryStr="select ProdName from products";
    Statement stmt=conn.createStatement();
    rs=stmt.executeQuery(QueryStr); //get resultset
    sbean.setInventory(rs); //set ResultSet in bean
    req.getSession(true).setAttribute("s_resbean",sbean); //create session/request variable, set to bean
    Bean:
    package beans;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.sql.*;
    import javax.sql.*;
    public class SearchBean extends HttpServlet{
         private int searchFlag=0;
         private ResultSet inventory;
         public SearchBean(){
         public int getSearchFlag(){
         return searchFlag;
         public ResultSet getInventory(){
              return inventory;
         public void setInventory(ResultSet rs){
              this.inventory=rs;
         public void setSearchFlag(){
              this.searchFlag=1;
    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 categories=PopInvLists.getCat();
    ResultSet manuf=PopInvLists.getManuf();
    ResultSet supplier=PopInvLists.getSupplier();
    ResultSet cars=PopInvLists.getCars();
    ResultSet search=(ResultSet)request.getAttribute("s_resbean");
    %>
    <%     while(search.next()){
         String pname=search.getString("ProdName");
    %>
    It craps out when i try to loop through the "search" ResultSet.
    I can loop through the rest of the ResultSets no problem....just this one doesn't work because it's set in a servlet, not a simple java class.
    Just to clarify, i am populating some dropdown lists on entry to the screen, which the user will use to perform a search. Once the search btn is clicked, the servlet is called, gets the request info for the search, performs search, and returns the resultset to the original screen. I want to eventually display the result under the search criteria.
    Someone....Please Please please tell me how to get this working...it should be very simple, but i just can't get it to work.
    Thanks in advance,
    Aditya

    req.getSession(true).setAttribute("s_resbean",sbean); //create session/request variable, set to beanHere you add an attribute to the session.
    ResultSet search=(ResultSet)request.getAttribute("s_resbean");Here you try to get the attribute from the request. Naturally it isn't there because you added it to the session, not the request. Despite your comment in the first line of code, a session is not a request. And vice versa.

  • Sending attachment from servlet or jsp

    Dear Friends,
    I downloaded javamail api and I have seen the sendfile.java, which is used to send attachments. it is working fine. I can able to run that program from command prompt like this :=
    c:>java sendfile [email protected] [email protected] mail.smtp.net c:/hello.java true
    It is working fine from console (command prompt)
    How can i execute that file on browser (i have to run as a servlet file or from jsp file).
    please help me how can i pass the emailids, file etc., if i want to use this program as servlet file or as jsp program.
    If anyone having idea, please share ur ideas.
    your kind cooperation would be greatly appreciated.
    Thanks in advance.
    Looking forward to hearing from you.
    Yours
    Rajesh
    ==
    program is like this (which is in javamail home ..demo directory
    ==
    import java.util.*;
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    * sendfile will create a multipart message with the second
    * block of the message being the given file.<p>
    * This demonstrates how to use the FileDataSource to send
    * a file via mail.<p>
    * usage: <code>java sendfile <i>to from smtp file true|false</i></code>
    * where <i>to</i> and <i>from</i> are the destination and
    * origin email addresses, respectively, and <i>smtp</i>
    * is the hostname of the machine that has smtp server
    * running. <i>file</i> is the file to send. The next parameter
    * either turns on or turns off debugging during sending.
    * @author     Christopher Cotton
    public class sendfile {
    public static void main(String[] args) {
         if (args.length != 5) {
         System.out.println("usage: java sendfile <to> <from> <smtp> <file> true|false");
         System.exit(1);
         String to = args[0];
         String from = args[1];
         String host = args[2];
         String filename = args[3];
         boolean debug = Boolean.valueOf(args[4]).booleanValue();
         String msgText1 = "Sending a file.\n";
         String subject = "Sending a file";
         // create some properties and get the default Session
         Properties props = System.getProperties();
         props.put("mail.smtp.host", host);
         Session session = Session.getDefaultInstance(props, null);
         session.setDebug(debug);
         try {
         // create a message
         MimeMessage msg = new MimeMessage(session);
         msg.setFrom(new InternetAddress(from));
         InternetAddress[] address = {new InternetAddress(to)};
         msg.setRecipients(Message.RecipientType.TO, address);
         msg.setSubject(subject);
         // create and fill the first message part
         MimeBodyPart mbp1 = new MimeBodyPart();
         mbp1.setText(msgText1);
         // create the second message part
         MimeBodyPart mbp2 = new MimeBodyPart();
    // attach the file to the message
         FileDataSource fds = new FileDataSource(filename);
         mbp2.setDataHandler(new DataHandler(fds));
         mbp2.setFileName(fds.getName());
         // create the Multipart and its parts to it
         Multipart mp = new MimeMultipart();
         mp.addBodyPart(mbp1);
         mp.addBodyPart(mbp2);
         // add the Multipart to the message
         msg.setContent(mp);
         // set the Date: header
         msg.setSentDate(new Date());
         // send the message
         Transport.send(msg);
         } catch (MessagingException mex) {
         mex.printStackTrace();
         Exception ex = null;
         if ((ex = mex.getNextException()) != null) {
              ex.printStackTrace();

    Hi,
    your sendmail.jsp would look like that:
    <%@ page import="java.util.*,java.io.*,javax.mail.*,javax.mail.internet.*,javax.activation.*" %>
    <%
    String to = request.getParameterValues("to")[0];
    String from = request.getParameterValues("from")[0];
    String host = request.getParameterValues("host")[0];
    String filename = request.getParameterValues("filename")[0];
    String msgText1 = "Sending a file.\n";
    String subject = "Sending a file";
    // create some properties and get the default Session
    Properties props = System.getProperties();
    props.put("mail.smtp.host", host);
    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(debug);
    try {
    // create a message
    MimeMessage msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(from));
    InternetAddress[] address = {new InternetAddress(to)};
    msg.setRecipients(Message.RecipientType.TO, address);
    msg.setSubject(subject);
    // create and fill the first message part
    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setText(msgText1);
    // create the second message part
    MimeBodyPart mbp2 = new MimeBodyPart();
    // attach the file to the message
    FileDataSource fds = new FileDataSource(filename);
    mbp2.setDataHandler(new DataHandler(fds));
    mbp2.setFileName(fds.getName());
    // create the Multipart and its parts to it
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp1);
    mp.addBodyPart(mbp2);
    // add the Multipart to the message
    msg.setContent(mp);
    // set the Date: header
    msg.setSentDate(new Date());
    // send the message
    Transport.send(msg);
    } catch (MessagingException mex) {
    mex.printStackTrace();
    Exception ex = null;
    if ((ex = mex.getNextException()) != null) {
    ex.printStackTrace();
    %>
    which you can call as: sendmail.jsp?to=...&from=...&host=...&filename=...
    so you may need to create a HTML file containing the necessary form.

  • 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

  • Database query ResultSet from servlet to JSP page

              Hi there,
              I have an Access 2000 database. I am running Apache and Tomcat on Windows Me.
              I would like to know if it is possible for me to use a Servlet to search the
              database (I know this bit is possible!), but then I would like the servlet to
              forward to a jsp page which will then display the ResultSet that the servlet has
              retrieved, i.e. when forwarding from a servlet to a jsp, is it possible for the
              jsp page to have access to the servlet's data? I know that it gets access to
              the response and request objects, but what about a ResultSet?
              Sorry it this sounds a little silly - i am a bit of a newbie.
              Thanks in advance for your help,
              SJ
              

    HttpServletRequest.setAttribute let's you share data for a particular
              request. When you call forward you can store the resultset in the request.
              Make sure your JSP does close the result set though, because what you are
              trying to do doesn't sound good :)
              If you want to share data across the session, take a look at the HttpSession
              object.
              read through the servlet specification, it is fairly easy to read and will
              give you all the info you need
              Filip
              ~
              Namaste - I bow to the divine in you
              ~
              Filip Hanik
              Software Architect
              [email protected]
              www.filip.net
              "SJ" <[email protected]> wrote in message
              news:[email protected]...
              >
              > Hi there,
              >
              > I have an Access 2000 database. I am running Apache and Tomcat on Windows
              Me.
              > I would like to know if it is possible for me to use a Servlet to search
              the
              > database (I know this bit is possible!), but then I would like the servlet
              to
              > forward to a jsp page which will then display the ResultSet that the
              servlet has
              > retrieved, i.e. when forwarding from a servlet to a jsp, is it possible
              for the
              > jsp page to have access to the servlet's data? I know that it gets access
              to
              > the response and request objects, but what about a ResultSet?
              >
              > Sorry it this sounds a little silly - i am a bit of a newbie.
              >
              > Thanks in advance for your help,
              >
              > SJ
              

  • Creating files from servlets or jsp

    The issue that I have is this
    I've been working with eclipse, netbeans, tomcat, glassfish, servlets and jsps.
    I have a little servlet/jsp web application that create few files from the servlet. Those files I need to make them visible to the browser because they are the end result of the servlets/jsp work.
    When I run the server from netbeans/eclipse they deploy the war file into tomcat/glassfish server and run the app.
    So far there is no problem here, just that.. the files created with the app are created into the project folder.
    If I manually run the server, those files are created in the folder from I started the server, so what I did is get into the deployed/unpacked war and from there start the server.
    Only that way I could make those files visibles to download.
    Is there a better way to do this? (of course, it must be, but I don't know how).
    What I want is, deploy the web-app and make the app create those files at the same folder of the web-app to allow those file could be downloaded, no matter from where or how the server is started.
    In the near future I need to install few web-apps like this at the same server, so I can't still starting the server from the web-app folder (as I did it until now).
    I read about the request.getContextPath(); but it return no the real address just the context address (something like "/my_app"), so when I use that address to create a file, what I get is something lik "/my_app/myFile.txt".
    I hope you can give some advices of how to solve my issue.
    Thanks in advance

    830896 wrote:
    Right now I know the absolute path to the tomcat/glassfish where the web-app is deployed, so I can use that address, but in the future that web-app could be deployed in another server and I can't know what address does it have.
    I wonder if there exists a way to know the current absolute address of the web-app, or a way to create, "%this-web-app-absolute-addres%/someDir/myNewFile.txt"No, you're solving the wrong problem. Don't store files you create in the context of the web application, or even in the context of the application server. Store them somewhere else entirely. Then the person who configures the web application just has to set up the name of the directory where they are stored as a variable for your application.

Maybe you are looking for

  • SAP GRC 5.3 CUP: Initial Password not displayed

    Hi, when a user account is created in the backend system CUP sents automatically the user ID and a link such as http://<Server>:50100/AE/showPassword.do?userId=NEWUSER30&ReqNo=1061&System=ERD to the user's email adresse. When opening the link no pass

  • How do I import bookmarks from a json file?

    I have Firefox 23.0.1. I am trying to import Firefox bookmarks from a json file on another disc, and merge these with my existing bookmarks. I only have options to import an html file. I can also use restore to bring in the file, but this will overwr

  • Updating with pacman fails

    I am trying to run a pacman -Syu and get the following error. error: failed to prepare transaction (could not satisfy dependencies) :: virtualbox-guest-utils: requires X-ABI-VIDEODRV_VERSION<15 Is there a way around this?

  • Yahoo messenger upgrade doesn't display in landscape

    Yahoo Messenger for the iPad recently had an update to 2.2.9.  Since I installed that update, Yahoo Messenger! misbehaves when I rotate the iPad to show landscape display.  The Messenger! app won't rotate.  I've done nothing to change the iPad's Sett

  • When I open to preview it'll open all picture how do  I fix ?

    when I open to preview it'll open all picture how do  I fix ?