Java Spring return Javascript -



Java Spring return Javascript -

i'm creating plugin website embed , display, similar disqus. have pretty thought , understanding on how works on client side post: how create javascript disqus or intensedebate.

so code i'm planning utilize on client side similar disqus or google analytics:

<script type="text/javascript"> var user_id = 'anbmdj3ish43'; (function() { var plug = document.createelement('script'); plug.type = 'text/javascript'; plug.async = true; plug.src = 'http://www.example.com/user/' + user_id; (document.getelementsbytagname('head')[0] || document.getelementsbytagname('body')[0]).appendchild(plug); })(); </script>

for each page of website plugin displayed different need alter content of javascript code returned page (i.e. have alter injected code, design of plugin,etc.). utilize java , spring framework back-end since rest of application utilize these technologies.

so question following: within spring controller, have able homecoming javascript understood browser? or, might on wrong way , have handle different way?

below 1 of first guess sends text/plain , it's not understood browser javascript..

@controller @requestmapping(value = {"/user/"}) public class embedjavascriptcontroller extends abstractcontroller{ @autowired private service service; @transactional @requestmapping(value = "/{userid}", method = requestmethod.get, produces="text/javascript; charset=utf-8") public string home(httpservletrequest request,httpsession session, @pathvariable("userid") string userid) throws exception { homecoming "console.log('i wanna load scripts');"; } }

any help appreciated :d

i had same issue , resolved using technique.

you can homecoming modelandview resolves jsp using internalresourceviewresolver. jsp hold of javascript contents want return. add together line top of jsp.

<%@ page language="java" contenttype="application/javascript; charset=utf-8" pageencoding="utf-8"%>

java javascript spring spring-mvc

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -