我正在使用spring mvc和apache tiles做一个web应用程序,我有下一个:
项目
| __WebContent
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
| __index.jsp
在app-config.xml中:
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:insertAttribute name="title" ignore="true" /></title>
</head>
<body>
<div><tiles:insertAttribute name="header" /></div>
<div style="float:left;padding:10px;width:15%;"><tiles:insertAttribute
name="menu" /></div>
<div style="float:left;padding:10px;width:80%;border-left:1px solid pink;">
<tiles:insertAttribute name="body" /></div>
<div style="clear:both"><tiles:insertAttribute name="footer" /></div>
</body>
</html>
我的layout.jsp:
<tiles-definitions>
<definition name="base.definition" template="/WEB-INF/view/layout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="header" value="/WEB-INF/view/header.jsp" />
<put-attribute name="menu" value="/WEB-INF/view/menu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/view/footer.jsp" />
</definition>
<definition name="home" extends="base.definition">
<put-attribute name="title" value="Home" />
<put-attribute name="body" value="/WEB-INF/view/home.jsp" />
</definition>
</tiles-definitions>
我的tiles.xml:
@Controller
public class HomeController {
@RequestMapping(value="/home")
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
return new ModelAndView("home");
}
我的控制器:
try
{
if (TryUpdateModel(theEvent))
{
storeDB.SaveChanges();
return RedirectToAction("Index");
}
}
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
{
Exception raise = dbEx;
foreach (var validationErrors in dbEx.EntityValidationErrors)
{
foreach (var validationError in validationErrors.ValidationErrors)
{
string message = string.Format("{0}:{1}",
validationErrors.Entry.Entity.ToString(),
validationError.ErrorMessage);
// raise a new exception nesting
// the current instance as InnerException
raise = new InvalidOperationException(message, raise);
}
}
throw raise;
}
当我输入good base时,它给出了错误:
http 404 /unqui.tip.vista/WEB-INF/view/layout.jsp
泰
答案 0 :(得分:1)
这可能是您编写时的拼写错误,但您在tiles.xml中的正文值应为:
<put-attribute name="body" value="/WEB-INF/views/home.jsp" />
由于您的home.jsp位于views文件夹中,因此您需要最后的s。您需要更新所有tiles.xml路径以说出视图。