本文整理汇总了Java中javax.servlet.http.HttpSession.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java HttpSession.getAttribute方法的具体用法?Java HttpSession.getAttribute怎么用?Java HttpSession.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpSession
的用法示例。
在下文中一共展示了HttpSession.getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCurrentUser
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
private AssessmentUser getCurrentUser(Long sessionId) {
IAssessmentService service = getAssessmentService();
// try to get form system session
HttpSession ss = SessionManager.getSession();
// get back login user DTO
UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
AssessmentUser assessmentUser = service.getUserByIDAndSession(new Long(user.getUserID().intValue()), sessionId);
if (assessmentUser == null) {
AssessmentSession session = service.getAssessmentSessionBySessionId(sessionId);
assessmentUser = new AssessmentUser(user, session);
service.createUser(assessmentUser);
}
return assessmentUser;
}
示例2: viewProfile
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@GetMapping("/viewProfile")
public ModelAndView viewProfile(HttpSession session, Model model) {
log.info("Inside viewProfile method of Registration Controller.");
Employee employee = (Employee) session.getAttribute("user");
//Check if the employee object exist in the session.
if (employee == null) {
log.error("Cannot find employee object in the session, so forwarding to Login page");
model.addAttribute("css", "danger");
model.addAttribute("msg", "Your session expired, please login to continue!!");
return new ModelAndView("redirect:/login");
}
model.addAttribute("employee", employee);
if (employee.isEmployeeRole()) {
return new ModelAndView("employee/viewProfile");
} else if (employee.isSupervisorRole()) {
return new ModelAndView("staff/viewProfileStaff");
} else if (employee.isAdminRole()) {
return new ModelAndView("staff/viewProfileStaff");
} else {
log.error("Cannot validate the role. Redirecting to the Login page.");
model.addAttribute("css", "danger");
model.addAttribute("msg", "Cannot validate the role, please login to continue!!");
return new ModelAndView("redirect:/login");
}
}
示例3: home
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
/**
* 教育官网首页
*/
@GetMapping("/home")
public String home(Model model, HttpServletRequest request, HttpSession session) {
Integer newpv = (Integer) session.getAttribute("is_new");
if (newpv == null) {
try {
TzPv pv = new TzPv();
pv.setUserip(Utils.getIpAddress(request));
pv.setUseragent(request.getHeader("User-Agent"));
pv.setVisittime(new Timestamp(System.currentTimeMillis()));
pv.setModule(2);
this.tzPvService.insert(pv);
} catch (Exception ex) {
ex.printStackTrace();
}
session.setAttribute("is_new", 1);
}
model.addAttribute("type", 1);
return "edu_index";
}
示例4: save
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
/**
* 最后一步,保存数据
*
* @param session
* @return
*/
@ResponseBody
@RequestMapping(value="/classes",method =RequestMethod.POST)
public Map<String, Object> save(HttpSession session) {
List<BaseClass> list = (List<BaseClass>) session.getAttribute(SessionKey.FETCH_MAJOR_BASECLASS_DATA_LIST.toString());
int addCount = 0;
int existCount = 0;
// 写入数据库
for (BaseClass bc : list) {
try {
baseClassService.addBaseClass(bc);
addCount++;
} catch (ObjectExistsException e) {
existCount++;
}
}
Map<String, Integer> result = new HashMap<String, Integer>();
result.put("addCount", addCount);
result.put("existCount", existCount);
return WebUtils.webJsonResult(result);
}
示例5: filter
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
final HttpSession session = httpServletRequest.getSession(false);
if (null == session || null == session.getAttribute(attributeName)) {
requestContext.abortWith(Response.seeOther(URI.create("/")).build());
}
}
示例6: arrangement
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@ResponseBody
@RequestMapping("/arrangement")
public CommonResult arrangement(MultipartFile multipartFile, Homework homework, HttpSession session) {
if (multipartFile == null)
return new CommonResult("文件为空", false);
else if (homework.getCourseClassId() == null)
return new CommonResult("班级为空", false);
else if (!FileFormatUtils.isPackage(multipartFile.getOriginalFilename()))
return new CommonResult("文件格式不是压缩包", false);
else if (multipartFile.getSize() > FILE_SIZE)
return new CommonResult("文件大小超出限制", false);
else if (StringUtils.isEmpty(homework.getHomeworkName(), homework.getContent()))
return new CommonResult("作业名称或正文不能为空", false);
else {
if (homework.getHomeworkName().length() > TITLE_SIZE) {
if (homework.getContent().length() > CONTENT_SIZE)
return new CommonResult("作业名称和正文太长", false);
else
return new CommonResult("作业名称太长", false);
} else if (homework.getContent().length() > CONTENT_SIZE)
return new CommonResult("正文太长", false);
}
User user = (User)session.getAttribute("user");
homework.setAnnouncerId(user.getId());
if (homeworkService.arrangement(homework, multipartFile)) {
return new CommonResult("成功", true);
} else
return new CommonResult("添加作业失败", false);
}
示例7: doPost
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HotelService service = new HotelService();
HotelDAO dao = new HotelDAO();
RelatorioDAO relatorioDAO = new RelatorioDAO();
RelatorioMudancas relatorio = new RelatorioMudancas();
String nome_hotel = request.getParameter("nome_hotel");
String data_entrada = request.getParameter("data_entrada");
String data_saida = request.getParameter("data_saida");
int quantidade_quartos = Integer.parseInt(request.getParameter("quantidade_quartos"));
int quantidade_hospedes = Integer.parseInt(request.getParameter("quantidade_hospedes"));
float preco = Float.parseFloat(request.getParameter("preco"));
request.setAttribute("erroNome_hotel", service.validaNome(nome_hotel));
request.setAttribute("erroData_entrada", service.validaEntrada(data_entrada));
request.setAttribute("erroData_saida", service.validaSaida(data_saida));
request.setAttribute("erroQuantidade_quartos", service.validaQuantidade_quartos(quantidade_quartos));
request.setAttribute("erroQuantidade_hospedes", service.validaQuantidade_hospedes(quantidade_hospedes));
request.setAttribute("erroPreco", service.validaPreco(preco));
Hotel hotel = new Hotel(nome_hotel.trim(), data_entrada.trim(), data_saida.trim(),
quantidade_quartos, quantidade_hospedes, preco, true);
if (service.validaHotel(nome_hotel, quantidade_quartos, data_entrada, data_saida, quantidade_hospedes, preco)) {
RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/CadastroHotel.jsp");
dispatcher.forward(request, response);
} else {
try {
dao.inserir(hotel);
HttpSession sessao = request.getSession();
int identificacaoF = (int) sessao.getAttribute("id_func");
relatorio.setId_func(identificacaoF);
relatorio.setMudanca("Cadastro de hotel efetuado!");
relatorioDAO.inserir(relatorio);
response.sendRedirect(request.getContextPath() + "/inicio");
} catch (Exception ex) {
Logger.getLogger(CadastroHotelServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
示例8: sessionCheck
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
/**
* 检测Session对象是否有效
*
* @param request
* @return
*/
public static boolean sessionCheck(HttpSession session) {
if (session.getAttribute(Const.SESSION_USER) == null) {
return false;
}
return true;
}
示例9: load
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
public void load(HttpSession session) {
iMinRoomSize = (String)session.getAttribute("RoomList.MinRoomSize");
iMaxRoomSize = (String)session.getAttribute("RoomList.MaxRoomSize");
iFilter = (String)session.getAttribute("RoomList.Filter");
iRoomTypes = (Long[]) session.getAttribute("RoomList.RoomTypes");
iRoomGroups = (Long[]) session.getAttribute("RoomList.RoomGroups");
iRoomFeatures = (Long[]) session.getAttribute("RoomList.RoomFeatures");
}
示例10: selectAll
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@RequestMapping("select_all.do")
public ServerResponse<CartVo> selectAll(HttpSession session) {
User user = (User) session.getAttribute(Const.CURRENT_USER);
if (user == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), ResponseCode.NEED_LOGIN.getDesc());
}
return iCartService.selectOrUnSelect(user.getId(), null, Const.Cart.CHECKED);
}
示例11: setAttributeInternal
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
private void setAttributeInternal(HttpSession session, String key, Object attribute)
{
final String realKey = getKey(key);
SerialisedValue<?> oldValue = (SerialisedValue<?>) session.getAttribute(realKey);
SerialisedValue<?> newValue = new SerialisedValue<Object>(attribute);
if( oldValue == null || !Arrays.equals(oldValue.getData(), newValue.getData()) )
{
session.setAttribute(realKey, newValue);
}
}
示例12: doFilter
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpSession session = ((HttpServletRequest) request).getSession();
if (session.getAttribute("user") == null) {
session.setAttribute("error",
"You have been logged out due to inactivity or invalid authentication. Please login again.");
((HttpServletResponse) response).sendRedirect("candidate-login.jsp");
} else {
chain.doFilter(request, response);
}
}
示例13: summary
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
private ActionForward summary(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
initializeScratchieService();
// initialize Session Map
SessionMap<String, Object> sessionMap = new SessionMap<String, Object>();
request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap);
request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID());
Long contentId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID);
List<GroupSummary> summaryList = service.getMonitoringSummary(contentId, true);
Scratchie scratchie = service.getScratchieByContentId(contentId);
Set<ScratchieUser> learners = service.getAllLeaders(contentId);
//set SubmissionDeadline, if any
if (scratchie.getSubmissionDeadline() != null) {
Date submissionDeadline = scratchie.getSubmissionDeadline();
HttpSession ss = SessionManager.getSession();
UserDTO teacher = (UserDTO) ss.getAttribute(AttributeNames.USER);
TimeZone teacherTimeZone = teacher.getTimeZone();
Date tzSubmissionDeadline = DateUtil.convertToTimeZoneFromDefault(teacherTimeZone, submissionDeadline);
request.setAttribute(ScratchieConstants.ATTR_SUBMISSION_DEADLINE, tzSubmissionDeadline.getTime());
request.setAttribute(ScratchieConstants.ATTR_SUBMISSION_DEADLINE_DATESTRING, DateUtil.convertToStringForJSON(submissionDeadline, request.getLocale()));
}
// cache into sessionMap
boolean isGroupedActivity = service.isGroupedActivity(contentId);
sessionMap.put(ScratchieConstants.ATTR_IS_GROUPED_ACTIVITY, isGroupedActivity);
sessionMap.put(ScratchieConstants.ATTR_SUMMARY_LIST, summaryList);
sessionMap.put(ScratchieConstants.ATTR_SCRATCHIE, scratchie);
sessionMap.put(ScratchieConstants.ATTR_LEARNERS, learners);
sessionMap.put(ScratchieConstants.ATTR_TOOL_CONTENT_ID, contentId);
sessionMap.put(AttributeNames.PARAM_CONTENT_FOLDER_ID,
WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID));
sessionMap.put(ScratchieConstants.ATTR_REFLECTION_ON, scratchie.isReflectOnActivity());
// Create BurningQuestionsDtos if BurningQuestions is enabled.
if (scratchie.isBurningQuestionsEnabled()) {
List<BurningQuestionItemDTO> burningQuestionItemDtos = service.getBurningQuestionDtos(scratchie, null, true);
sessionMap.put(ScratchieConstants.ATTR_BURNING_QUESTION_ITEM_DTOS, burningQuestionItemDtos);
}
// Create reflectList if reflection is enabled.
if (scratchie.isReflectOnActivity()) {
List<ReflectDTO> reflections = service.getReflectionList(contentId);
sessionMap.put(ScratchieConstants.ATTR_REFLECTIONS, reflections);
}
return mapping.findForward(ScratchieConstants.SUCCESS);
}
示例14: getUserId
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
private Integer getUserId() {
// return new Integer(WebUtil.readIntParam(request,AttributeNames.PARAM_USER_ID));
HttpSession ss = SessionManager.getSession();
UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
return user != null ? user.getUserID() : null;
}
示例15: execute
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
public void execute(HttpSession session, @Param("pageIndex") int pageIndex, @Param("searchKey") String searchKey, Context context)
throws Exception {
@SuppressWarnings("unchecked")
Map<String, Object> condition = new HashMap<String, Object>();
if ("请输入关键字(目前支持Node的ID、名字搜索)".equals(searchKey)) {
searchKey = "";
}
condition.put("searchKey", searchKey);
//System.out.println("cannal列表:"+pageIndex+","+);
User userInfo = (User) session.getAttribute(WebConstant.USER_SESSION_KEY);
if(userInfo != null && userInfo.getAuthorizeType().isAdmin())//确定是否进行过滤
condition.put("userId", userInfo.getId());
int count = canalService.getCount(condition);
Paginator paginator = new Paginator();
paginator.setItems(count);
paginator.setPage(pageIndex);
condition.put("offset", paginator.getOffset());
condition.put("length", paginator.getLength());
List<Canal> canals = canalService.listByCondition(condition);
List<SeniorCanal> seniorCanals = new ArrayList<SeniorCanal>();
for (Canal canal : canals) {
SeniorCanal seniorCanal = new SeniorCanal();
seniorCanal.setId(canal.getId());
seniorCanal.setName(canal.getName());
seniorCanal.setStatus(canal.getStatus());
seniorCanal.setDesc(canal.getDesc());
seniorCanal.setCanalParameter(canal.getCanalParameter());
seniorCanal.setGmtCreate(canal.getGmtCreate());
seniorCanal.setGmtModified(canal.getGmtModified());
List<Pipeline> pipelines = pipelineService.listByDestinationWithoutOther(canal.getName());
seniorCanal.setPipelines(pipelines);
seniorCanal.setUsed(!pipelines.isEmpty());
seniorCanals.add(seniorCanal);
}
context.put("seniorCanals", seniorCanals);
context.put("paginator", paginator);
context.put("searchKey", searchKey);
}