本文整理汇总了Java中javax.servlet.ServletRequest.getParameter方法的典型用法代码示例。如果您正苦于以下问题:Java ServletRequest.getParameter方法的具体用法?Java ServletRequest.getParameter怎么用?Java ServletRequest.getParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.ServletRequest
的用法示例。
在下文中一共展示了ServletRequest.getParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSessionId
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
// 如果参数中包含“__sid”参数,则使用此sid会话。 例如:http://localhost/project?__sid=xxx&__cookie=true
String sid = request.getParameter("__sid");
if (StringUtils.isNotBlank(sid)) {
// 是否将sid保存到cookie,浏览器模式下使用此参数。
if (WebUtils.isTrue(request, "__cookie")) {
HttpServletRequest rq = (HttpServletRequest) request;
HttpServletResponse rs = (HttpServletResponse) response;
Cookie template = getSessionIdCookie();
Cookie cookie = new SimpleCookie(template);
cookie.setValue(sid);
cookie.saveTo(rq, rs);
}
// 设置当前session状态
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE, ShiroHttpServletRequest.URL_SESSION_ID_SOURCE); // session来源与url
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID, sid);
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_IS_VALID, Boolean.TRUE);
return sid;
} else {
return super.getSessionId(request, response);
}
}
示例2: onAccessDenied
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
String error = request.getParameter("error");
String errorDescription = request.getParameter("error_description");
if(!StringUtils.isEmpty(error)) {//如果服务端返回了错误
WebUtils.issueRedirect(request, response, failureUrl + "?error=" + error + "error_description=" + errorDescription);
return false;
}
Subject subject = getSubject(request, response);
if(!subject.isAuthenticated()) {
if(StringUtils.isEmpty(request.getParameter(authcCodeParam))) {
//如果用户没有身份验证,且没有auth code,则重定向到服务端授权
saveRequestAndRedirectToLogin(request, response);
return false;
}
}
return executeLogin(request, response);
}
示例3: onAccessDenied
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
protected boolean onAccessDenied(ServletRequest request,
ServletResponse response) throws Exception {
String backUrl = request.getParameter("backUrl");
saveRequest(request, backUrl,
getDefaultBackUrl(WebUtils.toHttp(request)));
return false;
}
示例4: doFilter
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
final String userName = request.getParameter("user.name");
ServletRequest requestModified =
new HttpServletRequestWrapper((HttpServletRequest) request) {
@Override
public String getRemoteUser() {
return userName;
}
};
filterChain.doFilter(requestModified, response);
}
示例5: getFloatParameter
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Get a float parameter, with a fallback value. Never throws an exception.
* Can pass a distinguished value as default to enable checks of whether it was supplied.
* @param request current HTTP request
* @param name the name of the parameter
* @param defaultVal the default value to use as fallback
*/
public static float getFloatParameter(ServletRequest request, String name, float defaultVal) {
if (request.getParameter(name) == null) {
return defaultVal;
}
try {
return getRequiredFloatParameter(request, name);
}
catch (ServletRequestBindingException ex) {
return defaultVal;
}
}
示例6: doFilter
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
String sessionId = servletRequest.getParameter("sessionId");
if (sessionId != null) {
MDC.put("SessionId", sessionId);
}
filterChain.doFilter(servletRequest, servletResponse);
}
示例7: verify
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
public static int verify(ServletRequest request) {
int gtResult = 0;
try {
GeetestLib gtSdk = new GeetestLib(GeetestConfig.getGeetest_id(), GeetestConfig.getGeetest_key(),
GeetestConfig.isnewfailback());
String challenge = request.getParameter(GeetestLib.fn_geetest_challenge);
String validate = request.getParameter(GeetestLib.fn_geetest_validate);
String seccode = request.getParameter(GeetestLib.fn_geetest_seccode);
Object StatusSessionKey = RequestUtil.getCurrentHttpServletRequest().getSession().getAttribute(gtSdk.gtServerStatusSessionKey);
if (StatusSessionKey == null) {
return 0;
}
int gt_server_status_code = (Integer) StatusSessionKey;
//自定义参数,可选择添加
HashMap<String, String> param = new HashMap<String, String>();
param.put("client_type", "web");
param.put("ip_address", request.getRemoteAddr());
if (gt_server_status_code == 1) {
gtResult = gtSdk.enhencedValidateRequest(challenge, validate, seccode, param);
} else {
System.out.println("failback:use your own server captcha validate");
gtResult = gtSdk.failbackValidateRequest(challenge, validate, seccode);
}
} catch (Exception e) {
e.printStackTrace();
}
return gtResult;
}
示例8: getStringParameter
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Get a String parameter, or {@code null} if not present.
* @param request current HTTP request
* @param name the name of the parameter
* @return the String value, or {@code null} if not present
* @throws ServletRequestBindingException a subclass of ServletException,
* so it doesn't need to be caught
*/
public static String getStringParameter(ServletRequest request, String name)
throws ServletRequestBindingException {
if (request.getParameter(name) == null) {
return null;
}
return getRequiredStringParameter(request, name);
}
示例9: isGoodRequest
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
private boolean isGoodRequest(ServletRequest request) {
// Trigger parsing of parameters
request.getParameter("none");
// Detect failure
if (request.getAttribute(Globals.PARAMETER_PARSE_FAILED_ATTR) != null) {
return false;
}
return true;
}
示例10: introspect
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
public static void introspect(Object bean, ServletRequest request)
throws JasperException
{
Enumeration<String> e = request.getParameterNames();
while ( e.hasMoreElements() ) {
String name = e.nextElement();
String value = request.getParameter(name);
introspecthelper(bean, name, value, request, name, true);
}
}
示例11: getDoubleParameter
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Get a double parameter, with a fallback value. Never throws an exception.
* Can pass a distinguished value as default to enable checks of whether it was supplied.
* @param request current HTTP request
* @param name the name of the parameter
* @param defaultVal the default value to use as fallback
*/
public static double getDoubleParameter(ServletRequest request, String name, double defaultVal) {
if (request.getParameter(name) == null) {
return defaultVal;
}
try {
return getRequiredDoubleParameter(request, name);
}
catch (ServletRequestBindingException ex) {
return defaultVal;
}
}
示例12: getRequiredParameter
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
public static String getRequiredParameter(ServletRequest request, String parameterName) {
String rep = request.getParameter(parameterName);
if (rep == null) {
throw new IllegalArgumentException("The parameter '" + parameterName + "' is required!");
}
return rep;
}
示例13: doFilter
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
try {
if (req instanceof HttpServletRequest) {
HttpServletRequest request = (HttpServletRequest)req;
String locale = null;
// Try HTTP header, Accept-Language field
if (iUseBrowserSettings)
locale = request.getHeader("Accept-Language");
// Try locale parameter (use http session to store)
if (req.getParameter("locale") != null) {
locale = req.getParameter("locale");
request.getSession().setAttribute("unitime.locale", locale);
} else if (request.getSession().getAttribute("unitime.locale") != null) {
locale = (String)request.getSession().getAttribute("unitime.locale");
}
// Fall back to unitime.locale
if (locale == null) {
locale = ApplicationProperty.Locale.value();
UserContext user = getUser();
if (user != null)
locale = user.getProperty(ApplicationProperty.Locale.key(), locale);
}
Localization.setLocale(locale);
}
chain.doFilter(req, resp);
} finally {
Localization.removeLocale();
Formats.removeFormats();
}
}
示例14: getIntParameter
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Get an int parameter, with a fallback value. Never throws an exception.
* Can pass a distinguished value as default to enable checks of whether it was supplied.
* @param request current HTTP request
* @param name the name of the parameter
* @param defaultVal the default value to use as fallback
*/
public static int getIntParameter(ServletRequest request, String name, int defaultVal) {
if (request.getParameter(name) == null) {
return defaultVal;
}
try {
return getRequiredIntParameter(request, name);
}
catch (ServletRequestBindingException ex) {
return defaultVal;
}
}
示例15: update
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/** update table content from given request */
public void update(ServletRequest request) {
if (getModel().isExactTime()) {
int dayCode = 0;
for (int i=0;i<Constants.DAY_CODES.length;i++) {
if (request.getParameter(iName+"_d"+i)!=null)
dayCode += Constants.DAY_CODES[i];
}
int startSlot = -1;
try {
if (request.getParameter(iName+"_hour")!=null) {
int hour = Integer.parseInt(request.getParameter(iName+"_hour"));
if (hour==12) hour=0;
int min = Integer.parseInt(request.getParameter(iName+"_min"));
boolean morn = (Integer.parseInt(request.getParameter(iName+"_morn"))==1);
int startTime = ((hour+(morn?0:12))%24)*60 + min;
startSlot = (startTime - Constants.FIRST_SLOT_TIME_MIN) / Constants.SLOT_LENGTH_MIN;
}
} catch (Exception e) {}
getModel().setExactDays(dayCode);
getModel().setExactStartSlot(startSlot);
return;
} else {
for (int d=0;d<getModel().getNrDays();d++) {
for (int t=0; t<getModel().getNrTimes();t++) {
String prefStr = request.getParameter(iName + "_req_" + d + "_" + t);
iModel.setPreference(d, t, (prefStr==null?getModel().getDefaultPreference():prefStr));
}
}
}
}