标签: url-pattern

@WebFilter排除url-pattern

我使用过滤器来检查登录用户的URL模式.

但是我需要过滤许多URL模式.

{ "/table/*", "/user/*", "/contact/*", "/run/*", "/conf/*", ..., ..., ...}
Run Code Online (Sandbox Code Playgroud)

它变得不可维护.排除以下内容会更简单:

{ "/", "/login", "/logout", "/register" }
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

@WebFilter(urlPatterns = { "/table/*","/user/*", "/contact/*","/run/*","/conf/*"})
public class SessionTimeoutRedirect implements Filter {

    protected final Logger logger = LoggerFactory.getLogger("SessionFilter");

    @Override
    public void doFilter(ServletRequest req, ServletResponse res,
            FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        if (request.getSession().getAttribute("Id") != null) {
            chain.doFilter(req, res);
        } else {
            logger.debug("session is null:"+request.getRequestURL());                    
            response.sendRedirect(request.getContextPath()+"/login");
        }
    }

    @Override
    public void init(FilterConfig arg0) …
Run Code Online (Sandbox Code Playgroud)

java servlets url-pattern servlet-filters

15
推荐指数
1
解决办法
2万
查看次数

将特定servlet映射为Tomcat中的缺省servlet

我正在尝试实现一个获取原始请求的servlet,并决定处理它们,还是将它们转发到另一个后端服务器.它类似于负载均衡器,其中收到的请求被转发到(在我的情况下为2个)目的地之一.其中一个目标是远程(在另一台主机上).此外,请求可以到根(http://mycompany.com/).

因为我想获得原始请求,所以我实现了自己的servlet(子类化HttpServlet),这非常有用.我的servlet看起来像:

public class MyProxyServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
        processOrForward(req, resp);
    }
    // also doGet(), doHead(), ...
}
Run Code Online (Sandbox Code Playgroud)

由于我想要处理的服务可以向root发送请求,我想将我的servlet映射为默认的servlet,从而接收任何没有显式servlet映射的请求.假设我的servlet名称是"myservlet",并且正在另一个servlet"foo"的一侧运行,我希望所有以http://mycompany.com/foo/ ... 形式发出的请求都被传递给foo,以及一切else(例如/,/ bar/...,/ myservlet/...)到"myservlet".看一下之前的帖子(例如,这里这里的根映射,或者这里的 url重写),我以为我想出来了,但它不起作用.

这是我的web.xml:

<web-app>
  <servlet>
    <servlet-name>ProxyServlet</servlet-name>
    <servlet-class>com.mycompany.MyProxyServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>ProxyServlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

在上面的web.xml中,对于url-pattern我试过了

"/" and "/*" and empty (i.e., <url-pattern></url-pattern>), all behave the same -->
    Requests to root (/)goes to tomcat's default …
Run Code Online (Sandbox Code Playgroud)

java tomcat servlets url-pattern

14
推荐指数
1
解决办法
3万
查看次数

在servlet中获取请求url的一部分

我有一个EmailVerification使用/ev/*url-pattern 映射的Servlet .

http://example.com/ev/ce52320570
Run Code Online (Sandbox Code Playgroud)

如何ce52320570在Servlet中获取URL的这一部分?

protected void doPost(HttpServletRequest request, HttpServletResponse response)
                                                     throws ServletException, IOException {
      String vid = "";  // Here I need to get the id from the URL
}
Run Code Online (Sandbox Code Playgroud)

java servlets httprequest url-pattern java-ee

13
推荐指数
1
解决办法
2万
查看次数

为什么FacesServlet不能有/*的url模式.?

这是我的web.xml:

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

当我导航到:

http://localhost:8080/LearningRoot/index.xhtml
Run Code Online (Sandbox Code Playgroud)

我可以看到页面很好,但是当我导航到:

http://localhost:8080/LearningRoot/
Run Code Online (Sandbox Code Playgroud)

我收到错误:

发生错误:

FacesServlet不能具有/*的url模式.请定义一个不同的url模式.

但为什么?

这是我的欢迎档案:

<welcome-file-list>
    <welcome-file>/index.xhtml</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)

jsf url-pattern java-ee servlet-mapping

12
推荐指数
1
解决办法
1万
查看次数

为什么servlet映射中的url-pattern以正斜杠(/)开头

我正在阅读Head First JSP和Servlets一书.我正在浏览servlet的映射.我怀疑的是

<servlet>
    <servlet-name>test</servlet-name>
    <servlet-class>com.avinash.TestServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>test</servlet-name>
    <url-pattern>/ServletBeer.do</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
  1. 为什么要url-pattern以正斜杠(/)开头?
  2. 正斜杠(/)代表什么?它代表我们的webapp名称吗?
  3. 如果url-pattern不以正斜杠(/)开头会发生什么?
  4. 它是以正斜杠(/)开头的规范吗?

在书中明确提到:

不要忘记url-pattern中的正斜杠(/).

你可以解释吗?

java servlets url-pattern servlet-mapping

12
推荐指数
1
解决办法
4439
查看次数

Basic Spring MVC配置:使用InternalResourceViewResolver的PageNotFound

我正在尝试运行第一个Spring 3 MVC设置.

我的应用程序在tomcat上运行,在"葡萄藤"的服务器环境中运行

出于测试目的,我正在尝试从中提取请求http://localhost:8080/grapevine/test以呈现内容WEB-INF/jsp/noSuchInvitation.jsp

当我尝试这个时,我得到了一个404,并且日志表明我的jsp不存在:

WARN  org.springframework.web.servlet.PageNotFound  - No mapping found for HTTP request with URI [/grapevine/WEB-INF/jsp/noSuchInvitation.jsp] in DispatcherServlet with name 'grapevine'
Run Code Online (Sandbox Code Playgroud)

我必须在某个地方错误地配置它,但我看不出我做错了什么.

这是所有相关的片段.

web.xml中:

<servlet>
    <servlet-name>grapevine</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>grapevine</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

从我的背景来看:

<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

控制器:

@Controller
public class ParticipantInvitationController {

@RequestMapping("/test")
public ModelAndView test()
{
    return new ModelAndView("noSuchInvitation");
}
Run Code Online (Sandbox Code Playgroud)

日志:

DEBUG org.springframework.web.servlet.DispatcherServlet  - Rendering view [org.springframework.web.servlet.view.JstlView: name 'noSuchInvitation'; URL [/WEB-INF/jsp/noSuchInvitation.jsp]] in DispatcherServlet …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc url-pattern

11
推荐指数
1
解决办法
2万
查看次数

如何在filtermapping中排除网址

web.xml中

<filter>
    <filter-name>SessionCheckFilter</filter-name>
    <filter-class>filter.SessionCheckFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>SessionCheckFilter</filter-name>
    <url-pattern>/faces/app/admin/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)

我试图排除/faces/app/admin/index.xhtml唯一的,有没有办法做到这一点?

如果在web.xml中没有排除url patterin,也许我可以操纵该doFilter()方法来排除url?

java web.xml url-pattern servlet-filters

11
推荐指数
1
解决办法
3万
查看次数

如何在URL中使用.jsf扩展名?

我正在开发一个JSF 2 Web应用程序.对于声望的purpouses我希望每个URL以.jsf扩展名结尾.现在结束了.xhtml.如果我将其直接更改为.jsfWeb浏览器地址栏,则会显示HTTP 500错误.

我该怎么设置它.jsf

jsf url-pattern jsf-2 servlet-mapping

10
推荐指数
2
解决办法
1万
查看次数

错误:在ExternalContext中找不到/login.xhtml作为资源

我正在使用JBoss 7.1和JSF 2.1/Prime Faces并继续遇到标题中列出的错误.我已经尝试了很多这里提出的建议,但最终都出现了同样的错误.

文件结构是:

WEB-INF
   faces
      login.xhtml
Run Code Online (Sandbox Code Playgroud)

我在web.xml中有以下内容:

<display-name>clientAccountManager</display-name>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
    <param-value>true</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)

我正在使用以下URL访问该文件:

http://localhost:8080/clientAccountManager/faces/login.xhtml
Run Code Online (Sandbox Code Playgroud)

我还将URL模式更改为*.xhtml并使用:

http://localhost:8080/clientAccountManager/login.xhtml
Run Code Online (Sandbox Code Playgroud)

结果相同.

我错过了什么?

jsf url-pattern

10
推荐指数
1
解决办法
5万
查看次数

/faces/index.xhtml在ExternalContext中找不到作为Glassfish中的资源

启动应用程序时出现此错误.

com.sun.faces.context.FacesFileNotFoundException:/faces/index.xhtml作为资源在ExternalContext中找不到

这是web.xml的上下文:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>#{themeSwitcherBean.theme}</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>
Run Code Online (Sandbox Code Playgroud)

java netbeans glassfish url-pattern

9
推荐指数
1
解决办法
2万
查看次数