本文整理汇总了Java中javax.servlet.ServletException类的典型用法代码示例。如果您正苦于以下问题:Java ServletException类的具体用法?Java ServletException怎么用?Java ServletException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServletException类属于javax.servlet包,在下文中一共展示了ServletException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onAuthenticationFailure
import javax.servlet.ServletException; //导入依赖的package包/类
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
if (exception instanceof CaptchaException) {
getRedirectStrategy().sendRedirect(request, response, CODE_ERROR_URL);
} else {
getRedirectStrategy().sendRedirect(request, response, PASS_ERROR_URL);
}
}
示例2: unspecified
import javax.servlet.ServletException; //导入依赖的package包/类
/**
* <p>Dispatches to the target class' <code>unspecified</code> method, if
* present, otherwise throws a ServletException. Classes utilizing
* <code>EventActionDispatcher</code> should provide an <code>unspecified</code>
* method if they wish to provide behavior different than throwing a
* ServletException.</p>
*
* @param mapping The ActionMapping used to select this instance
* @param form The optional ActionForm bean for this request (if any)
* @param request The non-HTTP request we are processing
* @param response The non-HTTP response we are creating
* @return The forward to which control should be transferred, or
* <code>null</code> if the response has been completed.
* @throws Exception if the application business logic throws an
* exception.
*/
protected ActionForward unspecified(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// Identify if there is an "unspecified" method to be dispatched to
String name = "unspecified";
Method method = null;
try {
method = getMethod(name);
} catch (NoSuchMethodException e) {
String message =
messages.getMessage("event.parameter", mapping.getPath());
LOG.error(message + " " + mapping.getParameter());
throw new ServletException(message);
}
return dispatchMethod(mapping, form, request, response, name, method);
}
示例3: testDoGet
import javax.servlet.ServletException; //导入依赖的package包/类
@Test
public void testDoGet() {
try {
sut.doGet(request, response);
verify(response, times(1)).setContentType("text/html;charset=UTF-8");
verify(response, times(1)).getWriter();
assertEquals("<html>" +
"<img src='images/cat.jpg'>" +
"<p>Image by <a href=\"https://flic.kr/p/HPf9R1\">" +
"Andy Miccone</a></p>" +
"<p>License: <a href=\"https://creativecommons.org/" +
"publicdomain/zero/1.0/\">" +
"CC0 1.0 Universal (CC0 1.0) \n" +
"Public Domain Dedication</a></p>" +
"</html>", stringWriter.toString());
verify(pushBuilder, times(2)).push();
} catch (ServletException | IOException e) {
fail();
}
}
示例4: doGet
import javax.servlet.ServletException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response
) throws ServletException, IOException {
PrintWriter out = response.getWriter();
Map<String, String[]> params = request.getParameterMap();
SortedSet<String> keys = new TreeSet<String>(params.keySet());
for(String key: keys) {
out.print(key);
out.print(':');
String[] values = params.get(key);
if (values.length > 0) {
out.print(values[0]);
for(int i=1; i < values.length; ++i) {
out.print(',');
out.print(values[i]);
}
}
out.print('\n');
}
out.close();
}
示例5: toFileList
import javax.servlet.ServletException; //导入依赖的package包/类
/**
* 获取文件列表
* @param req 客户端发送的数据对象
* @param resp 服务器发送的数据对象(大概)
*/
protected void toFileList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 每页默认显示2条数据
String size = req.getParameter("pageSize");
int pageSize = size == null ? 5 : Integer.parseInt(size);
// 查询文件总数
int fileNum = fileService.queryFileNum();
// 计算总页数
int pages;
if (fileNum%pageSize != 0) {
pages = (fileNum/pageSize) + 1;
} else {
pages = (fileNum/pageSize);
}
// 当前页
String pageIndex = req.getParameter("curPage");
int curPage = pageIndex == null ? 1 : Integer.parseInt(pageIndex);
List<FileDemo> fileDemos = fileService.queryFile(curPage, pageSize);
req.setAttribute("fileDemos", fileDemos);
req.setAttribute("curPage",curPage);
req.setAttribute("pageSize",pageSize);
req.setAttribute("pages",pages);
req.getRequestDispatcher("/filemanage/filemanage.jsp").forward(req, resp);
}
示例6: invoke
import javax.servlet.ServletException; //导入依赖的package包/类
@Override
public int invoke(Request rqst, Response rspns) throws IOException,
ServletException {
if (!isStarted()) {
try {
start();
} catch (LifecycleException ex) {
throw new ServletException(ex);
}
}
rqst.setNote(CatalinaAdapter.REQUEST_TIME, System.currentTimeMillis());
if (!alreadySetLogbackStatusManager) {
alreadySetLogbackStatusManager = true;
org.apache.catalina.Context tomcatContext = rqst.getContext();
if (tomcatContext != null) {
ServletContext sc = tomcatContext.getServletContext();
if (sc != null) {
sc.setAttribute(AccessConstants.LOGBACK_STATUS_MANAGER_KEY, ctx.getStatusManager());
}
}
}
return INVOKE_NEXT;
}
示例7: doGet
import javax.servlet.ServletException; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
PrintWriter out = res.getWriter();
out.print("<p>" + getInitParameter("foo") + " "
+ getInitParameter("bar") + "</p>");
}
示例8: copyFile
import javax.servlet.ServletException; //导入依赖的package包/类
public void copyFile(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String newFullPath=req.getParameter("newFullPath");
String oldFullPath=req.getParameter("oldFullPath");
newFullPath=Utils.decodeURL(newFullPath);
oldFullPath=Utils.decodeURL(oldFullPath);
try{
InputStream inputStream=repositoryService.readFile(oldFullPath, null);
String content=IOUtils.toString(inputStream, "utf-8");
inputStream.close();
User user=EnvironmentUtils.getLoginUser(new RequestContext(req,resp));
repositoryService.createFile(newFullPath, content,user);
loadProjects(req, resp);
}catch(Exception ex){
throw new RuleException(ex);
}
}
示例9: doFilter
import javax.servlet.ServletException; //导入依赖的package包/类
/**
* 判断用户session是否存在 不存在则跳转到登录页面
* 重载方法
* @param srequest
* @param sresponse
* @param chain
* @throws IOException
* @throws ServletException
*/
public void doFilter(ServletRequest srequest, ServletResponse sresponse, FilterChain chain)
throws IOException, ServletException
{
HttpServletRequest request = (HttpServletRequest) srequest;
HttpServletResponse response = (HttpServletResponse) sresponse;
HttpSession session = request.getSession();
//获取工程路径
String path = request.getContextPath();
String requestURl = request.getRequestURI();
if(requestURl.contains("/pages") &&null != session.getAttribute("user"))
chain.doFilter(request, response);
else
response.sendRedirect(path + "/logout.jsp");
}
示例10: doPost
import javax.servlet.ServletException; //导入依赖的package包/类
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String method = request.getParameter("method");
if (method.equals("requestEmail")) {
String selectType = request.getParameter("selectType");
Boolean findByEmail = false;
String param = "";
if (selectType.equals("radioEmail")) {
findByEmail = true;
param = request.getParameter("email");
} else {
param = request.getParameter("login");
}
handleEmailRequest(findByEmail, param.trim(), response);
} else if (method.equals("requestPasswordChange")) {
String newPassword = request.getParameter("newPassword");
String key = request.getParameter("key");
handlePasswordChange(newPassword, key, response);
} else {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
}
}
示例11: handleLogon
import javax.servlet.ServletException; //导入依赖的package包/类
private void handleLogon(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String userName = request.getParameter("userName");
String password = request.getParameter("password");
LoginService loginService = new LoginService();
if (loginService.isValidUser(userName, password)) {
// UserBean user=loginService.getUser();
// request.setAttribute("user", user);
RequestDispatcher requestDispatcher = request
.getRequestDispatcher("useraccounts.jsp");
requestDispatcher.forward(request, response);
} else {
System.out.println("Wrong Login or Password");
response.sendRedirect("logon.jsp");
}
}
示例12: testCheckPreFlightRequestTypeEmptyACRM
import javax.servlet.ServletException; //导入依赖的package包/类
/**
* when a valid CORS Pre-flight request arrives, with empty
* Access-Control-Request-Method
*
* @throws ServletException
* @throws IOException
*/
@Test
public void testCheckPreFlightRequestTypeEmptyACRM()
throws ServletException, IOException {
TesterHttpServletRequest request = new TesterHttpServletRequest();
request.setHeader(CorsFilter.REQUEST_HEADER_ORIGIN,
TesterFilterConfigs.HTTP_TOMCAT_APACHE_ORG);
request.setHeader(
CorsFilter.REQUEST_HEADER_ACCESS_CONTROL_REQUEST_METHOD,
"");
request.setMethod("OPTIONS");
CorsFilter corsFilter = new CorsFilter();
corsFilter.init(TesterFilterConfigs
.getDefaultFilterConfig());
CorsFilter.CORSRequestType requestType =
corsFilter.checkRequestType(request);
Assert.assertEquals(CorsFilter.CORSRequestType.INVALID_CORS,
requestType);
}
示例13: doGet
import javax.servlet.ServletException; //导入依赖的package包/类
@Override
protected void doGet(
final HttpServletRequest req,
final HttpServletResponse resp
) throws ServletException, IOException {
for (final StaticResourceResolver resolver : staticResourceResolvers) {
final StaticResourceResolver.ResolvedResource resource = resolver.resolve(req.getPathInfo());
if (resource == null) {
continue;
}
resp.setContentType(resource.getContentType());
try {
resource.getContent(resp.getOutputStream());
}catch(final IOException e) {
LOG.error("I/O error serving static resource", e);
resp.setStatus(500);
}
return;
}
resp.setStatus(404);
}
示例14: execute
import javax.servlet.ServletException; //导入依赖的package包/类
/**
* Process the specified HTTP request, and create the corresponding HTTP
* response (or forward to another web component that will create it). Return
* an <code>ActionForward</code> instance describing where and how control
* should be forwarded, or <code>null</code> if the response has already been
* completed.
*
* @param mapping The ActionMapping used to select this instance
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
* @param form NOT YET DOCUMENTED
* @return NOT YET DOCUMENTED
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet exception occurs
*/
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
ActionErrors errors = new ActionErrors();
UcasProxyForm ucasForm = (UcasProxyForm) form;
// Query Args
String command = request.getParameter("command");
SchemEditUtils.showRequestParameters(request);
try {
return getUcasUserInfo(mapping, form, request, response);
} catch (Throwable t) {
t.printStackTrace();
errors.add("error",
new ActionError("generic.error", "System Error: " + t.getMessage()));
saveErrors(request, errors);
}
// Forward control to the specified success URI
return (mapping.findForward("error.page"));
}
示例15: doGet
import javax.servlet.ServletException; //导入依赖的package包/类
@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response)
throws ServletException,
IOException
{
logger.info("I am running!");
response.getWriter().write("Hello World!");
}