Ok, Simple problem:  Loss of session if cookies are not on doing a
POST FORM.
(BTW, I am using JRUN w/Linux IBM JDK 118)




I am sending a POST w/file to a servlet from JSP.

Here is my simple code to do so:

... JSP....
<H1>Sample upload form</H1>
<FORM ACTION="/servlet/SessionServlet" ENCTYPE="multipart/form-data"
method=post >
<INPUT TYPE="file" NAME="fileUp">
<INPUT TYPE="submit" VALUE="upload">
</FORM>
... JSP ...



This posts to a Servlet

--- BEGIN SERVLET ---

public class SessionServlet extends HttpServlet {

    public void doPost (HttpServletRequest req, HttpServletResponse res)

      throws ServletException, IOException
      {

   //Get the session object
   HttpSession session = req.getSession(true);

   //Get the output stream
   ServletOutputStream out = res.getOutputStream();
   try {
     MultipartRequest multi =
    // Imposes a 5 meg limit on upload and puts them into the tmp dir
off
    // of the root file system.
    new MultipartRequest(req, "/tmp", 5 * 1024 * 1024);

     // Show which files we received
     Enumeration files = multi.getFileNames();
     while (files.hasMoreElements()) {
        String name = (String)files.nextElement();
        String filename = multi.getFilesystemName(name);
        String type = multi.getContentType(name);
        session.putValue("fileName",filename);
        session.putValue("fileType", type);
        // File f = multi.getFile(name);
        res.sendRedirect(res.encodeURL("/upload.jsp"));
     }
   } catch (Exception e) {
    e.printStackTrace();
    res.sendRedirect(res.encodeURL("http://192.168.1.3/upload.jsp"));
  }

 }

---- END SLOP ----



I can send pages w/ GET and session is fine.

If I have cookies on, it works fine.


BUT, if I don't have cookies on...  no go.

I assume that I have to somehow get the session ID into the form.

I have tried putting a parameter jrunsessionid="325322523452345" as a
hidden field, didn't work.



*sigh*



If ANYONE has had any luck with this, please let me know.

BTW, if you don't recognize the code above, it is lots of cuts and snips
from Jason Hunters MultiRequest class example.



Thanks in advance folks..  enjoy your holidays.

and Cheers from Switzerland! :)

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to