How is it possible to generate HTML file using Servlet/JSP?
I'm using Spring MVC to create a service. This service would get some data from the database. Then I'd like it to read a JSP template from somewhere else, not from WEB-INF. There are attributes which are the data from the database that would be passed in upon reading this template. Then it should return a string which includes the source of JSP. This string should now contain the data which replaces the JSP variables. Finally, this string should be written to a file (.html file).
I can't find a tutorial about it. Instead, i noticed mostly the JSP file is being dispatched as response and displayed on the browser.
Please help. Thannks.
You can use spring with Thymeleaf.
Thymeleaf is a Java-based library used to create a web application. It provides good support for serving an XHTML/HTML5 in web applications. In this chapter, you will learn in detail about Thymeleaf.
Tutorial from Thymeleaf:- click here
Related
In my Spring MVC application, an svg-image is to be generated by controller "on-fly" and displayed in JSP page. Is there an elegant method to do this using Spring MVC capabilities without saving the svg-image as a file?
If it were me I would have an img tag on my JSP page with a src that points to a #Controller that invokes the svg generator and returns the generated svg as a Spring Resource or as a ByteArrayInputStream (although the latter may risk OOMs).
Hi guys here i am working on a new web project(e-commerce website) in which whole project is done in java and that to only in jsp's even java code is written in jsp .Action pages are written in jsps instead of servlets and database connectivity in simple .java files.now my boss asks me to get a customized url in the browser.any help will be thankful.
EXAMPLE:
https://www.buzzmeal.com/?register=login&success=true&name=xxx&address=xxx.
this is the url which i am getting at present what i need is https://www.buzzmeal.com/regester. i tried servlet url redirection but in that way i should create servlet for each of the jsp.can any busy suggest me best way to mask a url using java.
Use .htaccess file. Here is a small tutorial with examples: http://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049
I am using Spring MVC for my web application. My views are JSP based. What is the best practice to show role based menus?
Should I make a check on the JSP page for a role?
Should I build the menu in a Java class and pass it to a JSP page to show up?
Anything else?
Use a framework like Spring Security instead of implementing the complete security infrastructure on your own. Like all other Spring modules, you would simply configure the framework declaratively using XML (for defining roles etc.) and so it's quite flexible.
Spring Security comes with its own tag library that you would then use to secure your HTML elements. For example, to make a menu item available for Admin roles only just wrap it in an appropriate <sec:authorize> tag.
References:
Spring Source is a good place to begin with. Have a look at this video as well from their YouTube channel. Getting Started with Spring Security 3.1
Make different role based menu pages and include them in you main content page at runtime.
I have an application which uses Spring for backend and ExtJs for UI.
In this application, users can have variours roles and access rights.
When a user logs in and opens a form, then depending upon her role, its decided that which fields will be displayed to her.
For handling this, we have done following two things:
1. Enclosed the JS code (code which needs to be filtered on basis of role) in spring security tags following way:
< tag start >
js code
< / tag end >
2. Saved all js files as jsp, for example, instead of having a file as test.js - we changed it to test.js.jsp. This forces the backend to parse the security tags before delivering the code to client side.
Though this works fine, but there are following issues which we are ambigous about:
a. Is this the best way of implementing such thing? What other way could this be acheived?
b. After converting js to jsp, the compression tools for JS are not able to minify it due to presence of spring security tags. Could something be done about it?
Looking forward to guidance at above.
Thanks in advance.
I'm building a web front end to monitor the state of a SOAP service.
Is there any way to serve static files with jax.ws? For example Endpoint.publish("/static", new SomeStaticFileHandler()) where any requests to /static just serve the corresponding static file in my folder? Inside the static file I would like to query the state and update the page with AJAX calls.
Thanks!
The correct way to serve static files is to add a custom servlet to the web.xml.
As for the hack you want to try: serve any file type, with any content-type? It will not work, I believe. Perhaps you can serve XML files if they follow a predefined schema -- JAX-WS implementation classes return objects, not strings or streams. These objects are serialized to SOAP/XML using the schema and binding. You'd need to parse the files into objects and then return to JAX-WS runtime... and you'll get a SOAP envelope over the file content anyway.
Inside the static file I would like to
query the state and update the page
with AJAX calls
This doesn't sound like a static file to me. This is a dynamic method serving XML or JSON. The simplest answer is still a servlet.
JAX-RS (RESTful Java API) is a viable alternative too.