Java 为什么将pageContext.request.contextPath解释为$%7BpageContext.request.contextPath%7D?
我正在使用纯Java配置编写一个简单的基于REST的SpringMVC应用程序。我以前写过很多应用程序,从来没有遇到过这个问题。 我的urlJava 为什么将pageContext.request.contextPath解释为$%7BpageContext.request.contextPath%7D?,java,spring,spring-mvc,jsp,Java,Spring,Spring Mvc,Jsp,我正在使用纯Java配置编写一个简单的基于REST的SpringMVC应用程序。我以前写过很多应用程序,从来没有遇到过这个问题。 我的url 被解释为 $%7BpageContext.request.contextPath%7D/test/hello 在研究中,我发现我需要将web应用程序的版本设置为2.4+ 在编写纯java配置应用程序时,我无法在web.xml中更改它。 因此,我尝试将动态Web模块更改为3.0(当前设置为2.3)。 但是,由于许多人都面临这个问题,eclipse不允许我更改
被解释为
$%7BpageContext.request.contextPath%7D/test/hello
在研究中,我发现我需要将web应用程序的版本设置为2.4+
在编写纯java配置应用程序时,我无法在web.xml中更改它。
因此,我尝试将动态Web模块更改为3.0(当前设置为2.3)。
但是,由于许多人都面临这个问题,eclipse不允许我更改它。
因此,我在project.facet.core.xml中对其进行了更改,但它没有解决url问题,而且我还遇到了一个新错误“无法将project facet动态Web模块的版本更改为2.3”
我不明白的是,如果我手动将web模块的xml版本设置为3.0,为什么eclipse会再次尝试设置为2.3
Ufff!!!很多问题
我已经尝试解决这个问题大约8个小时了,但没有任何成功,所以请在这件事上提供任何帮助,我们将不胜感激
jsp文件:
<html>
<body>
<h2>Hello World!</h2>
<a href="mavn_spring_rest_demo/test/hello">try it </a>
</body>
</html>
你好,世界!
配置类:
```@EnableWebMvc
```@ComponentScan("com.org")
```public class MyConfig implements WebMvcConfigurer{
```}
servlet initializer class:
```public class MyServletInitializerConfig extends
```AbstractAnnotationConfigDispatcherServletInitializer {
```@Override
```protected Class<?>[] getServletConfigClasses() {
```return new Class[] { MyConfig.class };
```}
```@Override
```protected String[] getServletMappings() {
```return new String[] { "/" };
```}
rest controller:
```@RestController
```@RequestMapping("/test")
```public class MyRestController {
```@GetMapping("/hello")
```public String sayHello() {
return "hello finally";
```}
```}
``@EnableWebMvc
```@组件扫描(“com.org”)
```公共类MyConfig实现WebMVCConfiguer{
```}
servlet初始值设定项类:
```公共类MyServletInitializerConfig扩展
```AbstractAnnotationConfigDispatchersServletInitializer{
```@凌驾
```受保护类[]getServletConfigClasses(){
```返回新类[]{MyConfig.Class};
```}
```@凌驾
```受保护的字符串[]getServletMappings(){
```返回新字符串[]{”/“};
```}
休息控制器:
```@RestController
```@请求映射(“/test”)
```公共类MyRestController{
```@GetMapping(“/hello”)
```公共字符串sayHello(){
返回“hello finally”;
```}
```}
您应该删除web.xml文件并重新启动本地服务器,我认为您和我遵循相同的路线。我遇到这个问题是因为我有一个空的web.xml文件。我是一个新手,但在配置普通java类时,空的web.xml文件会造成阻碍
试一试。你应该删除web.xml文件并重新启动本地服务器,我想你和我的做法是一样的。我遇到这个问题是因为我有一个空的web.xml文件。我是一个新手,但在配置普通java类时,空的web.xml文件会造成阻碍
试一试。当我在jsp文件中使用
{pageContext.request.contextPath}
时,我遇到了同样的问题,正如您所说的问题是(web app at 2.3),我通过在web.xml
中修改xml代码来解决这个问题
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>spring-rest-demo</display-name>
</web-app>
春季休息演示
您可以将此代码复制到web.xml
文件中
希望这对你的项目有用当我在jsp文件中使用
{pageContext.request.contextPath}
时,我也遇到了同样的问题,正如你所说的问题是(web app at 2.3),我通过在web.xml
中修改xml代码来解决这个问题
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>spring-rest-demo</display-name>
</web-app>
春季休息演示
您可以将此代码复制到web.xml
文件中
希望这对您的项目有用虽然还不清楚为什么您的表达式无法解析,但我建议您编写
${request.contextPath}
。无需在此处查看pageContext对象。感谢@Mick的响应,但现在是$%7Brequest。contextPath%7d JSP处理器似乎没有启动。请发布完整的JSP源代码。尤其是标题行。@Mick用完整的JSP文件更新了op。这是默认情况下创建的基本文件,我只是在运行时添加了URL不清楚为什么没有解析表达式,我只是建议编写${request.contextPath}
。无需在此处查看pageContext对象。感谢@Mick的响应,但现在是$%7Brequest。contextPath%7d JSP处理器似乎没有启动。请发布完整的JSP源代码。尤其是标题行。@Mick用完整的JSP文件更新了op。这是默认情况下创建的基本文件,我刚刚添加了url