- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在 web.xml
中,如果我使用如下完整路径指定了 servlet 映射:
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/view/admin</url-pattern>
</servlet-mapping>
它工作正常,但如果我根据the specification使用星号(*) (第 12.2 章):
In the Web application deployment descriptor, the following syntax is used to define mappings:
- A string beginning with a ‘ / ’ character and ending with a ‘ /* ’ suffix is used for path mapping.
- A string beginning with a ‘ *. ’ prefix is used as an extension mapping. The empty string ("") is a special URL pattern that exactly maps to the application's context root, i.e., requests of the form http://host:port//. In this case the path info is ’ / ’ and the servlet path and context path is empty string (““).
- A string containing only the ’ / ’ character indicates the "default" servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.
- All other strings are used for exact matches only.
像这样:
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/view/*</url-pattern>
</servlet-mapping>
map 规则不起作用,glassfish 给出的日志如下:
[glassfish 4.0] [WARNING] [] [org.springframework.web.servlet.PageNotFound] [tid: _ThreadID=19 _ThreadName=http-listener-1(2)] [timeMillis: 1422503740955] [levelValue: 900] [[No mapping found for HTTP request with URI [/view/admin] in DispatcherServlet with name 'spring']]
应该是哪里出了问题?(我已经找到了导致此问题的原因,请继续阅读)
<小时/>有关 Spring MVC 配置和 Controller 类的其他信息
以下是评论所需的更多附加信息。
完整的web.xml
是:
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/view/*</url-pattern>
</servlet-mapping>
</web-app>
这是spring-servlet.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd ">
<mvc:annotation-driven></mvc:annotation-driven>
<context:component-scan base-package="com.ksider.service.searchserver.controller"></context:component-scan>
<bean id="freemarkerSettings" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/view/" />
<property name="freemarkerSettings">
<props>
<prop key="template_update_delay">0</prop>
<prop key="default_encoding">UTF-8</prop>
<prop key="locale">zh_CN</prop>
<prop key="url_escaping_charset">UTF-8</prop>
<prop key="whitespace_stripping">true</prop>
<prop key="date_format">yyyy-MM-dd</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="number_format">0.##</prop>
<prop key="classic_compatible">true</prop>
</props>
</property>
<property name="freemarkerVariables">
<map>
<entry key="xml_escape" value-ref="fmXmlEscape" />
</map>
</property>
</bean>
<bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/>
<!-- <property name="viewNames" value="*.ftl"/> -->
<property name="contentType" value="text/html; charset=utf-8"/>
<property name="cache" value="true" />
<property name="prefix" value="" />
<property name="suffix" value=".ftl" />
<property name="order" value="1"/>
<property name="exposeSpringMacroHelpers" value="true"/>
<property name="requestContextAttribute" value="rc"/>
</bean>
</beans>
这是 Controller :
package com.ksider.service.searchserver.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class AdminController {
@RequestMapping(value = "/view/admin", method = RequestMethod.GET)
public String getAdminPage(ModelMap modelMap){
modelMap.put("Msg","hello");
return "admin/index";
}
}
<小时/>
进度更新:
如果我使用的话,我很喜欢是什么原因造成的
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/view/*</url-pattern>
</servlet-mapping>
而不是
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/view/admin</url-pattern>
</servlet-mapping>
我应该如何为每个请求添加前缀 /view
,例如如果我想查询 http://localhost:8080/view/admin
我应该查询 http://localhost:8080/view/view/admin
。
我认为这是一个非常令人困惑的问题:-(
我只是检查了 servlet 映射引用,但无法找到为什么会发生这种情况的线索。也许应该归咎于一些Spring mvc技巧?
所以,问题变成了:
最佳答案
有两个不同的问题。
首先是 servlet 容器如何映射到 servlet。您已经正确地解释了:如果 servlet 映射到 /view/admin
或 /view/*
它同样会接收请求。
接下来是spring DispatcherServlet
如何解码和处理请求。 Servlet 规范 3.0(3.5 请求路径元素)说:
/view/admin
时,servlet 路径为 /view/admin
并且路径信息为 null/view/*
时,servlet 路径为 /view
且路径信息 ID /admin
当 DispatcherServlet 找到空路径信息时,它会在其映射中查找 servlet 路径(并找到您的 Controller ),但如果路径信息不为空,则假定 servlet 路径是不在映射中的前缀。
这就是为什么您在 /view/view/admin
下找到 Controller 的原因:第一个 /view
被 servlet 路径占用,路径信息 /view/admin
是 Controller 的映射。
当您将 DispatcherServlet
映射到 /view/*
时, Controller 映射不得包含 servlet 路径 => 您的 Controller 映射应为 /admin
关于java - spring servlet url-pattern 映射不适用于星号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28207018/
*args 和 **kwargs 是什么意思? def foo(x, y, *args): def bar(x, y, **kwargs): 最佳答案 *args 和 **kwargs 是一个常见的惯
*args 和 **kwargs 是什么意思? def foo(x, y, *args): def bar(x, y, **kwargs): 最佳答案 *args 和 **kwargs 是一个常见的惯
*args 和 **kwargs 是什么意思? def foo(x, y, *args):def bar(x, y, **kwargs): 最佳答案
在python文档中2.4.3. Formatted string literals ,似乎可以在 f 字符串的 {} 中写一个星号后跟一个表达式,但我找不到如何使用它。 那是什么以及如何使用它?它是
这些函数定义中的*args和**kwargs是什么意思? def foo(x, y, *args): pass def bar(x, y, **kwargs): pass 参见Wha
这些函数定义中的*args和**kwargs是什么意思? def foo(x, y, *args): pass def bar(x, y, **kwargs): pass 参见Wha
这个问题在这里已经有了答案: Delegated yield (yield star, yield *) in generator functions (3 个答案) 关闭 6 年前。 假设我创建了
我有时注意到使用 *偶尔搜索光标下的单词会有略微不同的行为(通常是当我在不同的计算机之间切换时)。问题是当我搜索前面有 * 的单词时(如 c++ 指针)。例如: MyPointer *foo; ...
This question already has answers here: Keyword only parameter (1个答案) Python documentation for os.re
这是我的数据: dput(dt) structure(c(15236000, 0, 0, 0, 0, 36722900, 45971100, 0, 0, 0, 0, 99067
所以我有一个看起来像这样但有 6k 行的数据框: AWC, LocationID 333, *Yukon 485, *Lewis Rich 76, *Kodiak 666, Kodiak 54, *R
我有一个简单的问题。我想列出我们可以使用关键字星号(或星号)* 的所有场景。 我只知道这些场景: Select * from Customers; Select Count(*) from Custo
瑞安·贝茨的Railscast about git ,他的 .gitignore 文件包含以下行: tmp/**/* 使用双星号后跟一个星号的目的是什么:**/*?简单地使用 tmp/* 而不是 tm
我想以这种方式选择带有 class="x"的元素的所有后代元素: .x * { color: red; } a b
这个问题在这里已经有了答案: What does ** (double star/asterisk) and * (star/asterisk) do for parameters? (25 个答案
最近我在 Programming Paradigms 上看到了这个视频和教授。使用星号、星形和符号等术语。 这就是他如何使用这些运算符的: int i = 37; float f = *(float*
我尝试在自定义按钮中居中对齐符号星号 (*),但我做不到。 如何像其他字符一样垂直居中对齐(1,2...)? 最佳答案 只需使用不同的字符。除了 * (ASTERISK U+002A),还有许多其他类
结论 概括的来说,就是对修饰的变量进行拆分, 对修饰的形式参数进行参数聚集。 单*号,将被修饰的变量按元素方式拆分, 对修饰的形式参数进行参数聚集。 双**号,将被修饰的变量按键值对进行拆分, 对
如果我想保持功能,并且不想在中间使用 *,那么等效的替代函数是什么?例如, import operator as op print(op.eq(*map(str.upper, ['a', 'A']))
我窥视 ng2-dropdown 我可以看到(ng2-dropdown-menu.ts) 除其他事项外 transition('hidden => visible', [
我是一名优秀的程序员,十分优秀!