i made a servlet using java-ee (know as: j2ee)
the mvc is a controller (java), and views (html-js-css) pages
i hava a controller that mapping the url
like ...../controller/index.jsp
so if we navigate this, index.jsp will opened and all the js & css it need.
when user click on a button in the page, it will open an Ajax connection to the controller.
like i saw here:
calling a java servlet from javascript
$.get('../controller/url_to_mapped?firstStringParameter=aaa, function(responseData) {
});
for example: in the link i wrote below i send a string parameter called firstStringParameter and it's value is aaa.
how do i send a variable and not just a string parameters from js file??
if it's only in html code so we was write <% request.setAttribute("key", value)%>
but, in js i cant write java code.
edited:
Add some code:
servlet.java:
public class servlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/test.jsp").forward(request,response);
    }
}
test.jsp:
<%@ page language="java" contentType="text/html; charset=windows-1255" pageEncoding="windows-1255"%>
<!DOCTYPE html>
<html>
<head>
        <script src="test.js"></script>
    </head>
    <body>
        <% String param = "foo";%>
    </body>
</html>
test.js
var param_js_context = '<%=param%>';
alert(param_js_context);
and the alert result was: <%=param%> as is.
 
     
     
    