JS file converting in JSP in spring - java

I want to convert spring application into angular js. I am using some external css and js.
css is included properly but not js.
when I use
<script src="bower_components/angular/angular.min.js"></script>
It is considering angular.min.jsp and throwing error not found.
How to include external js into my app.

It seems as some misconfiguration on the server side.
I would suppose that you are using Apache 2.4 or Tomcat 7
In Apache 2.4 take a look at https://httpd.apache.org/docs/2.4/rewrite/remapping.html
If you were running the application in the ubuntu then default location to look at would be /etc/apache2 and usually this is going to be found in /etc/apache2/sites/available/000-default.conf
In Tomcat 7 take a look at
https://tomcat.apache.org/tomcat-8.0-doc/rewrite.html
Under Ubuntu with the default installation of Tomcat, this information will be found either in the file /var/lib/tomcat7/conf/server.xml or under the directory your application is deployed in META-INF/context.xml or under /var/lib/tomcat7/Catalina in one of the subdirectory. This depends a lot on the settings you have.
If neither of these is a case then take a look at the filters applied to the application as some of them can screw the answer. For them take a look at WEB-INF/web.xml or if you are using the XML-less configuration then try Some of the I believe SpringWebApplication classes.
If you still use the Spring to serve the backend then it is also possible that you have incorrectly set up ViewResolver, which returns .jsp as appendix instead of .js

Related

Can we safely put `tomcat.addTldSkipPatterns("*.jar")` for a pure back-end spring boot service using embedded tomcat

Tomcat looks for *.tld files during startup within the entire class-path. For a production application, the classpath can be huge and this ends up consuming 10s during startup. I already know that tomcat logs the path that it tried searching for and could not find the TLDs, however, I came across this in the TLD docs (https://docs.oracle.com/javaee/5/tutorial/doc/bnamu.html):
If you want to redistribute your tag files or implement your custom tags with tag handlers written in Java, you must declare the tags in a tag library descriptor (TLD). A tag library descriptor is an XML document that contains information about a library as a whole and about each tag contained in the library. TLDs are used by a web container to validate the tags and by JSP page development tools.
The service in contention is a pure backend-service and there are no JSP pages being served and no tag files being used and all the spring configuration is Java based. Would then it be fine to just add this option in EmbeddedServletContainerFactory:
tomcat.addTldSkipPatterns("*.jar")
(or similar config in application.properties)
If you have no JSPs anywhere in your application, setting TLSjavasToSkip=*.jar is safe.
Note that classpath-scanning happens for a bunch of other reasons, too, so I tend to agree with #M.Deinum's comment that you probably won't see much of an improvement just by disabling TLD scanning.

How to apply filter to the request to resource which are directly under webapps

I want to apply filter in below URL's.
http://10.78.97.29/robots.txt
http://10.78.97.29/sitemap.xml
https://10.78.97.29/
Since they does not contain any specific URL pattern , I am not getting any idea. And in which web.xml I have to add that filter mapping. I am using Tomcat as a webcontainer.
Thanks in advance.
Tomcat by default uses the web application named ROOT to serve the application at the root folder of the server. You can either handle the requests there or just have the files contained in the web application.
You might want to read about tomcat naming for more details, explaining this behaviour.
Alternatively, you can also have an Apache httpd in front of your tomcat and handle those files there.

Use Spring 3 filters to embed timestamp in resource paths?

Would it work to setup some filters using Spring 3 MVC where the paths for javascript files and css files are modified when streamed to the client, by embedding some timestamp in the filename. And then when those resources are later requested another filter then strips those timestamps out?
This would be an attempt to prevent problems of cached js/css files when an application is redeployed
What would I need to do to set this up? How do I setup the filter to replace the paths with a timestamp and then how to I setup the filter to later strp the timestamps out?
I just need info on the Spring 3 MVC configuration for it in the web.xml, I am ok with what the actual code in the filter will need to do
It may be simpler to use Spring's resource mapping <mvc:resources>, that maps a virtual path to the real location of your CSS and Javascript files. The virtual path can contain the version of your application. This means that when you deploy a new version of your application, the path of the CSS and Javascript that gets sent to the browser is different than before and this fools the browser into thinking that they're new resources - and so it reloads them.
For example to map CSS and Javascript files in /resources:
<mvc:resources location="/resources" mapping="/resources-1.2.0/**"/>
This says that any request that comes in with the URL pattern /resources-1.2.0 followed by anything (e.g. /resources-1.2.0/css/styles.css), look for the file in the folder named resources in the web root.
When you update the application version between deployments the virtual path to the CSS and Javascript resources will change and so browsers will be forced to reload the files - even though the real files are in the same old location.
You can make the application version dynamic too - so you don't need to modify your config file.
There's a more in-depth write up of this whole approach here.

Glassfish embedded with ScatteredArchive and web content

I'm running Glassfish 3.1.2 embedded to unit test my application. I set up a ScatteredArchive like this:
archive.addClassPath(new File("target/classes"));
archive.addClassPath(new File("src/test/resources"));
archive.addMetadata(new File("src/main/webapp/WEB-INF/web.xml"));
In this way glassfish can find the servlets that are specified in the web.xml. Unit testing these works perfect. However, what glassfish can't find are any web contents, like javascript, images, etc.
How do I tell a ScattedArchive where the web contents are?
You can use a different constructor for the ScatteredArchive:
ScatteredArchive(String name,ScatteredArchive.Type type,File topDir)
which is described very briefly in the Oracle GlassFish Server 3.1.2 Embedded Server Guide for release 3.1.2. The topDir parameter is used to point to the 'top' of the archive, which would be the root directory of your war file. That is where your web content would usually be.

felix exthttpservice set session path for cookies

I have a webapplication that I am running in Felix osgi container. I am using jetty as the implementation for the extHttpService. Currently it is writing the cookies to the '/' root path. I would like to change this as it is causing conflicts with other web applications. Looking at jetty documentation it appears I need to set the following property.
org.mortbay.jetty.servlet.SessionPath
However, I am unable to find a way to set this using the ExtHttpService via osgi. I have tried creating a jetty.xml file, adding this to the config.properties, and setting it as a property in the call to register my servlet.
Does anyone know how to set this?
thanks,
I actually ended up patching the source for my current implementation, but on the mailing lists here, a patch has been submitted that should allow this to be configurable.

Categories