本文整理汇总了Java中javax.servlet.http.HttpSession类的典型用法代码示例。如果您正苦于以下问题:Java HttpSession类的具体用法?Java HttpSession怎么用?Java HttpSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpSession类属于javax.servlet.http包,在下文中一共展示了HttpSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: restore
import javax.servlet.http.HttpSession; //导入依赖的package包/类
@RequestMapping("Admin/RestorePedido")
public void restore(HttpSession session, Long id, HttpServletResponse response) {
if(Permissoes.checar(session, EnumMetodo.RESTAURAR, entidade)){ // Consulta a permissão
dao.restore(id); // Ação no banco
relatorio.gerarRelatorio(session, EnumMetodo.RESTAURAR, entidade); // Gera Relatório e armazena no banco
response.setStatus(200); // Indica para a requisição AJAX que tudo ocorreu bem
}
}
示例2: adminAddRentHouseDeal
import javax.servlet.http.HttpSession; //导入依赖的package包/类
@RequestMapping(value="adminAddRentHouseDeal.do", method={RequestMethod.GET,RequestMethod.POST})
public ModelAndView adminAddRentHouseDeal(@RequestParam(value ="inputTime") @DateTimeFormat(pattern="yyyy-MM-dd") Date date,HttpServletRequest request, RentHouseDeal rentHouseDeal) {
ModelAndView modelAndView = new ModelAndView();
HttpSession session = request.getSession();
rentHouseDeal.setRentTime(date);
System.err.println("ctbb");
System.err.println(date);
System.err.println(rentHouseDeal.getRentHouseDay());
System.err.println(rentHouseDeal.getRentTime());
rentHouseDealDao.insertRentHouseDeal(rentHouseDeal);
List<RentHouseDeal> rentHouseDealList = rentHouseDealDao.selectAll();
session.setAttribute("rentHouseDealList", rentHouseDealList);
modelAndView.setViewName("SystemUser/managerRentHistory");
return modelAndView;
}
示例3: doPost
import javax.servlet.http.HttpSession; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//Instância serviço de servidor para efetuar consulta e ligação com ClienteDAO
ServicoProduto sp = new ServicoProduto();
//Criação se sessão para retorno em tela
HttpSession sessao = request.getSession();
//Atribuição de valores digitados na tela de fornecedor e código da empresa
String codigoproduto = request.getParameter("codigoproduto");
String codigoempresa = (String) sessao.getAttribute("Empresa");
try {
sp.excluirProduto(Integer.parseInt(codigoproduto), Integer.parseInt(codigoempresa));
} catch (Exception e) {
}
sessao.setAttribute("produtoexcluido", codigoproduto);
response.sendRedirect(request.getContextPath() + "/consultarProduto.jsp");
}
示例4: deleteLearnerFile
import javax.servlet.http.HttpSession; //导入依赖的package包/类
public ActionForward deleteLearnerFile(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpSession ss = SessionManager.getSession();
UserDTO currentUser = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER);
Long detailID = WebUtil.readLongParam(request, "detailId");
if (submitFilesService == null) {
submitFilesService = getSubmitFilesService();
}
FileDetailsDTO fileDetail = submitFilesService.getFileDetails(detailID, request.getLocale());
if (fileDetail.getOwner().getUserID().equals(currentUser.getUserID()) && (StringUtils.isBlank(fileDetail.getMarks()))) {
submitFilesService.removeLearnerFile(detailID,null);
} else {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "You are not allowed to delete this item");
}
return null;
}
示例5: getSession
import javax.servlet.http.HttpSession; //导入依赖的package包/类
public Session getSession(SessionKey key) throws SessionException {
/*
if (!WebUtils.isHttp(key)) {
String msg = "SessionKey must be an HTTP compatible implementation.";
throw new IllegalArgumentException(msg);
}
*/
HttpServletRequest request = key.getServletRequest();
Session session = null;
HttpSession httpSession = request.getSession(false);
if (httpSession != null) {
session = createSession(httpSession, request.getRemoteHost());
}
return session;
}
示例6: doFilter
import javax.servlet.http.HttpSession; //导入依赖的package包/类
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession(false);
String redirecionamento = request.getContextPath() + "/login.xhtml";
if (session == null || session.getAttribute("usuario") == null) {
response.sendRedirect(redirecionamento);
} else {
Usuario usuario = (Usuario) session.getAttribute("usuario");
if(!usuario.getAdmin()) {
response.sendRedirect(redirecionamento);
} else {
chain.doFilter(request, response);
}
}
}
示例7: testAddEventWithWebAuthenticationDetails
import javax.servlet.http.HttpSession; //导入依赖的package包/类
@Test
public void testAddEventWithWebAuthenticationDetails() {
HttpSession session = new MockHttpSession(null, "test-session-id");
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSession(session);
request.setRemoteAddr("1.2.3.4");
WebAuthenticationDetails details = new WebAuthenticationDetails(request);
Map<String, Object> data = new HashMap<>();
data.put("test-key", details);
AuditEvent event = new AuditEvent("test-user", "test-type", data);
customAuditEventRepository.add(event);
List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
assertThat(persistentAuditEvents).hasSize(1);
PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4");
assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id");
}
开发者ID:asanzdiego,项目名称:codemotion-2017-taller-de-jhipster,代码行数:18,代码来源:CustomAuditEventRepositoryIntTest.java
示例8: newReflection
import javax.servlet.http.HttpSession; //导入依赖的package包/类
/**
* Display empty reflection form.
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward newReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
initKalturaService();
// get session value
String sessionMapID = WebUtil.readStrParam(request, KalturaConstants.ATTR_SESSION_MAP_ID);
ReflectionForm refForm = (ReflectionForm) form;
HttpSession ss = SessionManager.getSession();
UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
refForm.setUserID(user.getUserID());
refForm.setSessionMapID(sessionMapID);
SessionMap<String, Object> map = (SessionMap<String, Object>) request.getSession().getAttribute(sessionMapID);
Long toolSessionID = (Long) map.get(AttributeNames.PARAM_TOOL_SESSION_ID);
NotebookEntry entry = service.getEntry(toolSessionID, user.getUserID());
if (entry != null) {
refForm.setEntryText(entry.getEntry());
}
return mapping.findForward(KalturaConstants.NOTEBOOK);
}
示例9: adminAddRentHouse
import javax.servlet.http.HttpSession; //导入依赖的package包/类
@RequestMapping(value="adminAddRentHouse.do", method={RequestMethod.GET,RequestMethod.POST})
public ModelAndView adminAddRentHouse(@RequestParam(value ="inputPublishTime1") @DateTimeFormat(pattern="yyyy-MM-dd") Date inputPublishTime,HttpServletRequest request, RentHouse rentHouse) {
ModelAndView modelAndView = new ModelAndView();
HttpSession session = request.getSession();
//设置表单时间
rentHouse.setRentHousePublishTime(inputPublishTime);
System.err.println(inputPublishTime);
rentHouseDao.insertRentHouse(rentHouse);
List<RentHouse> rentHouseList = rentHouseDao.selectAllRentHouse();
session.setAttribute("rentHouseList", rentHouseList);
modelAndView.setViewName("SystemUser/managerRent");
return modelAndView;
}
示例10: preHandle
import javax.servlet.http.HttpSession; //导入依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
HttpSession session = request.getSession();
if (!"".equals(session.getAttribute(Constant.USERNAME))&& session.getAttribute(Constant.USERNAME)!=null && !"".equals(session.getAttribute(Constant.TOKEN)) && session.getAttribute(Constant.TOKEN)!=null ) {
return true;
} else {
PrintWriter out;
out = response.getWriter();
String json;
Gson gson = new Gson();
Message<String> message = new Message<String>("-200","管理员未登录,请重新登录","");//初始化message对象
json = gson.toJson(message, Message.class); //使用gson将Message对象转化为字符串
out.print(json);
return false;
}
}
示例11: doFilter
import javax.servlet.http.HttpSession; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpSession session = request.getSession(true);
Long lastActiveObject = (Long) session.getAttribute(LAST_ACTIVE_SESSION_ATTRIBUTE);
long currentTime = System.currentTimeMillis();
if(lastActiveObject != null) {
long lastActive = lastActiveObject.longValue();
if(currentTime - lastActive > SESSION_TIMEOUT) {
LOG.info(String.format("Invalidated session of %s due to timeout", LogUtil.getUserInfo(request)));
session.invalidate();
session = request.getSession(true);
}
}
session.setAttribute(LAST_ACTIVE_SESSION_ATTRIBUTE, Long.valueOf(currentTime));
filterChain.doFilter(request, servletResponse);
}
示例12: updateCategoryInfo
import javax.servlet.http.HttpSession; //导入依赖的package包/类
/**
* 更新类品接口
* @param session
* @param categoryName
* @param categoryId
* @return
*/
@RequestMapping(value = "updateCategoryInfo.do",method = RequestMethod.POST)
@ResponseBody
public ServerResponse updateCategoryInfo(HttpSession session,String categoryName,Integer categoryId){
User user = (User) session.getAttribute(Const.CURRENT_USER);
if (user == null){
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"请先登录");
}
//判断这个用户是不是管理员
ServerResponse<String> checkRoleResult = iUserService.checkUserRole(user);
if (checkRoleResult.isSuccess()){
//添加类品
return iCategoryService.updateCategoryInfo(categoryName, categoryId);
} else {
return ServerResponse.createByError("对不起,您没有管理员权限");
}
}
示例13: getAsProgress
import javax.servlet.http.HttpSession; //导入依赖的package包/类
public ChartVo getAsProgress(HttpSession session) {
String sql = "SELECT " +
"sum(CASE R.success WHEN 0 THEN 1 ELSE 0 END) failure, " +
"sum(CASE R.success WHEN 1 THEN 1 ELSE 0 END) success, " +
"sum(CASE R.success WHEN 2 THEN 1 ELSE 0 END) killed, " +
"sum(CASE R.jobType WHEN 0 THEN 1 ELSE 0 END) singleton, " +
"sum(CASE R.jobType WHEN 1 THEN 1 ELSE 0 END) flow, " +
"sum(CASE J.cronType WHEN 0 THEN 1 ELSE 0 END) crontab, " +
"sum(CASE J.cronType WHEN 1 THEN 1 ELSE 0 END) quartz, " +
"sum(CASE R.execType WHEN 0 THEN 1 ELSE 0 END) auto, " +
"sum(CASE R.execType WHEN 1 THEN 1 ELSE 0 END) operator, " +
"sum(CASE R.redoCount>0 WHEN 1 THEN 1 ELSE 0 END) rerun " +
"FROM T_RECORD R LEFT JOIN T_JOB J ON R.jobid=J.jobid WHERE 1=1 ";
if (!OpencronTools.isPermission(session)) {
User user = OpencronTools.getUser(session);
sql += " AND R.userId = " + user.getUserId() + " AND R.agentId in (" + user.getAgentIds() + ")";
}
return queryDao.sqlUniqueQuery(ChartVo.class, sql);
}
示例14: loginExecute
import javax.servlet.http.HttpSession; //导入依赖的package包/类
/**
* 3.管理员登录执行
*
* @return index/index_content.jsp
*/
@RequestMapping(value = "admin-index-login-execute", method = RequestMethod.POST)
public String loginExecute(Map<String, Object> requestMap, HttpSession session,
@RequestParam("name") String name, @RequestParam("password") String password) {
int loginSuccess = adminService.login(name, password);
String view = "redirect:/admin-index-index-show";
if (loginSuccess == 1) { //登录成功
Admin admin = adminService.getAdminByName(name);
requestMap.put("admin", admin);
session.setAttribute("admin", admin);
} else { //登录失败
requestMap.put("adminLoginError", "1");
view = "index/index_login";
}
return view;
}
示例15: testGetSessionWithBadCookie
import javax.servlet.http.HttpSession; //导入依赖的package包/类
/**
* Verifies that a request with a bad session ID causes a new session to be generated only when explicitly requested.
*/
public void testGetSessionWithBadCookie() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
ServletUnitContext context = new ServletUnitContext();
ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );
HttpSession originalSession = context.newSession();
String originalID = originalSession.getId();
request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, originalID ) );
request.getSession();
String badID = originalID + "BAD";
request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );
request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, badID ) );
assertNull( "Unexpected session returned for bad cookie", request.getSession( false ) );
assertNotNull( "Should have returned session when asked", request.getSession( true ));
assertNotSame( "Created session", originalSession, request.getSession( true ) );
}