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;
}