本文整理匯總了Java中javax.servlet.http.HttpServletRequest.getParameter方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletRequest.getParameter方法的具體用法?Java HttpServletRequest.getParameter怎麽用?Java HttpServletRequest.getParameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.getParameter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGet
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PolicyFactory policy = new HtmlPolicyBuilder()
.allowElements("p").toFactory();
String query = req.getQueryString();
String notes = req.getParameter("notes");
String foundIn = req.getParameter("foundIn");
String faultData = req.getParameter("faultData");
String projectId = req.getParameter("projectId");
if (notes == null) notes = "";
if (foundIn == null) foundIn = "";
if (faultData == null) faultData = "";
if (projectId == null) projectId = "-1";
notes = policy.sanitize(notes);
foundIn = policy.sanitize(foundIn);
projectId = policy.sanitize(projectId);
PrintWriter out = new PrintWriter(resp.getWriter());
out.println(String.format(template, notes, foundIn, faultData, projectId));
}
示例2: getParameter
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* 根據key獲取;如果有state,從state中獲取;否則從request中獲取
* @param request
* @param name
* @return
*/
public static String getParameter(HttpServletRequest request, String name){
String state = request.getParameter("state");
if(state != null){
String[] stateArr = state.split("!");//用!間隔
if(stateArr != null && stateArr.length > 0){
for(String s : stateArr){
String key = s.split("=")[0];
String value = s.split("=")[1];
if(name.equals(key)){
return value;
}
}
}
return null;
}else{
return request.getParameter(name);
}
}
示例3: doPost
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* doPost method to display categories of Hotels page.
*
* @param request
* @param response
* @throws IOException
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
StringBuilder sb = new StringBuilder();
PrintWriter out = response.getWriter();
if (getUsername(request) != null) {
String type = request.getParameter("type");
String[] titles = new String[] {"Hotels", "Reviews", "Attractions"};
for (int i = 0; i < titles.length; i++) {
if (type.equals(titles[i])) {
sb.append("<label class=\"list-group-item list-group-item-action active\">");
sb.append(titles[i]).append("</label>");
}
else {
sb.append("<label class=\"list-group-item list-group-item-action\" ");
sb.append("onclick=\"tableTitle('" + titles[i] + "')\">");
sb.append(titles[i]).append("</label>");
}
}
out.println(sb.toString());
}
}
示例4: run
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public Object run() {
try {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
Object blueOrGreen = request.getParameter("env");
RequestMetadata requestMetadata = RequestMetadata.getCurrent().init();
if (blueOrGreen != null ) {
requestMetadata.add("env", "canary");
} else {
requestMetadata.add("env", "prod");
}
} catch (Exception e) {
ReflectionUtils.rethrowRuntimeException(e);
}
return null;
}
示例5: preHandle
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
WxWebUser sessionUser = WxWebUtils.getWxWebUserFromSession(request);
if (sessionUser != null) {
return true;
}
String code = request.getParameter("code");
String state = request.getParameter("state");
if (!StringUtils.isEmpty(code)) {
WxWebUser wxWebUser = wxUserManager.getWxWebUser(code);
if (wxWebUser != null && wxWebUser.getOpenId() != null) {
if (wxOAuth2Callback != null) {
wxOAuth2Callback.after(new WxOAuth2Callback.WxOAuth2Context(wxWebUser, state, response, request));
}
WxWebUtils.setWxWebUserToSession(request, wxWebUser);
return true;
}
}
String requestUrl = getRequestUrl(request);
logger.info("WxOAuth2Interceptor request url is : " + requestUrl);
// 如果重定向到授權,則肯定可以獲得信息,但是如果重定向到基本,則無法獲得信息,所以默認重定向到授權
String redirectUrl = WxRedirectUtils.redirect(requestUrl, false);
logger.info("WxOAuth2Interceptor redirect to auth url : " + redirectUrl);
response.sendRedirect(redirectUrl);
return false;
}
示例6: validateParameters
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* validates request paramaters based on tool contract
*
* @param request
* @param mapping
* @return ActionForward
* @throws ServletException
*/
protected ActionForward validateParameters(HttpServletRequest request, ActionMapping mapping,
QaMonitoringForm qaMonitoringForm) throws ServletException {
String strToolContentId = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID);
if ((strToolContentId == null) || (strToolContentId.length() == 0)) {
QaUtils.cleanUpSessionAbsolute(request);
throw new ServletException("No Tool Content ID found");
} else {
try {
long toolContentId = new Long(strToolContentId).longValue();
qaMonitoringForm.setToolContentID(new Long(toolContentId).toString());
} catch (NumberFormatException e) {
QaUtils.cleanUpSessionAbsolute(request);
throw e;
}
}
return null;
}
示例7: seMenuListDataHandler
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping(value = "/se_menu_list_data.do", method = {RequestMethod.POST}, produces = "application/json")
@ResponseBody
public String seMenuListDataHandler(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws ServletException {
PageProperty pp = new PageProperty();
String[] enableSorts = {"id", "captionname", "menucode", "visible", "sourceurl"};
String parentcode = request.getParameter("parentcode");
if (!Utils.strIsNull(parentcode)) {
pp.putParamMap("parentcode", parentcode.replace("%", "/%"));
}
setPageInfo(request, pp, enableSorts);
PageList<SeMenu> seMenuList = seMenuService.getPageList(pp);
return JSON.toJSONString(seMenuList, WriteNullStringAsEmpty);
}
示例8: ajaxArticleTop
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* 文章置頂
* @param request
* @return
*/
@RequestMapping("/article/ajax/top")
@ResponseBody
public AjaxResult ajaxArticleTop(HttpServletRequest request){
AjaxResult ajaxResult = new AjaxResult();
ajaxResult.setSuccess(false);
try {
Boolean isTop = false;
String[] ids = request.getParameterValues("ids");
String topFlag = request.getParameter("topFlag");
if(StringUtils.isNotBlank(topFlag) && topFlag.equals("1")){
isTop = true;
}
if(ids != null && ids.length > 0){
for(String id:ids){
Article article = this.articleService.find(id);
article.setIsTop(isTop);
this.articleService.update(article);
}
}
ajaxResult.setSuccess(true);
} catch (Exception e) {
e.printStackTrace();
}
return ajaxResult;
}
示例9: add
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping(value = "/calculator", method = RequestMethod.POST)
public String add(Model model, HttpServletRequest request) {
String s1 = request.getParameter("s1");
String s2 = request.getParameter("s2");
String ans = service.calculation(s1, s2, request.getParameter("r1"));
model.addAttribute("ans", ans);
model.addAttribute("s1", s1);
model.addAttribute("s2", s2);
return "calculator";
}
示例10: validUser
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private User validUser(HttpServletRequest httpReq,
HttpServletResponse httpResp) {
// convert uniqueFields to object
UserType userType = WebUtil.getUserType(httpReq);
FieldMetadata[] uniqueFields = userType.getUserMetadata()
.getMainTableMetadata().getUniqueFields();
User expectUser = new User();
for (int i = 0; i < uniqueFields.length; i++) {
FieldMetadata fieldMetadata = uniqueFields[i];
String javaType = fieldMetadata.getJavaType();
String paramName = fieldMetadata.getName();
if (uniqueFieldsParams != null) {
paramName = uniqueFieldsParams[i];
}
String rawValue = httpReq.getParameter(paramName);
Object value = parse(javaType, rawValue);
expectUser.set(fieldMetadata.getName(), value);
}
String rawPassword = httpReq.getParameter(passwordParam);
String password = encrypt.encrypt(rawPassword);
UserManager manager = Factory.getUserManager(userType.getName());
User findUser = manager.selectByUniqueFields(expectUser);
if (findUser != null
&& findUser.get(userPasswordField).equals(password)) {
return findUser;
} else {
return null;
}
}
示例11: doFilterInternal
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
String authToken = request.getParameter(this.tokenHeader);
String userAppname = request.getParameter(this.appName);
// authToken.startsWith("Bearer ")
// String authToken = header.substring(7);
String ybid = jwtTokenUtil.getYBidFromTocken(authToken);
String appname = jwtTokenUtil.getAppnameFromTocken(authToken);
logger.info("checking authentication for user " + ybid);
if (ybid != null && SecurityContextHolder.getContext().getAuthentication() == null) {
// It is not compelling necessary to load the use details from the database. You could also store the information
// in the token and read it from it. It's up to you ;)
UserDetails userDetails = this.userDetailsService.loadUserByUsername(ybid);
// For simple validation it is completely sufficient to just check the token integrity. You don't have to call
// the database compellingly. Again it's up to you ;)
if (jwtTokenUtil.validateToken(authToken, userDetails)) {
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
logger.info("authenticated user " + ybid + ", setting security context");
SecurityContextHolder.getContext().setAuthentication(authentication);
}
}
chain.doFilter(request, response);
}
示例12: fileRename
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public void fileRename(HttpServletRequest req, HttpServletResponse resp) throws Exception {
String path=req.getParameter("path");
path=Utils.decodeURL(path);
String newPath=req.getParameter("newPath");
newPath=Utils.decodeURL(newPath);
repositoryService.fileRename(path, newPath);
loadProjects(req, resp);
}
示例13: repopulateRequestParameters
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* repopulateRequestParameters reads and saves request parameters
*
* @param request
* @param voteAuthoringForm
* @param voteGeneralAuthoringDTO
*/
protected void repopulateRequestParameters(HttpServletRequest request, VoteAuthoringForm voteAuthoringForm,
VoteGeneralAuthoringDTO voteGeneralAuthoringDTO) {
String toolContentID = request.getParameter(VoteAppConstants.TOOL_CONTENT_ID);
voteAuthoringForm.setToolContentID(toolContentID);
voteGeneralAuthoringDTO.setToolContentID(toolContentID);
String httpSessionID = request.getParameter(VoteAppConstants.HTTP_SESSION_ID);
voteAuthoringForm.setHttpSessionID(httpSessionID);
voteGeneralAuthoringDTO.setHttpSessionID(httpSessionID);
String lockOnFinish = request.getParameter(VoteAppConstants.LOCK_ON_FINISH);
voteAuthoringForm.setLockOnFinish(lockOnFinish);
voteGeneralAuthoringDTO.setLockOnFinish(lockOnFinish);
String useSelectLeaderToolOuput = request.getParameter(VoteAppConstants.USE_SELECT_LEADER_TOOL_OUTPUT);
voteAuthoringForm.setUseSelectLeaderToolOuput(useSelectLeaderToolOuput);
voteGeneralAuthoringDTO.setUseSelectLeaderToolOuput(useSelectLeaderToolOuput);
String allowText = request.getParameter(VoteAppConstants.ALLOW_TEXT);
voteAuthoringForm.setAllowText(allowText);
voteGeneralAuthoringDTO.setAllowText(allowText);
String showResults = request.getParameter(VoteAppConstants.SHOW_RESULTS);
voteAuthoringForm.setShowResults(showResults);
voteGeneralAuthoringDTO.setShowResults(showResults);
String maxNominationCount = request.getParameter(VoteAppConstants.MAX_NOMINATION_COUNT);
voteAuthoringForm.setMaxNominationCount(maxNominationCount);
voteGeneralAuthoringDTO.setMaxNominationCount(maxNominationCount);
String minNominationCount = request.getParameter(MIN_NOMINATION_COUNT);
voteAuthoringForm.setMinNominationCount(minNominationCount);
voteGeneralAuthoringDTO.setMinNominationCount(minNominationCount);
String reflect = request.getParameter("reflect");
voteAuthoringForm.setReflect(reflect);
voteGeneralAuthoringDTO.setReflect(reflect);
String reflectionSubject = request.getParameter("reflectionSubject");
voteAuthoringForm.setReflectionSubject(reflectionSubject);
voteGeneralAuthoringDTO.setReflectionSubject(reflectionSubject);
String maxInputs = request.getParameter(VoteAppConstants.MAX_INPUTS);
if (maxInputs == null) {
logger.info("Since minNomcount is equal to null hence setting it to '0'");
maxInputs = "0";
}
voteAuthoringForm.setMaxInputs(new Short(maxInputs));
ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());
}
示例14: save
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public String save() throws Exception {
HttpServletRequest request=Struts2Utils.getRequest();
User user=accountManager.getCurUser();
String email = request.getParameter("email");
String cellphone = request.getParameter("cellphone");
String name = request.getParameter("name");
user.setEmail(email);
user.setCellphone(cellphone);
user.setName(name);
accountManager.saveUp(user);
return SUCCESS;
}
示例15: saveBurningQuestions
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Saves burning questions entered by user. It also updates its values in SessionMap.
*/
private void saveBurningQuestions(HttpServletRequest request) {
initializeScratchieService();
String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
.getAttribute(sessionMapID);
final Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID);
Collection<ScratchieItem> items = (Collection<ScratchieItem>) sessionMap.get(ScratchieConstants.ATTR_ITEM_LIST);
for (ScratchieItem item : items) {
final Long itemUid = item.getUid();
final String burningQuestion = request.getParameter(ScratchieConstants.ATTR_BURNING_QUESTION_PREFIX + itemUid);
// update question in sessionMap
item.setBurningQuestion(burningQuestion);
// update new entry
service.saveBurningQuestion(sessionId, itemUid, burningQuestion);
}
// handle general burning question
final String generalQuestion = request.getParameter(ScratchieConstants.ATTR_GENERAL_BURNING_QUESTION);
service.saveBurningQuestion(sessionId, null, generalQuestion);
// update general question in sessionMap
sessionMap.put(ScratchieConstants.ATTR_GENERAL_BURNING_QUESTION, generalQuestion);
}