在我的 Web 应用程序的每个页面上,我都有一个公共(public)标题。
标题.jsp :
<link rel="stylesheet" type="text/css" href="stylesheets/320x480/portrait/header.css" />
<div data-theme="b" data-role="header">
<div class="ui-grid-b">
<div class="ui-block-a">
<a id="backButton" data-role="button" data-icon="arrow-l" data-ajax="false">
<spring:message code="backButton"/>
</a>
</div>
<div class="ui-block-b">
<h3>GeoAccessibility</h3>
</div>
<div class="ui-block-c">
<div data-role="navbar">
<ul>
<li id="french">
<a id="fr" href="?language=fr" data-role="button" data-transition="fade" class="ui-btn-active">fr</a>
</li>
<li id="english">
<a id="en" href="?language=en" data-role="button" data-transition="fade">eng</a>
</li>
</ul>
</div>
</div>
</div>
</div>
地址.jsp :
<script>
$('#fr').click(function(){
alert("hello");
//treatment to follow
});
$(document).ready(function(){
alert("here");
$('#backButton').attr("href","/fdfds");
});
</script>
<body>
<div data-role="page" data-ajax="false" id="page1">
<jsp:include page="header.jsp"></jsp:include>
<div data-role="content">
<forms:form method="post" modelAttribute="address" action="/address">
<spring:message code="streetName" var="streetName" />
<forms:input path="streetName" id="streetName" placeholder="${streetName}" />
<spring:message code="streetNumber" var="streetNumber" />
<forms:input path="streetNumber" id="streetNumber" placeholder="${streetNumber}" />
<!-- Rest of the form -->
<button id="submitButton" type="submit" data-mini="true" data-inline="true" data-theme="b" data-ajax="false"><spring:message code="adressValidateBtn" /></button>
</forms:form>
</div>
</div>
用于获取 Address.jsp 或发布表单的地址 Controller :
@Controller
public class AddressController {
@RequestMapping(value="/address",method=RequestMethod.GET)
public ModelAndView init(
@RequestParam(value="language",required=false,defaultValue="fr") String language){
Locale locale = new Locale(language);
String[] isoCountries = locale.getISOCountries();
Map<String,String> treeMap = new TreeMap<String,String>();
for(String isoCountry : isoCountries){
Locale countryLoc = new Locale(language, isoCountry);
String name = countryLoc.getDisplayCountry(locale);
if(!"".equals(name)){
treeMap.put(name,name);
}
}
Map<String,String> tree = new TreeMap<String,String>(treeMap);
ModelAndView modelAndView = new ModelAndView("address");
modelAndView.addObject("address",new Address());
modelAndView.addObject("countriesList", tree);
modelAndView.addObject("previousPage","/index");
return modelAndView;
}
@RequestMapping(value="/address",method=RequestMethod.POST)
public ModelAndView validate( @RequestParam(value="language",required=false,defaultValue="fr") String language,@ModelAttribute("address") Address address, BindingResult result){
boolean ok = true;
//check-up data
return new ModelAndView("address");
}
正如您在“AddressController”类的“init”方法中所见,我添加了一个对象“previousPage”,该对象具有上一页的“url”值。我想在我的 address.jsp 中检索“previousPage”属性,以更改“后退”按钮(位于 header.jsp 中)的“href”属性。怎么做 ?
谢谢
最佳答案
像所有其他属性一样:
${previousPage}
我看不出有任何理由使用 JavaScript 来初始化链接的 href。您可以直接使用初始化它
<a href="${previousPage}" ...>
关于java - Spring 集成 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20735193/