Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6970277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:41:21+00:00 2026-05-27T16:41:21+00:00

I tend to have this statement STKUser authenticatedUser = (STKUser) request.getSession().getAttribute(STKUserSession); in every method

  • 0

I tend to have this statement

STKUser authenticatedUser = (STKUser) request.getSession().getAttribute("STKUserSession");

in every method of my Classes. authenticatedUser is used for authorization checks/ logic flow. Is this OK or should I be coding this class differently??? Also are there any recommended books that could help improve my coding for Java Classes like the one below, which are used in web applicatons? Most of my Classes looked like the one below.

public class TD0301AssignmentForm extends Form {
  private boolean notifyApprover = false;
  boolean employeeChange = false;

  public TD0301AssignmentForm(TD0301AssignmentDAO dao) {
    this.dao = dao;
  }


  private TD0301Assignment unlockAssignment(HttpServletRequest request) {
    STKUser authenticatedUser = (STKUser) request.getSession().getAttribute("STKUserSession");
    TD0301Assignment tdas = new TD0301Assignment();
    notifyApprover = true;
    boolean unlock = false;

    try {
        // get the original data
        tdas = dao.retreive(request.getParameter("calc_num"), request.getParameter("calc_rev"), request.getParameter("calc_dept"), authenticatedUser);

        if ("3".equals(tdas.getForm_approve_state()) && authenticatedUser.getBadge().equals(tdas.getOriginator())) {
            tdas.setForm_approve_state("1");
            notifyApprover = true;
            unlock = true;
        }

     }


public TD0301Assignment updateAssignment(HttpServletRequest request) {
    STKUser authenticatedUser = (STKUser) request.getSession().getAttribute("STKUserSession");
    .... 
    if (authenticatedUser.getBadge().equals(tdas.getOriginator())) {
        //do something
}

EDIT

The TD0301AssignmentForm Class is accessed using these two Classes.

Servlet

TD0301AssignmentDAO dao = new TD0301AssignmentDAO();
TD0301AssignmentForm form = new TD0301AssignmentForm(dao);
TD0301Assignment obj = new TD0301Assignment();

String pkString = "calc_num=" + request.getParameter("calc_num") + "&calc_rev=" + request.getParameter("calc_rev") + "&calc_dept="
        + request.getParameter("calc_dept");

modelMap.put("dbTable", dbTable);
modelMap.put("action", request.getRequestURL());
modelMap.put("reportTitle", "CommitmentReport");

// I think this is the Application Controller Strategy
actionMap.put(null, new ListAction(modelMap, form, "WEB-INF/views/genericList_v.jsp", "WEB-INF/views/genericList_v.jsp"));
actionMap.put("list", new ListAction(modelMap, form, "WEB-INF/views/genericList_v.jsp", "WEB-INF/views/genericList_v.jsp"));
actionMap.put("view", new ViewAction(modelMap, form, obj, "WEB-INF/views/genericView_v.jsp", "WEB-INF/views/genericView_v.jsp"));
actionMap.put("delete", new DeleteAction(modelMap, form, obj, "WEB-INF/views/genericDeleteConfirm_v.jsp", "WEB-INF/views/genericView_v.jsp"));
actionMap.put("sqlConfirmDelete", new DeleteConfirmAction(form, request.getRequestURL() + "?message=Deletion was successful!", request.getRequestURL()
        + "?method=view&" + pkString));
actionMap.put("edit", new EditAction(modelMap, form, obj, "WEB-INF/views/genericEdit_v.jsp", "WEB-INF/views/genericView_v.jsp"));
actionMap.put("sqlUpdate", new UpdateAction(modelMap, form, obj, request.getRequestURL() + "?message=Update was successful!", "WEB-INF/views/genericEdit_v.jsp"));
actionMap.put("new", new NewAction(modelMap, form, "WEB-INF/views/genericAdd_v.jsp"));
actionMap.put("sqlInsert", new InsertAction(modelMap, form, obj, request.getRequestURL() + "?message=Insert was successful!", "WEB-INF/views/genericAdd_v.jsp"));

String op = request.getParameter("method");
ControllerAction action = (ControllerAction) actionMap.get(op);

if (action != null) {
    action.service(request, response);
} else {
    String url = "WEB-INF/views/errorMessage_v.jsp";
    String errMessage = "Operation '" + op + "' not a valid for in '" + request.getServletPath() + "' !!";
    request.setAttribute("message", errMessage);
    request.getRequestDispatcher(url).forward(request, response);
}

public class EditAction implements ControllerAction {

private Form form;
private Object obj;
private String xPage;
private String yPage;
private HashMap modelMap;

public EditAction(HashMap modelMap, Form form, Object obj, String yPage, String xPage) {
    this.form = form;
    this.obj = obj;
    this.xPage = xPage;
    this.yPage = yPage;
    this.modelMap = modelMap;
}

public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    obj = form.edit(request);

    Iterator it = modelMap.entrySet().iterator(); 
    while (it.hasNext()) { 
        Map.Entry pairs = (Map.Entry)it.next(); 
        request.setAttribute(pairs.getKey().toString(), pairs.getValue());       
    }

    request.setAttribute("obj", obj);
    request.setAttribute("form", form);

    if (form.isSucces()) {
        RequestDispatcher view = request.getRequestDispatcher(yPage);
        view.forward(request, response);
    }
    else {
        RequestDispatcher view = request.getRequestDispatcher(xPage);
        view.forward(request, response);
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:41:22+00:00Added an answer on May 27, 2026 at 4:41 pm

    If you find yourself retrieving the same value all the time, you’d probably at least want to abstract it into a method in a base class:

    public class BaseForm extends WhateverYouHave {
        public STKUser getUser(HttpServletRequest request) {
            return request.getSession().getAttribute("STKUserSession");
        }
        ...
    }
    
    ...
    
    public class AnotherServlet extends BaseForm {
        public TD0301Assignment updateAssignment(HttpServletRequest request) {
            if (getUser(request).equals(tdas.getOriginator())) {
            ...
    

    Another, potentially cleaner option depending on your dispatch/instantiation/etc. mechanism would be to inject the value into your forms (if they’re not singletons, unclear):

    public class AnotherServlet extends BaseForm {
        public AnotherServlet(STKUser user) {
            this.user = user;
            ...
        }
    
        public TD0301Assignment updateAssignment(HttpServletRequest request) {
            if (user.equals(tdas.getOriginator())) {
            ...
    

    Or provide it as an argument to form methods (if they are):

    public TD0301Assignment updateAssignment(STKUser user, HttpServletRequest request) {
        if (user.equals(tdas.getOriginator())) {
            ...
    

    It’s unfortunate your forms are tied directly to the servlet spec; it’s more pleasant to do as much development as possible without that requirement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tend to have this redundant naming in case classes: abstract class MyTree case
It seems I tend to attract strange issues. This time, I have written a
I hear this term used quite frequently, but have yet to see it specified
I have heard that web-based chat clients tend to use networking frameworks such as
We have found that with our memcache some keys tend to be lost. To
I have noted over the years, that I tend to write maybe a screen
We mostly tend to following the above best practice. Have a look at String
I have this weird crash that only happens when running the app on the
If right after BEGIN I have SET TRANSACTION ISOLATION LEVEL ... statement, will the
I have a table with about 20 columns. 10 of them generally tend to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.