我有一个不是用JSP和Spring MVC构建的Web应用程序,但我目前负责它的源代码。
当我测试将应用程序重定向到大多数页面时,它给我一个错误401(未授权)。
我在应用程序中进行搜索,但可能无济于事。
我仅有的线索是web.xml文件和mvc-dispatcher-servlet.xml,它们告诉我正确的重定向和异常处理程序。
web.xml页面包含<security-constraint>
标签,其中包含每个用户允许使用的页面,所有有问题的页面都在每个<url-pattern>
内部的<security-constraint>
标签中。
但是,没有任何页面对未经授权的页面一无所知。
即使我尝试调试与每个页面相关的ManagedBean类,但是在调试任何代码行之前,都会显示错误页面。我只能在部署应用程序时调试托管Bean的构造函数。
如果您需要示例或某些文件的内容。让我知道,我会把它们给你。
以下是mvc-dispatcher-servlet.htm的片段:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/paginas/" />
<property name="suffix" value=".jsp" />
</bean>
<bean name="/bloqueoindividual.htm"
class="cl.claro.aplicaciones.webberr.controler.BloqueoIndividual">
<!-- DOESN'T WORK. ERROR 401 -->
</bean>
<bean name="/bloqueomasivo.htm" class="cl.claro.aplicaciones.webberr.controler.BloqueoMasivo" >
<!--WORKS-->
</bean>
<bean id="handlerExceptionResolver" class="cl.claro.aplicaciones.webberr.exception.ExceptionHandler" >
<!-- from ExceptionHandler -->
<property name="ajaxErrorView" value="ajaxexception" />
<property name="ajaxDefaultErrorMessage" value="${ajaxErrorMessage}" />
<property name="ajaxShowTechMessage" value="false" />
<!-- from SimpleMappingExceptionResolver -->
<property name="defaultErrorView" value="checked"/>
<property name="exceptionMappings">
<props>
<prop key="java.lang.RuntimeException" >unchecked</prop>
</props>
</property>
</bean>
<!-- Message resource bundle and locale -->
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource" >
<property name="defaultEncoding" value="UTF-8" />
<property name="basenames">
<list>
<value>classpath:message</value>
</list>
</property>
<property name="fallbackToSystemLocale" value="false" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver" >
<property name="defaultLocale" value="es" />
</bean>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" >
<property name="paramName" value="lang" />
</bean>
<!-- End of resource bundle -->
<!-- DISABLE CACHE DE PAGINAS -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="org.springframework.web.servlet.mvc.WebContentInterceptor" >
<property name="cacheSeconds" value="0" />
<property name="useExpiresHeader" value="true"/>
<property name="useCacheControlHeader" value="true"/>
<property name="useCacheControlNoStore" value="true"/>
<property name="alwaysUseFullPath" value="true"/>
</bean>
</mvc:interceptor>
</mvc:interceptors>
编辑:按照Akshay Mishra的要求,我在应用程序中搜索了将应用于页面的任何过滤器。我找到2个过滤器。
javax.servlet.Filter
的类,因此按如下所示覆盖它的doFilter方法:public static final String TXID_HEADER = "X-TXID";
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain fc) throws IOException, ServletException {
String path = ((HttpServletRequest) servletRequest).getRequestURI();
if (path.startsWith(((HttpServletRequest) servletRequest).getContextPath() + "/resources/")) {
//no aplicar txid a contenido estatico
fc.doFilter(servletRequest, servletResponse);
return;
}
long t1 = System.currentTimeMillis();
try{
String txID = ((HttpServletRequest)servletRequest).getHeader(TXID_HEADER);
if (txID == null) {
txID = UUID.randomUUID().toString();
}
ThreadContext.put("txid", txID);
HttpServletRequest request = (HttpServletRequest)servletRequest;
log.info("Peticion recibida: metodo=[{}] url=[{}] desde=[{}]", request.getMethod(), request.getRequestURI(), request.getRemoteAddr());
HttpServletResponse response = (HttpServletResponse)servletResponse;
response.setHeader(TXID_HEADER, txID);
response.setCharacterEncoding(CharEncoding.UTF_8);
fc.doFilter(servletRequest, servletResponse);
}
finally{
long t2 = System.currentTimeMillis();
log.info("Peticion atendida en {} ms", t2-t1);
ThreadContext.remove("txid");
}
}
<filter>
<filter-name>ResponseOverrideFilter</filter-name>
<filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ResponseOverrideFilter</filter-name>
<url-pattern>*.htm</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ResponseOverrideFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>