I am trying to clean up an application which is written in jsp servlet and javascript, jquery. Currently in the jsp's, there are lots of javascripts written. I am trying to move all these javascripts to a separate js file. In the jsp, it's getting the contextPath through javascript and then doing some logic using this contextPath. Is it possible to get the context path in the javascript ? Also it's using some code like this in jsp..How can I move this code to js file?
HTML
<input type=button id=cntButton value=CONTINUE onclick=javascript: callTest('<%=request.getContextPath()%>/test1/test2/test3.do');/>
function callTest(pageURL){
}
If I move function callTest(pageURL) to a javascript file, how can I pass the contextPath from the jsp?
Update 2
In the jsp,
<%
String firstName= ;
if (sampleBean.getName() != null) {
firstName = sampleBean.getName();
}
%>
<script type=text/javascript>
window.onload=loadVal;
function loadVal() {
document.getElementById('business_name').value = <%=firstName%>;
}
</script>
I need to move this loadVal() to another js file. So how can I pass this <%=firstName%> which is fetched from the bean?