Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Still no luck with Web App

Reply
Thread Tools

Re: Still no luck with Web App

 
 
Talking with Tonz - Emery Z. Balint Jr.
Guest
Posts: n/a
 
      07-25-2003
Hi Andy,

Thank you for testing the app. I'm using Tomcat 4.1.24.

Did you try doing the following: after immediately logging out, hitting the
brower's back button and then hitting refresh. That should take you back to
the login screen, but then the app fails. It won't login or logout properly
again. It works great only the first time around.

I also noticed that the first time I logged out, the System.out.println's in
the logout section did what they were supposed to. But the second time I
tried logging out, they would no longer show up. I don't know what's going
on.

Emery.
/\^/\^/\
Sun Certified Java Programmer
www.websamba.com/javarobotics/
E-stronomy - Astronomical Resrouces
www.websamba.com/e-stronomy/


"Andy Flowers" <(E-Mail Removed)> wrote in message
news:16gUa.1771$(E-Mail Removed)...
> Runs perfect for me.
>
> What version of Tomcat are you using ? I have 4.0.3 running under JBuilder
> 7.
>
> "Talking with Tonz - Emery Z. Balint Jr."
> <(E-Mail Removed)-> wrote in message
> newsyeUa.31419$(E-Mail Removed) ...
> > Hello Folks,
> >
> > Argg. I am still not having any luck with this Web app. I've done stuff

> like
> > this in ASP easily. But somehow it just isn't working here. I've taken

the
> > advice of some helpful people but it hasn't worked. Something tells me

> that
> > this should be working, but yet isn't.
> >
> > 1. Login with a fake username (any username works at this point).
> > 2. You can switch between the whatever and user_mod JSP pages. Great.
> > 3. You can logout THE FIRST TIME.
> > 4. At this point you can hit the link to login again. Loggin in again

> works.
> > The back button/refresh can get goofy though.
> > 5. You can't logout anymore!! The logout page seems not to do anything
> > anymore! At least no output is show in the Tomcat console.
> > 6. Everything goes wrong again. Somehow the servlet isn't run again, or
> > appears that it's not running. Logging in no longer function properly.
> >
> > All the code is posted below. I would again appreciate some help, I

really
> > don't know why this is behaving the way it is. There are lots of
> > System.out.println's in the code so you can see the output in Tomcat.

> Many,
> > many thanks in advance for any help!
> >
> > Emery.
> > /\^/\^/\
> > Sun Certified Java Programmer
> > www.websamba.com/javarobotics/
> > E-stronomy - Astronomical Resrouces
> > www.websamba.com/e-stronomy/
> >
> > ===================================
> > Controller.java
> > (in the "src\com\nsae\testdb1\controller" folder)
> > ===================================
> > package com.nsae.testdb1.controller;
> >
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> >
> > import java.io.*;
> >
> > import com.nsae.testdb1.*;
> >
> > public class Controller extends HttpServlet {
> >
> > protected static final String LOGIN_PAGE = "/login.html";
> > protected static final String MOD_USER_PAGE = "/mod_user.jsp";
> > protected static final String ADD_USER_PAGE = "/add_user.jsp";
> > protected static final String DEL_USER_PAGE = "/del_user.jsp";
> > protected static final String UPD_USER_PAGE = "/upd_user.jsp";
> > protected static final String WHATEVER_PAGE = "/whatever.jsp";
> > protected static final String LOGOUT_PAGE = "/logout.html";
> >
> > public void doGet(HttpServletRequest req, HttpServletResponse res)

throws
> > ServletException, IOException {
> > doPost(req, res);
> > }
> >
> > public void doPost(HttpServletRequest req, HttpServletResponse res)

> throws
> > ServletException, IOException {
> > String formAction = req.getParameter("form_action");
> > String forwardTo = LOGIN_PAGE;
> >
> > if ((formAction==null) || (formAction.equals(""))) {
> > HttpSession session = req.getSession(true);
> > System.out.println("formAction==null");
> >
> > if (!session.isNew()) {
> > System.out.println("formAction==null | session is not new");
> > session.invalidate();
> > session = req.getSession(true);
> > System.out.println(session.isNew());
> > }
> >
> > } else if (formAction.equals("login")) {
> > HttpSession session = req.getSession(false);
> > System.out.println("formAction==login");
> >
> > if (session!=null) {
> > System.out.println("formAction==login | session!=null");
> > if (!session.isNew()) {
> > UserCheck uC = new UserCheck(req.getParameter("username"));
> > session.setAttribute("user", uC.getUserName());
> > session.setAttribute("servletPath", getFullServletPath(req));
> > session.setMaxInactiveInterval(300);
> > forwardTo = MOD_USER_PAGE;
> > System.out.println("formAction==login | session is not new");
> > } else {
> > session.invalidate();
> > session = req.getSession(true);
> > System.out.println("formAction==login | session was new");
> > }
> > }
> >
> > } else if (formAction.equals("user_mod")) {
> > HttpSession session = req.getSession(false);
> > System.out.println("formAction==user_mod");
> >
> > if (session.getAttribute("user")!=null) {
> > forwardTo = MOD_USER_PAGE;
> > System.out.println("formAction==user_mod | user!=null");
> > } else {
> > System.out.println("formAction==user_mod | user==null");
> > }
> >
> > } else if (formAction.equals("whatever")) {
> > HttpSession session = req.getSession(false);
> > System.out.println("formAction==whatever");
> >
> > if (session.getAttribute("user")!=null) {
> > forwardTo = WHATEVER_PAGE;
> > System.out.println("formAction==whatever | user!=null");
> > } else {
> > System.out.println("formAction==whatever | user==null");
> > }
> >
> > } else if (formAction.equals("logout")) {
> > HttpSession session = req.getSession(false);
> > System.out.println("formAction==logout: " + session.isNew());
> >
> > if (session!=null) {
> > session.removeAttribute("user");
> > forwardTo = LOGOUT_PAGE;
> > System.out.println("formAction==logout | session!=null");
> > } else {
> > forwardTo = LOGOUT_PAGE;
> > System.out.println("formAction==logout | session==null");
> > session = req.getSession(true);
> > }
> > }
> >
> > System.out.println(res.encodeURL(forwardTo));
> > RequestDispatcher rD =

> req.getRequestDispatcher(res.encodeURL(forwardTo)) ;
> > rD.forward(req, res);
> >
> > }
> >
> > protected String getFullServletPath(HttpServletRequest req) {
> > String servlet = req.getServletPath();
> > String ctxPath = req.getContextPath();
> > return (ctxPath + servlet);
> > }
> >
> > }
> >
> > ===================================
> > UserCheck.java (will be implemented later)
> > (in the "src\com\nsae\testdb1" folder)
> > ===================================
> > package com.nsae.testdb1;
> >
> > public class UserCheck {
> >
> > private String userName = "";
> >
> > public UserCheck() {
> > }
> >
> > public UserCheck(String uN) {
> > userName = uN;
> > }
> >
> > public String getUserName() {
> > return userName;
> > }
> >
> > public void setUserName(String uN) {
> > userName = uN;
> > }
> >
> > }
> >
> > ===================================
> > index.jsp
> > (in the "web" folder)
> > (this simply forwards the browser to
> > the servlet so an initial session can be established)
> > ===================================
> > <jsp:forward page="testdb1"/>
> >
> > ===================================
> > login.html
> > (in the "web" folder)
> > ===================================
> > <html>
> >
> > <head>
> > <title>Login</title>
> > </head>
> >
> > <body bgcolor="#FFFFFF">
> > Please login:
> >
> > <p>
> > <form action="testdb1" method="post">
> > <input type="hidden" name="form_action" value="login">
> > <input type="text" name="username" size="20"> - Username<br>
> > <input type="text" name="password" size="20"> - Password<br>
> > <input type="submit" value="Submit">
> > <input type="reset" value="Reset">
> > </form>
> >
> > </body>
> >
> > </html>
> >
> > ===================================
> > logout.html
> > (in the "web" folder)
> > ===================================
> > <html>
> >
> > <head>
> > <title>Logout</title>
> > </head>
> >
> > <body bgcolor="#FFFFFF">
> > Thanks for logging out!
> >
> > <p>
> > <a href="testdb1" target="_parent">Login Again?</a>
> >
> > </body>
> >
> > </html>
> >
> > ===================================
> > mod_user.jsp
> > (in the "web" folder)
> > ===================================
> > <jsp:useBean id="servletPath" class="java.lang.String" scope="session"/>
> > <jsp:useBean id="user" class="java.lang.String" scope="session"/>
> >
> > <html>
> >
> > <head>
> > <title>Modify User</title>
> > </head>
> >
> > <body bgcolor="#FFFFFF">
> > <a href="testdb1?form_action=whatever">Whatever</a> |
> > <a href="testdb1?form_action=logout">Logout</a>
> >
> > <p>
> > Hi <%=user%>!
> >
> > <p>
> > Add User:
> >
> > <p>
> > <form action="testdb1" method="post">
> > <input type="hidden" name="form_action" value="add_user">
> > <input type="text" name="username" size="20"> - Username<br>
> > <input type="text" name="password" size="20"> - Password<br>
> > <input type="submit" value="Add">
> > <input type="reset" value="Reset">
> > </form>
> >
> > Modify User Information:
> >
> > <p>
> > <form action="testdb1" method="post">
> > <input type="hidden" name="form_action" value="mod_user">
> > <input type="hidden" name="user_id" value="user_id">
> > <input type="text" name="username" size="20"> - Username<br>
> > <input type="text" name="password" size="20"> - Password<br>
> > <input type="submit" value="Update">
> > <input type="reset" value="Reset">
> > </form>
> >
> > <p>
> > Delete User:
> >
> > <p>
> > <form action="testdb1" method="post">
> > <input type="hidden" name="form_action" value="del_user">
> > <input type="hidden" name="user_id" value="user_id">
> > <input type="submit" value="Delete">
> > <input type="reset" value="Reset">
> > </form>
> >
> > </body>
> >
> > </html>
> >
> > ===================================
> > whatever.jsp
> > (in the "web" folder)
> > ===================================
> > <jsp:useBean id="servletPath" class="java.lang.String" scope="session"/>
> > <jsp:useBean id="user" class="java.lang.String" scope="session"/>
> >
> > <html>
> >
> > <head>
> > <title>Just a Session Test</title>
> > </head>
> >
> > <body bgcolor="#FFFFFF">
> > <a href="testdb1?form_action=user_mod">Modify Users?</a> |
> > <a href="testdb1?form_action=logout">Logout</a>
> >
> > <p>
> > Hi <%=user%>!
> >
> > </body>
> >
> > </html>
> >
> > ===================================
> > web.xml
> > (in the "web/WEB-INF" folder)
> > ===================================
> > <?xml version="1.0" encoding="ISO-8859-1" ?>
> >
> > <!DOCTYPE web-app
> > PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
> > "http://java.sun.com/dtd/web-app_2_3.dtd" >
> >
> > <web-app>
> > <icon>
> > </icon>
> > <display-name>Test Database Application</display-name>
> > <description>
> > This is a test of a database editing application.
> > </description>
> >
> > <servlet>
> > <servlet-name>Controller</servlet-name>
> > <description>
> > Controller Servlet
> > </description>
> > <servlet-class>
> > com.nsae.testdb1.controller.Controller
> > </servlet-class>
> > </servlet>
> >
> > <servlet-mapping>
> > <servlet-name>Controller</servlet-name>
> > <url-pattern>/testdb1</url-pattern>
> > </servlet-mapping>
> > </web-app>
> >
> >

>
>



 
Reply With Quote
 
 
 
 
Andy Flowers
Guest
Posts: n/a
 
      07-26-2003
Still works fine even with the refresh.

There's a couple of suggestions about the code though. First off use JSP
pages for everything, even the HTML. This makes it easier in the long run
should something need to become dynamic. Also there's no need to use
isNew(). Rely on the fact that if it's a new session there are no values in
it's attributes, and that these will disappear with the invalidate().

Perhaps isNew() is failing in your scenario, there are a few bugs/caveats
around the use of isNew() in Tomcat 4.1.x ?

"Talking with Tonz - Emery Z. Balint Jr."
<(E-Mail Removed)-> wrote in message
news:XNhUa.36060$(E-Mail Removed). ..
> Hi Andy,
>
> Thank you for testing the app. I'm using Tomcat 4.1.24.
>
> Did you try doing the following: after immediately logging out, hitting

the
> brower's back button and then hitting refresh. That should take you back

to
> the login screen, but then the app fails. It won't login or logout

properly
> again. It works great only the first time around.
>
> I also noticed that the first time I logged out, the System.out.println's

in
> the logout section did what they were supposed to. But the second time I
> tried logging out, they would no longer show up. I don't know what's going
> on.
>
> Emery.
> /\^/\^/\
> Sun Certified Java Programmer
> www.websamba.com/javarobotics/
> E-stronomy - Astronomical Resrouces
> www.websamba.com/e-stronomy/
>
>
> "Andy Flowers" <(E-Mail Removed)> wrote in message
> news:16gUa.1771$(E-Mail Removed)...
> > Runs perfect for me.
> >
> > What version of Tomcat are you using ? I have 4.0.3 running under

JBuilder
> > 7.
> >
> > "Talking with Tonz - Emery Z. Balint Jr."
> > <(E-Mail Removed)-> wrote in message
> > newsyeUa.31419$(E-Mail Removed) ...
> > > Hello Folks,
> > >
> > > Argg. I am still not having any luck with this Web app. I've done

stuff
> > like
> > > this in ASP easily. But somehow it just isn't working here. I've taken

> the
> > > advice of some helpful people but it hasn't worked. Something tells me

> > that
> > > this should be working, but yet isn't.
> > >
> > > 1. Login with a fake username (any username works at this point).
> > > 2. You can switch between the whatever and user_mod JSP pages. Great.
> > > 3. You can logout THE FIRST TIME.
> > > 4. At this point you can hit the link to login again. Loggin in again

> > works.
> > > The back button/refresh can get goofy though.
> > > 5. You can't logout anymore!! The logout page seems not to do anything
> > > anymore! At least no output is show in the Tomcat console.
> > > 6. Everything goes wrong again. Somehow the servlet isn't run again,

or
> > > appears that it's not running. Logging in no longer function properly.
> > >
> > > All the code is posted below. I would again appreciate some help, I

> really
> > > don't know why this is behaving the way it is. There are lots of
> > > System.out.println's in the code so you can see the output in Tomcat.

> > Many,
> > > many thanks in advance for any help!
> > >
> > > Emery.
> > > /\^/\^/\
> > > Sun Certified Java Programmer
> > > www.websamba.com/javarobotics/
> > > E-stronomy - Astronomical Resrouces
> > > www.websamba.com/e-stronomy/
> > >
> > > ===================================
> > > Controller.java
> > > (in the "src\com\nsae\testdb1\controller" folder)
> > > ===================================
> > > package com.nsae.testdb1.controller;
> > >
> > > import javax.servlet.*;
> > > import javax.servlet.http.*;
> > >
> > > import java.io.*;
> > >
> > > import com.nsae.testdb1.*;
> > >
> > > public class Controller extends HttpServlet {
> > >
> > > protected static final String LOGIN_PAGE = "/login.html";
> > > protected static final String MOD_USER_PAGE = "/mod_user.jsp";
> > > protected static final String ADD_USER_PAGE = "/add_user.jsp";
> > > protected static final String DEL_USER_PAGE = "/del_user.jsp";
> > > protected static final String UPD_USER_PAGE = "/upd_user.jsp";
> > > protected static final String WHATEVER_PAGE = "/whatever.jsp";
> > > protected static final String LOGOUT_PAGE = "/logout.html";
> > >
> > > public void doGet(HttpServletRequest req, HttpServletResponse res)

> throws
> > > ServletException, IOException {
> > > doPost(req, res);
> > > }
> > >
> > > public void doPost(HttpServletRequest req, HttpServletResponse res)

> > throws
> > > ServletException, IOException {
> > > String formAction = req.getParameter("form_action");
> > > String forwardTo = LOGIN_PAGE;
> > >
> > > if ((formAction==null) || (formAction.equals(""))) {
> > > HttpSession session = req.getSession(true);
> > > System.out.println("formAction==null");
> > >
> > > if (!session.isNew()) {
> > > System.out.println("formAction==null | session is not new");
> > > session.invalidate();
> > > session = req.getSession(true);
> > > System.out.println(session.isNew());
> > > }
> > >
> > > } else if (formAction.equals("login")) {
> > > HttpSession session = req.getSession(false);
> > > System.out.println("formAction==login");
> > >
> > > if (session!=null) {
> > > System.out.println("formAction==login | session!=null");
> > > if (!session.isNew()) {
> > > UserCheck uC = new UserCheck(req.getParameter("username"));
> > > session.setAttribute("user", uC.getUserName());
> > > session.setAttribute("servletPath", getFullServletPath(req));
> > > session.setMaxInactiveInterval(300);
> > > forwardTo = MOD_USER_PAGE;
> > > System.out.println("formAction==login | session is not new");
> > > } else {
> > > session.invalidate();
> > > session = req.getSession(true);
> > > System.out.println("formAction==login | session was new");
> > > }
> > > }
> > >
> > > } else if (formAction.equals("user_mod")) {
> > > HttpSession session = req.getSession(false);
> > > System.out.println("formAction==user_mod");
> > >
> > > if (session.getAttribute("user")!=null) {
> > > forwardTo = MOD_USER_PAGE;
> > > System.out.println("formAction==user_mod | user!=null");
> > > } else {
> > > System.out.println("formAction==user_mod | user==null");
> > > }
> > >
> > > } else if (formAction.equals("whatever")) {
> > > HttpSession session = req.getSession(false);
> > > System.out.println("formAction==whatever");
> > >
> > > if (session.getAttribute("user")!=null) {
> > > forwardTo = WHATEVER_PAGE;
> > > System.out.println("formAction==whatever | user!=null");
> > > } else {
> > > System.out.println("formAction==whatever | user==null");
> > > }
> > >
> > > } else if (formAction.equals("logout")) {
> > > HttpSession session = req.getSession(false);
> > > System.out.println("formAction==logout: " + session.isNew());
> > >
> > > if (session!=null) {
> > > session.removeAttribute("user");
> > > forwardTo = LOGOUT_PAGE;
> > > System.out.println("formAction==logout | session!=null");
> > > } else {
> > > forwardTo = LOGOUT_PAGE;
> > > System.out.println("formAction==logout | session==null");
> > > session = req.getSession(true);
> > > }
> > > }
> > >
> > > System.out.println(res.encodeURL(forwardTo));
> > > RequestDispatcher rD =

> > req.getRequestDispatcher(res.encodeURL(forwardTo)) ;
> > > rD.forward(req, res);
> > >
> > > }
> > >
> > > protected String getFullServletPath(HttpServletRequest req) {
> > > String servlet = req.getServletPath();
> > > String ctxPath = req.getContextPath();
> > > return (ctxPath + servlet);
> > > }
> > >
> > > }
> > >
> > > ===================================
> > > UserCheck.java (will be implemented later)
> > > (in the "src\com\nsae\testdb1" folder)
> > > ===================================
> > > package com.nsae.testdb1;
> > >
> > > public class UserCheck {
> > >
> > > private String userName = "";
> > >
> > > public UserCheck() {
> > > }
> > >
> > > public UserCheck(String uN) {
> > > userName = uN;
> > > }
> > >
> > > public String getUserName() {
> > > return userName;
> > > }
> > >
> > > public void setUserName(String uN) {
> > > userName = uN;
> > > }
> > >
> > > }
> > >
> > > ===================================
> > > index.jsp
> > > (in the "web" folder)
> > > (this simply forwards the browser to
> > > the servlet so an initial session can be established)
> > > ===================================
> > > <jsp:forward page="testdb1"/>
> > >
> > > ===================================
> > > login.html
> > > (in the "web" folder)
> > > ===================================
> > > <html>
> > >
> > > <head>
> > > <title>Login</title>
> > > </head>
> > >
> > > <body bgcolor="#FFFFFF">
> > > Please login:
> > >
> > > <p>
> > > <form action="testdb1" method="post">
> > > <input type="hidden" name="form_action" value="login">
> > > <input type="text" name="username" size="20"> - Username<br>
> > > <input type="text" name="password" size="20"> - Password<br>
> > > <input type="submit" value="Submit">
> > > <input type="reset" value="Reset">
> > > </form>
> > >
> > > </body>
> > >
> > > </html>
> > >
> > > ===================================
> > > logout.html
> > > (in the "web" folder)
> > > ===================================
> > > <html>
> > >
> > > <head>
> > > <title>Logout</title>
> > > </head>
> > >
> > > <body bgcolor="#FFFFFF">
> > > Thanks for logging out!
> > >
> > > <p>
> > > <a href="testdb1" target="_parent">Login Again?</a>
> > >
> > > </body>
> > >
> > > </html>
> > >
> > > ===================================
> > > mod_user.jsp
> > > (in the "web" folder)
> > > ===================================
> > > <jsp:useBean id="servletPath" class="java.lang.String"

scope="session"/>
> > > <jsp:useBean id="user" class="java.lang.String" scope="session"/>
> > >
> > > <html>
> > >
> > > <head>
> > > <title>Modify User</title>
> > > </head>
> > >
> > > <body bgcolor="#FFFFFF">
> > > <a href="testdb1?form_action=whatever">Whatever</a> |
> > > <a href="testdb1?form_action=logout">Logout</a>
> > >
> > > <p>
> > > Hi <%=user%>!
> > >
> > > <p>
> > > Add User:
> > >
> > > <p>
> > > <form action="testdb1" method="post">
> > > <input type="hidden" name="form_action" value="add_user">
> > > <input type="text" name="username" size="20"> - Username<br>
> > > <input type="text" name="password" size="20"> - Password<br>
> > > <input type="submit" value="Add">
> > > <input type="reset" value="Reset">
> > > </form>
> > >
> > > Modify User Information:
> > >
> > > <p>
> > > <form action="testdb1" method="post">
> > > <input type="hidden" name="form_action" value="mod_user">
> > > <input type="hidden" name="user_id" value="user_id">
> > > <input type="text" name="username" size="20"> - Username<br>
> > > <input type="text" name="password" size="20"> - Password<br>
> > > <input type="submit" value="Update">
> > > <input type="reset" value="Reset">
> > > </form>
> > >
> > > <p>
> > > Delete User:
> > >
> > > <p>
> > > <form action="testdb1" method="post">
> > > <input type="hidden" name="form_action" value="del_user">
> > > <input type="hidden" name="user_id" value="user_id">
> > > <input type="submit" value="Delete">
> > > <input type="reset" value="Reset">
> > > </form>
> > >
> > > </body>
> > >
> > > </html>
> > >
> > > ===================================
> > > whatever.jsp
> > > (in the "web" folder)
> > > ===================================
> > > <jsp:useBean id="servletPath" class="java.lang.String"

scope="session"/>
> > > <jsp:useBean id="user" class="java.lang.String" scope="session"/>
> > >
> > > <html>
> > >
> > > <head>
> > > <title>Just a Session Test</title>
> > > </head>
> > >
> > > <body bgcolor="#FFFFFF">
> > > <a href="testdb1?form_action=user_mod">Modify Users?</a> |
> > > <a href="testdb1?form_action=logout">Logout</a>
> > >
> > > <p>
> > > Hi <%=user%>!
> > >
> > > </body>
> > >
> > > </html>
> > >
> > > ===================================
> > > web.xml
> > > (in the "web/WEB-INF" folder)
> > > ===================================
> > > <?xml version="1.0" encoding="ISO-8859-1" ?>
> > >
> > > <!DOCTYPE web-app
> > > PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
> > > "http://java.sun.com/dtd/web-app_2_3.dtd" >
> > >
> > > <web-app>
> > > <icon>
> > > </icon>
> > > <display-name>Test Database Application</display-name>
> > > <description>
> > > This is a test of a database editing application.
> > > </description>
> > >
> > > <servlet>
> > > <servlet-name>Controller</servlet-name>
> > > <description>
> > > Controller Servlet
> > > </description>
> > > <servlet-class>
> > > com.nsae.testdb1.controller.Controller
> > > </servlet-class>
> > > </servlet>
> > >
> > > <servlet-mapping>
> > > <servlet-name>Controller</servlet-name>
> > > <url-pattern>/testdb1</url-pattern>
> > > </servlet-mapping>
> > > </web-app>
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
 
Talking with Tonz - Emery Z. Balint Jr.
Guest
Posts: n/a
 
      07-26-2003
Hello Andy,

Again, thank you for your assistance. I actually ended up renaming all my
html files to jsp and then everything started working. I also posted my new
code (Post subject: Fixed Web App Issue But Do Servlets Ignore HTML Pages?)
where my app relies on whether or not the "user" is still in the session
instead of isNew(). Less code and works better too. I can finally rest easy.
8^D

Emery.
/\^/\^/\
Sun Certified Java Programmer
www.websamba.com/javarobotics/
E-stronomy - Astronomical Resrouces
www.websamba.com/e-stronomy/


"Andy Flowers" <(E-Mail Removed)> wrote in message
news:Y6qUa.2116$(E-Mail Removed)...
> Still works fine even with the refresh.
>
> There's a couple of suggestions about the code though. First off use JSP
> pages for everything, even the HTML. This makes it easier in the long run
> should something need to become dynamic. Also there's no need to use
> isNew(). Rely on the fact that if it's a new session there are no values

in
> it's attributes, and that these will disappear with the invalidate().
>
> Perhaps isNew() is failing in your scenario, there are a few bugs/caveats
> around the use of isNew() in Tomcat 4.1.x ?
>
> "Talking with Tonz - Emery Z. Balint Jr."
> <(E-Mail Removed)-> wrote in message
> news:XNhUa.36060$(E-Mail Removed). ..
> > Hi Andy,
> >
> > Thank you for testing the app. I'm using Tomcat 4.1.24.
> >
> > Did you try doing the following: after immediately logging out, hitting

> the
> > brower's back button and then hitting refresh. That should take you back

> to
> > the login screen, but then the app fails. It won't login or logout

> properly
> > again. It works great only the first time around.
> >
> > I also noticed that the first time I logged out, the

System.out.println's
> in
> > the logout section did what they were supposed to. But the second time I
> > tried logging out, they would no longer show up. I don't know what's

going
> > on.
> >
> > Emery.
> > /\^/\^/\
> > Sun Certified Java Programmer
> > www.websamba.com/javarobotics/
> > E-stronomy - Astronomical Resrouces
> > www.websamba.com/e-stronomy/
> >
> >
> > "Andy Flowers" <(E-Mail Removed)> wrote in message
> > news:16gUa.1771$(E-Mail Removed)...
> > > Runs perfect for me.
> > >
> > > What version of Tomcat are you using ? I have 4.0.3 running under

> JBuilder
> > > 7.
> > >
> > > "Talking with Tonz - Emery Z. Balint Jr."
> > > <(E-Mail Removed)-> wrote in message
> > > newsyeUa.31419$(E-Mail Removed) ...
> > > > Hello Folks,
> > > >
> > > > Argg. I am still not having any luck with this Web app. I've done

> stuff
> > > like
> > > > this in ASP easily. But somehow it just isn't working here. I've

taken
> > the
> > > > advice of some helpful people but it hasn't worked. Something tells

me
> > > that
> > > > this should be working, but yet isn't.
> > > >
> > > > 1. Login with a fake username (any username works at this point).
> > > > 2. You can switch between the whatever and user_mod JSP pages.

Great.
> > > > 3. You can logout THE FIRST TIME.
> > > > 4. At this point you can hit the link to login again. Loggin in

again
> > > works.
> > > > The back button/refresh can get goofy though.
> > > > 5. You can't logout anymore!! The logout page seems not to do

anything
> > > > anymore! At least no output is show in the Tomcat console.
> > > > 6. Everything goes wrong again. Somehow the servlet isn't run again,

> or
> > > > appears that it's not running. Logging in no longer function

properly.
> > > >
> > > > All the code is posted below. I would again appreciate some help, I

> > really
> > > > don't know why this is behaving the way it is. There are lots of
> > > > System.out.println's in the code so you can see the output in

Tomcat.
> > > Many,
> > > > many thanks in advance for any help!
> > > >
> > > > Emery.
> > > > /\^/\^/\
> > > > Sun Certified Java Programmer
> > > > www.websamba.com/javarobotics/
> > > > E-stronomy - Astronomical Resrouces
> > > > www.websamba.com/e-stronomy/
> > > >
> > > > ===================================
> > > > Controller.java
> > > > (in the "src\com\nsae\testdb1\controller" folder)
> > > > ===================================
> > > > package com.nsae.testdb1.controller;
> > > >
> > > > import javax.servlet.*;
> > > > import javax.servlet.http.*;
> > > >
> > > > import java.io.*;
> > > >
> > > > import com.nsae.testdb1.*;
> > > >
> > > > public class Controller extends HttpServlet {
> > > >
> > > > protected static final String LOGIN_PAGE = "/login.html";
> > > > protected static final String MOD_USER_PAGE = "/mod_user.jsp";
> > > > protected static final String ADD_USER_PAGE = "/add_user.jsp";
> > > > protected static final String DEL_USER_PAGE = "/del_user.jsp";
> > > > protected static final String UPD_USER_PAGE = "/upd_user.jsp";
> > > > protected static final String WHATEVER_PAGE = "/whatever.jsp";
> > > > protected static final String LOGOUT_PAGE = "/logout.html";
> > > >
> > > > public void doGet(HttpServletRequest req, HttpServletResponse res)

> > throws
> > > > ServletException, IOException {
> > > > doPost(req, res);
> > > > }
> > > >
> > > > public void doPost(HttpServletRequest req, HttpServletResponse res)
> > > throws
> > > > ServletException, IOException {
> > > > String formAction = req.getParameter("form_action");
> > > > String forwardTo = LOGIN_PAGE;
> > > >
> > > > if ((formAction==null) || (formAction.equals(""))) {
> > > > HttpSession session = req.getSession(true);
> > > > System.out.println("formAction==null");
> > > >
> > > > if (!session.isNew()) {
> > > > System.out.println("formAction==null | session is not new");
> > > > session.invalidate();
> > > > session = req.getSession(true);
> > > > System.out.println(session.isNew());
> > > > }
> > > >
> > > > } else if (formAction.equals("login")) {
> > > > HttpSession session = req.getSession(false);
> > > > System.out.println("formAction==login");
> > > >
> > > > if (session!=null) {
> > > > System.out.println("formAction==login | session!=null");
> > > > if (!session.isNew()) {
> > > > UserCheck uC = new UserCheck(req.getParameter("username"));
> > > > session.setAttribute("user", uC.getUserName());
> > > > session.setAttribute("servletPath", getFullServletPath(req));
> > > > session.setMaxInactiveInterval(300);
> > > > forwardTo = MOD_USER_PAGE;
> > > > System.out.println("formAction==login | session is not new");
> > > > } else {
> > > > session.invalidate();
> > > > session = req.getSession(true);
> > > > System.out.println("formAction==login | session was new");
> > > > }
> > > > }
> > > >
> > > > } else if (formAction.equals("user_mod")) {
> > > > HttpSession session = req.getSession(false);
> > > > System.out.println("formAction==user_mod");
> > > >
> > > > if (session.getAttribute("user")!=null) {
> > > > forwardTo = MOD_USER_PAGE;
> > > > System.out.println("formAction==user_mod | user!=null");
> > > > } else {
> > > > System.out.println("formAction==user_mod | user==null");
> > > > }
> > > >
> > > > } else if (formAction.equals("whatever")) {
> > > > HttpSession session = req.getSession(false);
> > > > System.out.println("formAction==whatever");
> > > >
> > > > if (session.getAttribute("user")!=null) {
> > > > forwardTo = WHATEVER_PAGE;
> > > > System.out.println("formAction==whatever | user!=null");
> > > > } else {
> > > > System.out.println("formAction==whatever | user==null");
> > > > }
> > > >
> > > > } else if (formAction.equals("logout")) {
> > > > HttpSession session = req.getSession(false);
> > > > System.out.println("formAction==logout: " + session.isNew());
> > > >
> > > > if (session!=null) {
> > > > session.removeAttribute("user");
> > > > forwardTo = LOGOUT_PAGE;
> > > > System.out.println("formAction==logout | session!=null");
> > > > } else {
> > > > forwardTo = LOGOUT_PAGE;
> > > > System.out.println("formAction==logout | session==null");
> > > > session = req.getSession(true);
> > > > }
> > > > }
> > > >
> > > > System.out.println(res.encodeURL(forwardTo));
> > > > RequestDispatcher rD =
> > > req.getRequestDispatcher(res.encodeURL(forwardTo)) ;
> > > > rD.forward(req, res);
> > > >
> > > > }
> > > >
> > > > protected String getFullServletPath(HttpServletRequest req) {
> > > > String servlet = req.getServletPath();
> > > > String ctxPath = req.getContextPath();
> > > > return (ctxPath + servlet);
> > > > }
> > > >
> > > > }
> > > >
> > > > ===================================
> > > > UserCheck.java (will be implemented later)
> > > > (in the "src\com\nsae\testdb1" folder)
> > > > ===================================
> > > > package com.nsae.testdb1;
> > > >
> > > > public class UserCheck {
> > > >
> > > > private String userName = "";
> > > >
> > > > public UserCheck() {
> > > > }
> > > >
> > > > public UserCheck(String uN) {
> > > > userName = uN;
> > > > }
> > > >
> > > > public String getUserName() {
> > > > return userName;
> > > > }
> > > >
> > > > public void setUserName(String uN) {
> > > > userName = uN;
> > > > }
> > > >
> > > > }
> > > >
> > > > ===================================
> > > > index.jsp
> > > > (in the "web" folder)
> > > > (this simply forwards the browser to
> > > > the servlet so an initial session can be established)
> > > > ===================================
> > > > <jsp:forward page="testdb1"/>
> > > >
> > > > ===================================
> > > > login.html
> > > > (in the "web" folder)
> > > > ===================================
> > > > <html>
> > > >
> > > > <head>
> > > > <title>Login</title>
> > > > </head>
> > > >
> > > > <body bgcolor="#FFFFFF">
> > > > Please login:
> > > >
> > > > <p>
> > > > <form action="testdb1" method="post">
> > > > <input type="hidden" name="form_action" value="login">
> > > > <input type="text" name="username" size="20"> - Username<br>
> > > > <input type="text" name="password" size="20"> - Password<br>
> > > > <input type="submit" value="Submit">
> > > > <input type="reset" value="Reset">
> > > > </form>
> > > >
> > > > </body>
> > > >
> > > > </html>
> > > >
> > > > ===================================
> > > > logout.html
> > > > (in the "web" folder)
> > > > ===================================
> > > > <html>
> > > >
> > > > <head>
> > > > <title>Logout</title>
> > > > </head>
> > > >
> > > > <body bgcolor="#FFFFFF">
> > > > Thanks for logging out!
> > > >
> > > > <p>
> > > > <a href="testdb1" target="_parent">Login Again?</a>
> > > >
> > > > </body>
> > > >
> > > > </html>
> > > >
> > > > ===================================
> > > > mod_user.jsp
> > > > (in the "web" folder)
> > > > ===================================
> > > > <jsp:useBean id="servletPath" class="java.lang.String"

> scope="session"/>
> > > > <jsp:useBean id="user" class="java.lang.String" scope="session"/>
> > > >
> > > > <html>
> > > >
> > > > <head>
> > > > <title>Modify User</title>
> > > > </head>
> > > >
> > > > <body bgcolor="#FFFFFF">
> > > > <a href="testdb1?form_action=whatever">Whatever</a> |
> > > > <a href="testdb1?form_action=logout">Logout</a>
> > > >
> > > > <p>
> > > > Hi <%=user%>!
> > > >
> > > > <p>
> > > > Add User:
> > > >
> > > > <p>
> > > > <form action="testdb1" method="post">
> > > > <input type="hidden" name="form_action" value="add_user">
> > > > <input type="text" name="username" size="20"> - Username<br>
> > > > <input type="text" name="password" size="20"> - Password<br>
> > > > <input type="submit" value="Add">
> > > > <input type="reset" value="Reset">
> > > > </form>
> > > >
> > > > Modify User Information:
> > > >
> > > > <p>
> > > > <form action="testdb1" method="post">
> > > > <input type="hidden" name="form_action" value="mod_user">
> > > > <input type="hidden" name="user_id" value="user_id">
> > > > <input type="text" name="username" size="20"> - Username<br>
> > > > <input type="text" name="password" size="20"> - Password<br>
> > > > <input type="submit" value="Update">
> > > > <input type="reset" value="Reset">
> > > > </form>
> > > >
> > > > <p>
> > > > Delete User:
> > > >
> > > > <p>
> > > > <form action="testdb1" method="post">
> > > > <input type="hidden" name="form_action" value="del_user">
> > > > <input type="hidden" name="user_id" value="user_id">
> > > > <input type="submit" value="Delete">
> > > > <input type="reset" value="Reset">
> > > > </form>
> > > >
> > > > </body>
> > > >
> > > > </html>
> > > >
> > > > ===================================
> > > > whatever.jsp
> > > > (in the "web" folder)
> > > > ===================================
> > > > <jsp:useBean id="servletPath" class="java.lang.String"

> scope="session"/>
> > > > <jsp:useBean id="user" class="java.lang.String" scope="session"/>
> > > >
> > > > <html>
> > > >
> > > > <head>
> > > > <title>Just a Session Test</title>
> > > > </head>
> > > >
> > > > <body bgcolor="#FFFFFF">
> > > > <a href="testdb1?form_action=user_mod">Modify Users?</a> |
> > > > <a href="testdb1?form_action=logout">Logout</a>
> > > >
> > > > <p>
> > > > Hi <%=user%>!
> > > >
> > > > </body>
> > > >
> > > > </html>
> > > >
> > > > ===================================
> > > > web.xml
> > > > (in the "web/WEB-INF" folder)
> > > > ===================================
> > > > <?xml version="1.0" encoding="ISO-8859-1" ?>
> > > >
> > > > <!DOCTYPE web-app
> > > > PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
> > > > "http://java.sun.com/dtd/web-app_2_3.dtd" >
> > > >
> > > > <web-app>
> > > > <icon>
> > > > </icon>
> > > > <display-name>Test Database Application</display-name>
> > > > <description>
> > > > This is a test of a database editing application.
> > > > </description>
> > > >
> > > > <servlet>
> > > > <servlet-name>Controller</servlet-name>
> > > > <description>
> > > > Controller Servlet
> > > > </description>
> > > > <servlet-class>
> > > > com.nsae.testdb1.controller.Controller
> > > > </servlet-class>
> > > > </servlet>
> > > >
> > > > <servlet-mapping>
> > > > <servlet-name>Controller</servlet-name>
> > > > <url-pattern>/testdb1</url-pattern>
> > > > </servlet-mapping>
> > > > </web-app>
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to provide credentials to a web app from an external web app? rpfe@sapo.pt ASP .Net 1 02-09-2007 05:06 PM
convert java web app 2 .NET web app =?Utf-8?B?bml6YW0=?= ASP .Net 0 02-28-2006 04:46 AM
convert java web app 2 .NET web app =?Utf-8?B?bml6YW0=?= ASP .Net 0 02-28-2006 04:45 AM
403 Error Web App to Web App with Client Certificates Peter Sedman ASP .Net Security 18 11-18-2004 08:09 PM
How to secure one web app with another web app... Maras ASP .Net Security 0 06-17-2004 07:37 AM



Advertisments