本文整理匯總了Java中javax.servlet.http.HttpServletRequest.setAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletRequest.setAttribute方法的具體用法?Java HttpServletRequest.setAttribute怎麽用?Java HttpServletRequest.setAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.setAttribute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: unspecified
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException {
if (!getSecurityService().isSysadmin(getUserID(), "display cleanup preview lessons", false)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a sysadmin");
return null;
}
if (!(request.isUserInRole(Role.SYSADMIN))) {
request.setAttribute("errorName", "CleanupPreviewLessonsAction");
request.setAttribute("errorMessage", AdminServiceProxy.getMessageService(getServlet().getServletContext())
.getMessage("error.need.sysadmin"));
return mapping.findForward("error");
}
long[] lessonCount = getLessonService().getPreviewLessonCount();
request.setAttribute("previewCount", lessonCount[0]);
request.setAttribute("allLessonCount", lessonCount[1]);
return mapping.findForward("cleanup");
}
示例2: newInstruction
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Ajax call, will add one more input line for new survey item instruction.
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
private ActionForward newInstruction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
int count = NumberUtils.stringToInt(request.getParameter(AuthoringAction.INSTRUCTION_ITEM_COUNT), 0);
List instructionList = new ArrayList(++count);
for (int idx = 0; idx < count; idx++) {
String item = request.getParameter(AuthoringAction.INSTRUCTION_ITEM_DESC_PREFIX + idx);
if (item == null) {
instructionList.add("");
} else {
instructionList.add(item);
}
}
request.setAttribute(SurveyConstants.ATTR_INSTRUCTION_LIST, instructionList);
return mapping.findForward(SurveyConstants.SUCCESS);
}
示例3: editArticle
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@GetMapping(value = "/{cid}")
public String editArticle(@PathVariable String cid, HttpServletRequest request) {
ContentVo contents = contentsService.getContents(cid);
request.setAttribute("contents", contents);
List<MetaVo> categories = metasService.getMetas(Types.CATEGORY.getType());
request.setAttribute("categories", categories);
request.setAttribute("active", "article");
return "admin/article_edit";
}
示例4: execute
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException, JSONException, DokumaranConfigurationException, URISyntaxException {
String param = mapping.getParameter();
request.setAttribute("initialTabId", WebUtil.readLongParam(request, AttributeNames.PARAM_CURRENT_TAB, true));
if (param.equals("summary")) {
return summary(mapping, form, request, response);
} else if (param.equals("fixFaultySession")) {
return fixFaultySession(mapping, form, request, response);
} else if (param.equals("launchTimeLimit")) {
return launchTimeLimit(mapping, form, request, response);
} else if (param.equals("addOneMinute")) {
return addOneMinute(mapping, form, request, response);
}
return mapping.findForward(DokumaranConstants.ERROR);
}
示例5: checkforCookie
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Checks if specific cookies exist and save their value as message.
*
* @param request
* @param response
*/
protected void checkforCookie(HttpServletRequest request, HttpServletResponse response) {
if (request.getCookies() != null) {
for (Cookie cook : request.getCookies()) {
if (cook.getName().equals(MESSAGECOOKIE)) {
request.setAttribute("message", cook.getValue().replaceAll("_", " "));
cook.setMaxAge(0);
response.addCookie(cook);
} else if (cook.getName().equals(PRODUCTCOOKIE)) {
request.setAttribute("numberProducts", cook.getValue());
} else if (cook.getName().equals(ERRORMESSAGECOOKIE)) {
request.setAttribute("errormessage", cook.getValue().replaceAll("_", " "));
cook.setMaxAge(0);
response.addCookie(cook);
}
}
}
}
示例6: showModifyLessonPage
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private void showModifyLessonPage(HttpServletRequest request, HttpServletResponse response, Context ctx)
throws InitializationException, BbServiceException, PersistenceException, IOException, ServletException {
// retrive the LAMS lesson
BbPersistenceManager bbPm = PersistenceServiceFactory.getInstance().getDbPersistenceManager();
Container bbContainer = bbPm.getContainer();
Id contentId = new PkId(bbContainer, CourseDocument.DATA_TYPE, request.getParameter("content_id"));
ContentDbLoader courseDocumentLoader = (ContentDbLoader) bbPm.getLoader(ContentDbLoader.TYPE);
Content bbContent = (Content) courseDocumentLoader.loadById(contentId);
// get LAMS lessons's properties
Calendar startDate = bbContent.getStartDate();
Calendar endDate = bbContent.getEndDate();
FormattedText description = bbContent.getBody();
request.setAttribute("bbContent", bbContent);
request.setAttribute("startDate", startDate);
request.setAttribute("endDate", endDate);
request.setAttribute("description", description);
request.getRequestDispatcher("/modules/modify.jsp").forward(request, response);
}
示例7: viewReflection
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private ActionForward viewReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
Long uid = WebUtil.readLongParam(request, ResourceConstants.ATTR_USER_UID);
Long sessionID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID);
IResourceService service = getResourceService();
ResourceUser user = service.getUser(uid);
NotebookEntry notebookEntry = service.getEntry(sessionID, CoreNotebookConstants.NOTEBOOK_TOOL,
ResourceConstants.TOOL_SIGNATURE, user.getUserId().intValue());
ResourceSession session = service.getResourceSessionBySessionId(sessionID);
ReflectDTO refDTO = new ReflectDTO(user);
if (notebookEntry == null) {
refDTO.setFinishReflection(false);
refDTO.setReflect(null);
} else {
refDTO.setFinishReflection(true);
refDTO.setReflect(notebookEntry.getEntry());
}
refDTO.setReflectInstrctions(session.getResource().getReflectInstructions());
request.setAttribute("userDTO", refDTO);
return mapping.findForward("success");
}
示例8: quartz
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping(value = ACTION_LIST)
public String quartz(HttpServletRequest request,
HttpServletResponse response) {
try {
Iterator<?> it = request.getParameterMap().entrySet().iterator();
QuartzSchedule entity = new QuartzSchedule();
while (it.hasNext()) {
Map.Entry<?, ?> ent = (Entry<?, ?>) it.next();
entity.setValue((String) ent.getKey(),
((String[]) ent.getValue())[0]);
}
request.setAttribute("group", entity.getGroup());
request.setAttribute("title", entity.getName());
Map<?, ?> map = (Map<?, ?>) service.iQuartzScheduleService
.selectByWhere(entity);
List<?> list = service.iQuartzGroupService
.selectByWhere(new QuartzGroup());
request.setAttribute(LIST, list);
request.setAttribute(ENTITY, map);
} catch (SchedulerException e) {
e.printStackTrace();
}
return VIEW_WIDGET + VIEW_QUARTZ + PAGE_LIST;
}
示例9: importInit
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Initializes import questions page.
*/
private ActionForward importInit(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws ServletException {
String sessionMapID = WebUtil.readStrParam(request, AssessmentConstants.ATTR_SESSION_MAP_ID);
request.setAttribute(AssessmentConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return mapping.findForward(AssessmentConstants.SUCCESS);
}
示例10: view
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping(value = ACTION_VIEW, method = RequestMethod.GET)
public String view(HttpServletRequest request, HttpServletResponse response)
throws IOException {
Iterator<?> it = request.getParameterMap().entrySet().iterator();
KettleResult entity = new KettleResult();
while (it.hasNext()) {
Map.Entry<?, ?> ent = (Entry<?, ?>) it.next();
entity.setValue((String) ent.getKey(),
((String[]) ent.getValue())[0]);
}
entity = (KettleResult) service.iKettleResultService.select(entity);
request.setAttribute("entity", entity);
return VIEW_WIDGET + VIEW_KETTLE + VIEW_RESULT + PAGE_VIEW;
}
示例11: addErrors
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Adds the specified errors keys into the appropriate request attribute
* for use by the <html:errors> tag, if any messages are required.
* Initialize the attribute if it has not already been. Otherwise, ensure
* that the request attribute is not set.
*
* @param request The servlet request we are processing
* @param errors Errors object
* @since Struts 1.2.1
*/
protected void addErrors(
HttpServletRequest request,
ActionMessages errors) {
if (errors == null){
// bad programmer! *slap*
return;
}
// get any existing errors from the request, or make a new one
ActionMessages requestErrors = (ActionMessages)request.getAttribute(Globals.ERROR_KEY);
if (requestErrors == null){
requestErrors = new ActionMessages();
}
// add incoming errors
requestErrors.add(errors);
// if still empty, just wipe it out from the request
if (requestErrors.isEmpty()) {
request.removeAttribute(Globals.ERROR_KEY);
return;
}
// Save the errors
request.setAttribute(Globals.ERROR_KEY, requestErrors);
}
示例12: postHandle
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public void postHandle(HttpServletRequest request, //③
HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
long startTime = (Long) request.getAttribute("startTime");
request.removeAttribute("startTime");
long endTime = System.currentTimeMillis();
System.out.println("本次請求處理時間為:" + new Long(endTime - startTime)+"ms");
request.setAttribute("handlingTime", endTime - startTime);
}
示例13: edit
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@At
@Ok("beetl:/WEB-INF/base/department.html")
public void edit(@Param("id")Long id,
HttpServletRequest request){
if(id == null || id == 0){
request.setAttribute("department", null);
}else{
request.setAttribute("department", departmentService.fetch(id));
}
}
示例14: execute
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String param = mapping.getParameter();
// -----------------------Spreadsheet Author function ---------------------------
if (param.equals("start")) {
ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());
return start(mapping, form, request, response);
}
if (param.equals("definelater")) {
// update define later flag to true
Long contentId = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID));
ISpreadsheetService service = getSpreadsheetService();
Spreadsheet spreadsheet = service.getSpreadsheetByContentId(contentId);
spreadsheet.setDefineLater(true);
service.saveOrUpdateSpreadsheet(spreadsheet);
//audit log the teacher has started editing activity in monitor
service.auditLogStartEditingActivityInMonitor(contentId);
request.setAttribute(AttributeNames.ATTR_MODE, ToolAccessMode.TEACHER.toString());
return start(mapping, form, request, response);
}
if (param.equals("initPage")) {
return initPage(mapping, form, request, response);
}
if (param.equals("updateContent")) {
return updateContent(mapping, form, request, response);
}
return mapping.findForward(SpreadsheetConstants.ERROR);
}
示例15: doGet
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Pessoa pessoa = new Pessoa();
pessoa.setNome("Maria");
Endereco endereco = new Endereco();
endereco.setLogradouro("Rua que sobe e desce");
endereco.setNumero(8752);
endereco.setBairro("Muito Longe");
pessoa.setEndereco(endereco);
request.setAttribute("pessoa", pessoa);
request.getRequestDispatcher("mostraPessoa.jsp").forward(request, response);
}