Hey!
Can I make a suggestion about control structure.
I only briefly looked at this thread, so I may be way off base.
You authenticate, good. Client then asks for a service to be performed, good.
At that time you should know what JavaBean-Model he needs, right. So
while in the servlet, get an instance of the bean, okay. It's empty at this
point.
Fill it up, create a session object, and put the bean in the session-object,
forward()
to client a View-JSP. Get the session object while in the View-JSP and therefore
get the JavaBean. Now use the bean in the View-JSP.
Hopes this helps.
Also, some things about JRun, I too am forced to use it, against my preferences.
Given:
WEB-INF/com/yourcompany/yourapp/MyClass
Like posted already by someone else:
<jsp:useBean id="myservice" class="com.yourcompany.yourapp.MyClass"
scope="session"/>
For JRun, always restart the server if you change this class.
Don't use the DEFAULTAPP, for how are you going to keep your apps organized.
Create an application, YOURAPP.
Method 2.
Once you have YOURAPP, now you can use the web.xml to your real advantage.
Let JRun create a web.xml for you that you can edit. Put web.xml-type of things
in
it. Just remember that if you use JRun's web interface to the web.xml it will
overwrite
your edited version.
Why? Because now you can do such things as getServlet().getInitParameter(),
powerful.
Also, you can now do this:
<jsp:useBean id="myservice" class="MyClass" scope="session"/>
Where, 'myservice' is the named you assigned in the web.xml to
com.yourcompany.yourapp.MyClass.
Sans adieu,
Danny Rubis
Mark Galbreath wrote:
> Tim,
>
> I'm doing everything you suggest below with the exception of having the
> classes in a package (JRUN is not finding them. For example, if I name the
> package "net.dirtroad," placing the class files in
> /WEB-INF/classes/net/dirtroad throws a ClassNotFoundException and Forte
> reports an "Invalid package name" error). I don't know what's up with this
> (I'm new to JRUN), so I just used the default package. Now this was working
> if I took the database field values and set them into session scope as
> attributes and then set the Bean properties from the JSP page using the
> session.getAttribute() values, but I cannot get the servlet to set the Bean
> properties and then read them from the JSP. Here's the program flow (and
> BTW, you are right on the general architecture):
>
> JSP logon >> Controller servlet >> Authenticate servlet (get values from
> database) >> JavaBean set >> Controller >> appropriate JSP based on
> accesslevel << JavaBean get.
>
> I tried to send the code, but the listserv reject anything over 300 lines.
> Below is just my Authenticate.java that attempts to set the Bean properties.
> I don't blame anyone for not wanting to look at my shitty code!
>
> public class Authenticate extends HttpServlet {
> public void init(ServletConfig config) throws ServletException {
> super.init(config);
> }
>
> protected void processRequest(HttpServletRequest req,
> HttpServletResponse res) throws ServletException, IOException {
> HttpSession session = req.getSession();
> if( session == null) {
> res.sendError( res.SC_PRECONDITION_FAILED, "Session has not been
> instantiated.");
> }
>
> Integer accessCount = new Integer( 0);
> if( !session.isNew()) {
> Integer oldAccessCount = (Integer) session.getAttribute(
> "accessCount");
> if( oldAccessCount != null) {
> accessCount = new Integer( oldAccessCount.intValue() + 1);
> }
> }
> session.setAttribute( "accessCount", accessCount);
>
> String parmUserid = req.getParameter( "userid");
> String parmPW = req.getParameter( "password");
>
> if( parmUserid.trim().length() > 0 && parmPW.trim().length() > 0) {
> UserBean userBean = new UserBean();
> Calendar ts = Calendar.getInstance();
> String time = ts.getTime().toString();
> String sql = "SELECT * FROM validation.dbo.gatekeeper";
> String dbURL = "jdbc:microsoft:sqlserver://CC615520-C:1433";
> String minit = null;
>
> try {
>
> Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
> Connection conn = DriverManager.getConnection(
> dbURL,"sa","rocket01");
> Statement stmt = conn.createStatement();
> ResultSet rs = stmt.executeQuery( sql);
>
> while( rs.next()) {
> String id = rs.getString( "email");
> String pw = rs.getString( "passwd");
>
> if( parmUserid.equalsIgnoreCase( id) &&
> parmPW.equalsIgnoreCase( pw)) {
> String fname = rs.getString( "fname");
> if( rs.getString( "minit") != null) { minit =
> rs.getString( "minit");}
> String lname = rs.getString( "lname");
> String accesslevel = rs.getString( "accesslevel");
> String lastaccess = rs.getString( "lastaccess");
>
> userBean.setUserID( id);
> userBean.setPassword( pw);
> userBean.setFname( fname);
> if( minit != null) {
> userBean.setMinit( minit);
> }
> userBean.setLname( lname);
> userBean.setAccessLevel( accesslevel);
> userBean.setLastAccess( lastaccess);
>
> String updateSQL = "UPDATE validation.dbo.gatekeeper
> SET lastaccess='" + time + "' WHERE email='" + parmUserid + "'";
> stmt.executeUpdate( updateSQL);
> conn.commit();
> conn.close();
> RequestDispatcher rd =
> getServletContext().getRequestDispatcher( "/servlet/Controller");
> if( rd != null) {
> rd.forward( req, res);
> } else {
> res.sendError( res.SC_NOT_FOUND, "The Controller
> is not available.");
> }
> }
> }
> } catch( ClassNotFoundException e) {
> e.printStackTrace();
> } catch( SQLException e) {
> e.printStackTrace();
> }
>
> RequestDispatcher rd =
> getServletContext().getRequestDispatcher( "/newUser.jsp?userid=" +
> parmUserid);
> if( rd != null) {
> rd.forward( req, res);
> } else {
> res.sendError( res.SC_NOT_FOUND, "The requested resource was
> not available.");
> }
>
> } else {
> int cnt = 0;
> try {
> cnt = Integer.parseInt( session.getAttribute(
> "accessCount").toString());
> } catch( NumberFormatException e) {
> e.printStackTrace();
> }
> if( cnt < 3) {
> RequestDispatcher rd =
> getServletContext().getRequestDispatcher( "/index.jsp?error=true");
> if( rd != null) {
> rd.forward( req, res);
> } else {
> res.sendError( res.SC_NOT_FOUND);
> }
> } else {
> session.invalidate();
> res.sendError( res.SC_UNAUTHORIZED, "You have exhausted your
> login attempts. Please contact the system administrator.");
> }
> }
> }
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html