当前位置: 首页>>代码示例>>Java>>正文


Java URLEncoder类代码示例

本文整理汇总了Java中org.apache.catalina.util.URLEncoder的典型用法代码示例。如果您正苦于以下问题:Java URLEncoder类的具体用法?Java URLEncoder怎么用?Java URLEncoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


URLEncoder类属于org.apache.catalina.util包,在下文中一共展示了URLEncoder类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGet

import org.apache.catalina.util.URLEncoder; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    AsyncContext ac = req.startAsync();
    // Quick and dirty. Sufficient for this test but ignores lots of
    // edge cases.
    String target = null;
    if (dispatchPath != null) {
        target = req.getServletPath();
        int lastSlash = target.lastIndexOf('/');
        target = target.substring(0, lastSlash + 1);
        if (encodePath) {
            target = URLEncoder.DEFAULT.encode(target, "UTF-8");
        }
        target += dispatchPath;
    }
    try {
        ac.dispatch(target);
    } catch (UnsupportedOperationException uoe) {
        ac.complete();
        resp.setContentType("text/plain");
        resp.setCharacterEncoding("UTF-8");
        resp.getWriter().print(NULL);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:27,代码来源:TestApplicationContextGetRequestDispatcher.java

示例2: dispatch

import org.apache.catalina.util.URLEncoder; //导入依赖的package包/类
@Override
public void dispatch() {
	check();
	String path;
	String pathInfo;
	ServletRequest servletRequest = getRequest();
	if (servletRequest instanceof HttpServletRequest) {
		HttpServletRequest sr = (HttpServletRequest) servletRequest;
		path = sr.getServletPath();
		pathInfo = sr.getPathInfo();
	} else {
		path = request.getServletPath();
		pathInfo = request.getPathInfo();
	}
	if (pathInfo != null) {
		path += pathInfo;
	}
	if (this.context.getDispatchersUseEncodedPaths()) {
		path = URLEncoder.DEFAULT.encode(path, "UTF-8");
	}
	dispatch(path);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:23,代码来源:AsyncContextImpl.java

示例3: sendRESTCall

import org.apache.catalina.util.URLEncoder; //导入依赖的package包/类
/**
 * Proceed with SMS API's rest call.
 *
 * @param context      the AuthenticationContext
 * @param smsUrl       the smsUrl
 * @param httpMethod   the httpMethod
 * @param headerString the headerString
 * @param payload      the payload
 * @param httpResponse the httpResponse
 * @param mobile       the mobile number
 * @param otpToken     the OTP token
 * @return true or false
 * @throws IOException
 * @throws AuthenticationFailedException
 */
public boolean sendRESTCall(AuthenticationContext context, String smsUrl, String httpMethod,
                            String headerString, String payload, String httpResponse, String mobile,
                            String otpToken) throws IOException, AuthenticationFailedException {
    if (log.isDebugEnabled()) {
        log.debug("Preparing message for sending out");
    }
    HttpURLConnection httpConnection;
    boolean connection;
    String smsMessage = SMSOTPConstants.SMS_MESSAGE;
    URLEncoder encoder = new URLEncoder();
    String encodedMobileNo = encoder.encode(mobile);
    smsUrl = smsUrl.replaceAll("\\$ctx.num", encodedMobileNo).replaceAll("\\$ctx.msg",
            smsMessage.replaceAll("\\s", "+") + otpToken);
    URL smsProviderUrl = new URL(smsUrl);
    String subUrl = smsProviderUrl.getProtocol();
    if (subUrl.equals(SMSOTPConstants.HTTPS)) {
        httpConnection = (HttpsURLConnection) smsProviderUrl.openConnection();
        connection = getConnection(httpConnection, context, headerString, payload, httpResponse, encodedMobileNo,
                smsMessage, otpToken, httpMethod);
    } else {
        httpConnection = (HttpURLConnection) smsProviderUrl.openConnection();
        connection = getConnection(httpConnection, context, headerString, payload, httpResponse, encodedMobileNo,
                smsMessage, otpToken, httpMethod);
    }
    return connection;
}
 
开发者ID:wso2-extensions,项目名称:identity-outbound-auth-sms-otp,代码行数:42,代码来源:SMSOTPAuthenticator.java

示例4: getRequestDispatcher

import org.apache.catalina.util.URLEncoder; //导入依赖的package包/类
/**
 * Return a RequestDispatcher that wraps the resource at the specified
 * path, which may be interpreted as relative to the current request path.
 *
 * @param path Path of the resource to be wrapped
 */
@Override
public RequestDispatcher getRequestDispatcher(String path) {

    if (context == null) {
        return null;
    }

    // If the path is already context-relative, just pass it through
    if (path == null) {
        return null;
    } else if (path.startsWith("/")) {
        return (context.getServletContext().getRequestDispatcher(path));
    }

    // Convert a request-relative path to a context-relative one
    String servletPath = (String) getAttribute(
            RequestDispatcher.INCLUDE_SERVLET_PATH);
    if (servletPath == null) {
        servletPath = getServletPath();
    }

    // Add the path info, if there is any
    String pathInfo = getPathInfo();
    String requestPath = null;

    if (pathInfo == null) {
        requestPath = servletPath;
    } else {
        requestPath = servletPath + pathInfo;
    }

    int pos = requestPath.lastIndexOf('/');
    String relative = null;
    if (context.getDispatchersUseEncodedPaths()) {
        if (pos >= 0) {
            relative = URLEncoder.DEFAULT.encode(
                    requestPath.substring(0, pos + 1), "UTF-8") + path;
        } else {
            relative = URLEncoder.DEFAULT.encode(requestPath, "UTF-8") + path;
        }
    } else {
        if (pos >= 0) {
            relative = requestPath.substring(0, pos + 1) + path;
        } else {
            relative = requestPath + path;
        }
    }

    return context.getServletContext().getRequestDispatcher(relative);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:57,代码来源:Request.java

示例5: getRequestDispatcher

import org.apache.catalina.util.URLEncoder; //导入依赖的package包/类
/**
 * Return a RequestDispatcher that wraps the resource at the specified path,
 * which may be interpreted as relative to the current request path.
 *
 * @param path
 *            Path of the resource to be wrapped
 */
@Override
public RequestDispatcher getRequestDispatcher(String path) {

	if (context == null) {
		return null;
	}

	// If the path is already context-relative, just pass it through
	if (path == null) {
		return null;
	} else if (path.startsWith("/")) {
		return (context.getServletContext().getRequestDispatcher(path));
	}

	// Convert a request-relative path to a context-relative one
	String servletPath = (String) getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
	if (servletPath == null) {
		servletPath = getServletPath();
	}

	// Add the path info, if there is any
	String pathInfo = getPathInfo();
	String requestPath = null;

	if (pathInfo == null) {
		requestPath = servletPath;
	} else {
		requestPath = servletPath + pathInfo;
	}

	int pos = requestPath.lastIndexOf('/');
	String relative = null;
	if (context.getDispatchersUseEncodedPaths()) {
		if (pos >= 0) {
			relative = URLEncoder.DEFAULT.encode(requestPath.substring(0, pos + 1), "UTF-8") + path;
		} else {
			relative = URLEncoder.DEFAULT.encode(requestPath, "UTF-8") + path;
		}
	} else {
		if (pos >= 0) {
			relative = requestPath.substring(0, pos + 1) + path;
		} else {
			relative = requestPath + path;
		}
	}

	return context.getServletContext().getRequestDispatcher(relative);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:56,代码来源:Request.java


注:本文中的org.apache.catalina.util.URLEncoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。