【问题标题】:How to include jsp pages using Spring form tag?如何使用 Spring 表单标签包含 jsp 页面?
【发布时间】:2013-03-19 20:16:38
【问题描述】:

我正在使用 Spring,因为我有 user.jsp

user.jsp 有三个独立的部门:1. 个人部门,2. 教育部门,3. 奖项。每个部分都有我创建的不同表单 .jsp。

现在我正在考虑将这三种形式包含在user.jsp 中,并使用一个控制器显示模型。

这是我的控制器类代码:

@Controller
@RequestMapping(value="profile")
public class UserProfileController {

    @RequestMapping(value="user", method=RequestMethod.GET)
    public String user(Model model) throws Exception {
        model.addAttribute("profile", new PersonalForm());

        return "profile/user";
    }

这是我的 Personal.jsp 文件(所有剩余的文件都相同,但名称不同)

那么如何将这三个jsp包含到user.jsp中呢?实际上我正在尝试,但 Eclipse 显示错误。以下是我在user.jsp 中的错误代码:

片段“profile/professional.jsp”未在 预期路径/EClass/WebContent/WEB-INF/ pages/profile/profile/professional.jsp

那么请帮助我如何包含以及如何使用单个控制器?

【问题讨论】:

  • 能否请您从您的上下文 xml 文件中发布视图解析器配置?
  • @Jeevan patil .. 一旦看到我的编辑代码..
  • 我没有看到你在其他 jsp 的任何地方都包含了 professional.jsp。那你怎么会得到这个错误呢?

标签: java spring jsp spring-annotations


【解决方案1】:

在您的 User.jsp 中编写以下代码...

        <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<fieldset id="profile_proffiesional">
    <form:form action="profile/user" modelAttribute="profile">
        <jsp:include page="personal.jsp"></jsp:include>
        <jsp:include page="educational.jsp"></jsp:include>
        <jsp:include page="awards.jsp"></jsp:include>
    </form:form>
</fieldset>

【讨论】:

    猜你喜欢
    • 2011-01-14
    • 1970-01-01
    • 2021-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多