我有一个使用Tile3的Spring MVC应用程序.我有很多静态页面需要将它们嵌入到tile3当前提供的网站模板中.(我需要在所有页面上使用相同的页脚和页眉,无论是动态还是静态,但不确定如何对静态页面进行寻址).
静态页面的示例是index.jsp和aboutus.jsp.如何访问这些静态页面?我应该通过控制器吗?
我知道我可以使用jsp:include但这是一个好习惯吗?因为我正在使用瓷砖,所以没有其他选择吗?本教程建议使用单独的控制器,但我不确定这是否是最佳解决方案.因为它向服务器发送不必要的请求.
如果有比Tiles更好的选择,请告诉我
web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<listener>
<listener-class>org.apache.tiles.extras.complete.CompleteAutoloadTilesListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springapp-servlet.xml</param-value>
</context-param>
</web-app>
Run Code Online (Sandbox Code Playgroud)
tiles.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/WEB-INF/templates/baseLayout.jsp">
<put-attribute name="title" value="Title is here (Tile)"/>
<put-attribute name="header" value="header.jsp"/>
<put-attribute name="menu" value="Title is here (Tile)"/>
<put-attribute name="body" value="Title is here (Tile)"/>
<put-attribute name="footer" value="footer.jsp"/>
</definition> …Run Code Online (Sandbox Code Playgroud) <tr class="rowsAdded">
<td><input name="item" class="form-control" type="text" placeholder="Item" /></td>
<td><input name="amount" class="form-control" type="number" placeholder="Amount" /></td>
<td><input name="expenseDate" class="form-control" type="date"placeholder="ExpenseDate" /></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
下面是我的控制器和Init Binder
@RequestMapping (value = "/saveExpenses", method=RequestMethod.POST)
public String saveExpenses (@RequestBody ExpenseDetailsListVO expenseDetailsListVO, Model model,BindingResult result) {
if (result.hasErrors()) {
System.out.println(result.getFieldError().getField().toString()+" error");
}
System.out.println(expenseDetailsListVO);
return "success";
}
@InitBinder
public void initBinder(WebDataBinder webDataBinder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
webDataBinder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
Run Code Online (Sandbox Code Playgroud)
这样我想要的日期格式不起作用,这是输出我得到的 消费日期= 3月18日05:30:00 IST 2015 但是我希望它变成像yyyy-MM-dd这样的特定格式...建议我这样做的方法.
我使用spring MVC将数据保存到数据库中.问题是当我刷新页面时它重新提交JSP页面.以下是我的代码段
<c:url var="addNumbers" value="/addNumbers" ></c:url>
<form:form action="${addNumbers}" commandName="AddNumber" id="form1">
</<form:form>
Run Code Online (Sandbox Code Playgroud)
@RequestMapping(value = "/addNumbers", method = RequestMethod.POST)
public String addCategory(@ModelAttribute("addnum") AddNumber num){
this.numSrevice.AddNumbers(num);
return "number";
}
Run Code Online (Sandbox Code Playgroud)