相关疑难解决方法(0)

在JSP视图中,Spring 3.0.6 MVC @PathVariable和@RequestParam为空/空

我一直试图设置一个非常简单的控制器/视图,但是无法使其工作.在我web.xml,我已经定义了一个<servlet>名为servlet-context.xml,运行正常.在servlet-context.xml,我设置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"

<...other stuff in here... />

<mvc:annotation-driven />
Run Code Online (Sandbox Code Playgroud)

除其他事项外.我的理解是这就是使用@注释所需要的一切.

在我的控制器中,我有:

@RequestMapping(value="/student/{username}/", method=RequestMethod.GET)
public String adminStudent(@PathVariable String username, @RequestParam String studentid) {
    return "student";
}
Run Code Online (Sandbox Code Playgroud)

在我student.jsp看来,我有:

<p>This is the page where you would edit the stuff for ${username}.</p>
<p>The URL parameter <code>studentid</code> is set to ${studentid}.</p>
Run Code Online (Sandbox Code Playgroud)

当我发出请求时http://localhost:8080/application/student/xyz123/?studentid=456,我得到了我期望的视图,但所有变量都是空白或为空:

<p>This is the page where you would edit the stuff for .</p>
<p>The URL …
Run Code Online (Sandbox Code Playgroud)

spring spring-annotations spring-3

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

标签 统计

spring ×1

spring-3 ×1

spring-annotations ×1