本文整理汇总了Java中javax.servlet.http.HttpServletRequest.getSession方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.getSession方法的具体用法?Java HttpServletRequest.getSession怎么用?Java HttpServletRequest.getSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.getSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDescription
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public String getDescription(boolean includeClientInfo) {
HttpServletRequest request = getRequest();
StringBuilder sb = new StringBuilder();
sb.append("uri=").append(request.getRequestURI());
if (includeClientInfo) {
String client = request.getRemoteAddr();
if (StringUtils.hasLength(client)) {
sb.append(";client=").append(client);
}
HttpSession session = request.getSession(false);
if (session != null) {
sb.append(";session=").append(session.getId());
}
String user = request.getRemoteUser();
if (StringUtils.hasLength(user)) {
sb.append(";user=").append(user);
}
}
return sb.toString();
}
示例2: getDelete
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@GetMapping("/delete/{id}")
public String getDelete(HttpServletRequest request, HttpServletResponse response, @PathVariable long id,
Model model) throws IOException {
HttpSession session = request.getSession(true);
Entry entry = getEntryDao().getEntry(id);
if(entry == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return null;
}
if(canEdit(session, entry)) {
model.addAttribute("entry", entry);
return "delete";
}
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return null;
}
示例3: doPost
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String n=request.getParameter("username");
String p=request.getParameter("userpass");
HttpSession session = request.getSession(false);
DB dbProperties = new DB(getServletContext().getInitParameter("dbHost"), getServletContext().getInitParameter("dbPort"), getServletContext().getInitParameter("dbName"), getServletContext().getInitParameter("dbUser"), getServletContext().getInitParameter("dbPassword"));
if(LoginDao.validate(n, p, request, dbProperties) != null){
session.setAttribute("LoggedUser", LoginDao.validate(n, p, request, dbProperties));
} else{
request.setAttribute("login_error", "<p style=\"color:red\">Sorry user name or password error</p>");
}
RequestDispatcher rd = getServletContext().getRequestDispatcher(request.getContextPath() + "/login.jsp");
rd.forward(request, response);
doGet(request, response);
}
示例4: doPost
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
String name = request.getParameter("name") != null ? request.getParameter("name").trim() : "",
viewLimit = request.getParameter("viewLimit") != null ? request.getParameter("viewLimit").trim() : "";
if (name.isEmpty() || viewLimit.isEmpty()) {
session.setAttribute("companyError", "Please enter a name and profile view limit");
} else {
Companies company = new Companies();
company.setName(name);
company.setViewLimit(Integer.parseInt(viewLimit));
company.setProfilesViewed(0);
company.setProfilesViewedThisMonth(0);
try {
company = CompanyDataAccessObject.persist(company);
List<Companies> companyList = CompanyDataAccessObject.getAll();
session.setAttribute("companyList", companyList);
} catch (Exception e) {
session.setAttribute("companyError", "An error occurred");
e.printStackTrace();
}
}
response.sendRedirect("admin/admin-company-list.jsp");
}
示例5: handleGenericException
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@ExceptionHandler({Exception.class})
public ModelAndView handleGenericException(Exception ex, HttpServletRequest request) {
//LOG HERE
ModelAndView model = new ModelAndView("error");
AppErrorInfo errorInfo = new AppErrorInfo();
HttpSession session = request.getSession(false);
errorInfo.setErrorCode("TIMESHEET.SERVER.ERROR");
errorInfo.setErrorDetails("");
errorInfo.setErrorMessage(messageSource.getMessage("internal.server.error",
new String[]{}, Locale.US));
errorInfo.setHttpStatusCode(500);
errorInfo.setSessionId(session.getId());
StringWriter sw = new StringWriter();
ex.printStackTrace(new PrintWriter(sw));
String s = sw.toString();
errorInfo.setStackTrace(s);
errorInfo.setTimeStamp(System.currentTimeMillis());
model.addObject("ecasErrorInfo", errorInfo);
return model;
}
示例6: authUser
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@RequestMapping(value="auth")
public void authUser(HttpServletRequest request,HttpServletResponse response,String email,String password) throws Exception{
User usercent=new User();
usercent.setEmail(email);
usercent.setPassword(MD5Utils.MD5(password));
User user=manageServiceImpl.valUserCenter(usercent);
if (null != user) {
LOG.info("login suc.");
user.setLoginTimes(user.getLoginTimes()+1);
user.setLastLoginIp(request.getRemoteAddr());
manageServiceImpl.reCordUserLogin(user);
HttpSession session = request.getSession();
session.setAttribute("curUser", user);
session.setAttribute("username", user.getUsername());
setCookie(response, "name", user.getUsername(),"/", COOKIE_TIME);
setCookie(response, "email", user.getEmail() + "","/", COOKIE_TIME);
response.getWriter().print("suc");
}else{
response.getWriter().print("false");
}
}
示例7: doSSOLogin
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public static void doSSOLogin(HttpServletRequest httpRequest) {
HttpSessionManager sessionManager =(HttpSessionManager) httpRequest.getAttribute(HttpSessionManager.class.getName());
String alias = httpRequest.getParameter("_s");
SessionRepository<Session> sessionRepository =
(SessionRepository<Session>) httpRequest.getAttribute(SessionRepository.class.getName());
for(Map.Entry<String, String> entry : sessionManager.getSessionIds(httpRequest).entrySet()) {
String aliasId = entry.getKey();
String sessionValue = entry.getValue();
Session session = sessionRepository.getSession(sessionValue);
HttpSession httpSession = httpRequest.getSession();
if(session != null && session.getAttribute("username") != null && httpSession.getAttribute("username") == null ) {
httpSession.setAttribute("username", session.getAttribute("username"));
}
log.info("[SSOLoginService] doSSOLogin aliasId {} : session value{}",aliasId,sessionValue);
}
if(StringUtils.isEmpty(alias)) {
alias = sessionManager.getNewSessionAlias(httpRequest);
}
httpRequest.setAttribute("alias",alias);
}
示例8: doUnlock
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* 解锁客户端
*/
@RequestMapping("doUnlockCheck")
@ResponseBody
private AjaxResult doUnlock(HttpServletRequest request, @RequestParam("password") String password) {
HttpSession session = request.getSession();
UserEntity member = (UserEntity) session.getAttribute(IConstants.RBAC_SESSION_MEMBER);
if (member.getPassword().equals(CommonUtils.MD5(password))) {
session.setAttribute(IConstants.RBAC_SESSION_LOCK, null);
return new AjaxResult();
}
return new AjaxResult(false, "密码错误!");
}
示例9: logout
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* Logs out the user and invalidates the session
* @return
* the method always returns SUCCESS or throws an error if logout fails.
* @throws ServletException
*/
public String logout() throws ServletException {
final HttpServletRequest request = ServletActionContext.getRequest();
final HttpSession session = request.getSession();
//perform container login
request.logout();
session.invalidate();
return SUCCESS;
}
示例10: getServiceResult
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
HttpSession session = request.getSession();
CheStudio cheStudio = CallAction.getStudio(session);
if (cheStudio != null) {
SourcePickerViewWrap spv = cheStudio.getSourcePickerView();
if (spv != null) {
String xpath = request.getParameter("xpath").trim();
spv.modifyXpathText(xpath);
}
}
}
示例11: service
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
HttpSession session = req.getSession();
session.invalidate();
session = req.getSession();
session.invalidate();
req.getSession();
}
示例12: processRequest
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
HttpSession session = request.getSession();
String modul = request.getParameter("modul");
session.setAttribute("modul", modul);
RequestDispatcher rd = request.getRequestDispatcher("JSP/ModulLevering.jsp");
rd.include(request, response);
}
示例13: doGet
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
int clientID = Integer.parseInt(request.getParameter("clientID"));
Clients client = ClientPersistence.getByID(clientID);
session.setAttribute("client", client);
response.sendRedirect("admin/admin-client-logs.jsp");
}
示例14: doGet
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
HttpSession s = req.getSession(true);
s.getId();
res.getWriter().write("Hello world");
}
示例15: doLogout
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String doLogout(HttpServletRequest request) {
HttpSession session = request.getSession();
session.invalidate();
return "index";
}