无法通过spring MVC加载iframe

时间:2015-05-13 06:43:00

标签: spring-mvc iframe

我点击链接旁边的iframe / frame应该打开几个链接。我有一个控制器类,它有控制代码。

UserAccount.jsp

<html>
<head>
<base target="frame1">
<style>
h1 {
    text-align: center;
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    margin-bottom: 5%;
    color: #0000FF;
    font-weight: bold;
}

h3 {
    color: navy;
}
iframe{margin-top:-50%;margin-left:15%;width:100%;height:300px;}
</style>


</head>

<body>
    <h1>Online banking</h1>
    <div>
        <h3>Account Details</h3>
        <a href="/AccountSummary" target="frame1">Account Summary</a>
        <br/><a href="">Account Statement</a>
    </div>

    <div>
        <h3>Transactions</h3>
        <a href="">Transfer Funds</a>
        <br/><a href="">Deposit</a>
        </div>
    <div>
        <h3>My Profile</h3>
        <a href="">Edit Profile</a>
        <br/><a href="">Change Password</a>

    </div>

 <iframe src="myframe.jsp" name="frame1"></iframe>

</body>
</html>

UserController.java

@RequestMapping(value = "/UserAccount", method = RequestMethod.GET)
    public ModelAndView displayUserAccount() {


        ModelAndView model1 = new ModelAndView("UserAccount");

        return model1;
    }
    @RequestMapping(value = "/AccountSummary", method = RequestMethod.GET)
    public ModelAndView displayAccountSummary() {


        ModelAndView model1 = new ModelAndView("AccountSummary");

        return model1;
    }

问题在于,当我点击AccountSummary时,它显示HTTP状态404错误。我无法理解我在编码时遗漏的内容。请帮助

以下是我的调度员servlet:

<bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

这是我的项目文件截图: BankProject-files

1 个答案:

答案 0 :(得分:2)

假设UserAccount - 页面包含网址example.com/bankproject/UserAccount,此链接

<a href="/AccountSummary" target="frame1">Account Summary</a>

指向网址example.com/AccountSummary。 将href - 属性的值更改为./AccountSummary

浏览器相对于URL域解析以单个/开头的相对URL;您需要一个相对于当前目录的URL(前缀./),因为请求映射是在同一个控制器中定义的。