创建了一个应用程序。页面A显示包含值列表的下拉列表。如果用户点击特定帐户,将显示图表。我们有类似的按钮权限到帐户下拉列表。这些是独立的JSP。如果用户点击了页面A,那么所选的帐户名称应该移动到那些4个jsp页面。我试过过URL。但没有得到。请帮忙。
JSP 1
<a id="priorityCallAnalysis" class="item"> <button type ="button" onclick="getPriorityCall()">Priority </button> </a>
<form:form action="somepage" method="post" commandName="somedata"
id="taskDetails" enctype="multipart/form-data">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Choose Account*</label>
<form:select path="accountName" class="form-control"
id="accountName" onchange="getDashboard()">
<form:option value="" label="--select--"></form:option>
<c:forEach items="${accountList}" var="accountName">
<form:option value="${accountName}" label="${accountName}"></form:option>
</c:forEach>
</form:select>
</div>
</div>
</div>
</form:form>
function getPriorityCall()
{
var accountName = $("#accountName").val();
alert(accountName);
window.location="priorityCall.html?accountName="+accountName+"";
}
控制器
@RequestMapping(value="/priorityCall")
public ModelAndView priorityCall(Map<String, Object> model,@RequestParam ("accountName") String accName)
{
System.out.println("entry");
SampleBean template = new SampleBean ();
model.put("template ", template );
List<String> accountList = Service.getAccountList();
model.put("accountList", accountList);
model.put("accName", accName);
return new ModelAndView("analByPrior","","");
}
JSP:analByPrior
<form:form action="#" method="post" commandName="somedata"
id="taskDetails" enctype="multipart/form-data">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Choose Account*</label>
<form:select path="accountName" class="form-control"
id="accountName" onchange="getAssignmentGroups()">
<form:option value="" label="--select--"></form:option>
<c:forEach items="${accountList}" var="accName">
<form:option value="${accName}" selected="true"> ${accName}</form:option>
</c:forEach>
</form:select>
</div>
</div>
</div>
</form:form>
更新 点击优先按钮,这个控制器被调用,而不是优先呼叫..我不知道y ..
@RequestMapping("/priorityCallAnalysis")
public String someAction(@ModelAttribute("accountName") TicketInfo data, Map<String, Object> map,
HttpServletRequest request) {
TicketInfo somedata = new TicketInfo();
map.put("somedata",somedata);
System.out.println(somedata);
System.out.println("acc=" + request.getParameter("accountName"));
/* do some process and send back the data */
map.put("somedata", data);
map.put("accountName", request.getParameter("accountName"));
return "analysisByPriority";
}
答案 0 :(得分:0)
首先在 .jsp文件中,您可以使用全局变量来存储上下文路径,并将此变量用作所有相对路径中的前缀。
<script>var context = "${pageContext.request.contextPath}"</script>
现在在你的js函数中使用上下文路径并调用控制器。
function getPriorityCall(){
var accountName = $("#accountName").val();
alert("contextPath: "+context); // will print your {appName}
window.location=context+"/priorityCall?accountName="+accountName;
}
因此,您的URI在请求调用中如下所示。
http://localhost:8080/{appName}/priorityCall?accountName={acountName}
PS:
${pageContext.request.contextPath}
的好处是,如果您稍后更改appName,则无需在视图中更改它。它将自动获取最新的contextPath。