OK I am writing a custom application which needs to do a limited amount of web browsing...
i.e. browsing is not its main intention but yes it is ABSOLUTELY necessary for
it to be able to browse the web.... I am using a JEditorPane with the HTMLEditorKit
for the display of web pages... I am ok with small things not working, for instance
the wrap attr in <textarea> doesn't work...

however I am having trouble accessing a session scoped attribute...

Back up, I suppose further clarification is in order, I am also writing the web application which will be viewed through the JEditorPane....

so it has to do with user validation and logging in...
Below is the code... the bean is created in the LoginServlet.java
I initially had it as a session scoped attribute...
then i forward the bean to the add content page... which then forwards
the bean to the uploadcontent servlet

i posted the version of the code that works....
when I browse the pages through my app, the bean is persisted as an application scoped
bean...
however when I have the bean session scoped, which I what I would prefer... when I try to access it as a session attribute in the uploadContentServlet... it is null...
thing is the same web application code shown below works in firefox, no matter whether the bean is session scoped or application scoped....

So the problem I imagine lies in the JEditorPane rudimentary handling of things..
and this is where my knowledge lacks.... I know it is possible to edit the HTMLEditorKit which displays the pages.... but is this the problem... I am not even sure whre to look next...

Thanks in advance
here is the code
LoginServlet.java

String userName = req.getParameter("username");
		String password = req.getParameter("password");
		User loginUser = new User();
		loginUser.setUserName(userName);
		loginUser.setPassword(password);
		ContentManagerDBMain.getInstance();
		boolean success = ContentManagerDBMain.checkUserCredentials(loginUser);
		if (success) {
			User validatedUser = ContentManagerDBMain.loadUser(userName);
			req.getSession().setAttribute("validUser", validatedUser);
			getServletContext().setAttribute("validUser", validatedUser);
			req.getRequestDispatcher("addContent.jsp").forward(req, res);
			
		} else {
			out.println("<h1>Login Failed!</h1>");
			out.println("<form action=\"login.jsp\" method=\"get\">"
			+ "<input type=\"submit\" name=\"login\"  value=\"Login\"/>"
			+ "</form>");
		}

addContent.jsp

<jsp:useBean id="validUser" class="com.addingdimensions.DAO.User" scope="application"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1> Welcome <%= validUser.getFirstName() %></h1>
<h2> To add content, you must first use your client to create a .torrent file</h2>
<h3> Then use this page to add a description of what the torrent contains and upload the .torrent file</h3>

<br/>
	<form action="/HFTPContentManagerClient/uploadContent" method="post" enctype ="multipart/form-date">
		<p>
		 <textarea name="contentDescription" cols=60 rows=5 wrap=HARD >Please provide short descritpion of what content contains which will be displayed when others are browsing content.</textarea><br/>
		Torrent metafile: <input type="file" name="metainfoFile"/><br/>
		<input type="submit" name="addContentButton" value="Upload"/>
		</p>
	</form>
</body>

UploadContentServlet.java

public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		PrintWriter out = res.getWriter();
		String contentDescription = req.getParameter("contentDescription");
		out.println("Your description<BR>");
		contentDescription.replace("\n", "<BR>");
		out.println(contentDescription);

		Object test = getServletContext().getAttribute("validUser");
		User uploadingUser = null;
		if (test instanceof User) {
			uploadingUser = (User) test;

		}

OK in the same vein the problem continues... this time I am not even sure of a workaraound as I did above...

once the user has logged in.. I want them to be able to upload a file...

I use the following jsp to accomplish this

<br/>
    <form action="/HFTPContentManagerClient/uploadTorrent" method="post" enctype="multipart/form-data">
        <p>
        Torrent metafile: <input type="file" name="metainfoFile"/><br/>
        <input type="submit" name="addContentButton" value="Upload"/>
        </p>
    </form>

that is all that is on the jsp page....

then the following servlet code...

    String contentType = req.getHeader("Content-type");
    String contentType2 = req.getContentType();

    System.out.println("Content type: " + contentType);
    System.out.println("Content type: " + contentType2);

    int length = req.getContentLength();
    if (length > _maximumFileSize) {
        throw new IOException(
                "Torrent size exceeds maximum uploadable size");
    }

    int index = contentType.lastIndexOf("boundary=");

    String end = contentType.substring(index + 9);
    System.out.println("end:" + end);

    end = "--" + end;

My browser app which use JEditorPane outputs the following
Content type: application/x-www-form-urlencoded
Content type: application/x-www-form-urlencoded
end:ion/x-www-form-urlencoded

While firefox reads it in correctly with
Content type: multipart/form-data; boundary=---------------------------42291047110428
Content type: multipart/form-data; boundary=---------------------------42291047110428
end:---------------------------42291047110428

any ideas.....
do I have to we write the HTMLEditorKit to take care of these types of things...
I can see how it would be in this case... but above, the session issues, while are
probably related, are the same problem... anyone who can shed some light on this
would be a big help

THanks in advance
T.J.

OK I am glad I am the only one who can help myself.. figured out the second part...

I have to extend the JEditorPane and override the setPage and handleURL methods to
fix the file upload problem... but the session scoped bean is still a problem

OK narrowed down the problem... I have to set a header name cookie and JSESSIONID some value

is this value random???
and how should I persist it within my app?? always send the same one???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.