I am using the new Servlet 3.0 approach of packaging web resources (such as Javascript, CSS, and JSPs) in JAR files. The approach says that everything under JARROOT/src/META-INF/resources will get mounted to the WAR root when the application starts. All works file for CSS and Javascript but not so much for Struts tiles.
This is the structure I have in the JAR:
base.jar
|--src/
|----META-INF/
|------base.tld
|------resources/
|--------base/
|----------css/
|----------js/
|----------baseTiles.xml
In my application (WAR) web.xml I got this for the tiles:
<context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles.xml,/base/baseTiles.xml</param-value>
</context-param>
When I start my application I do not get any errors about the baseTiles.xml so I assume it would the tiles files. However, trying to reference a tile from a JSP (using the <tiles:insertAttribute> tag) fails with
org.apache.tiles.jsp.taglib.NoSuchAttributeException: Attribute 'base.nav' not found.
What do you think the is?
Summary and other info:
Using JBoss eap 6.1 Alpha
Using Struts 2.1.4
The base JAR is included with the WAR in the lib directory
The base JAR contain all the files mentioned above (including baseTiles.xml)
Thank you for your help!!
Problem solved! Must point to the right Schema in your web.xml...
<web-app version="3.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app_3_1.xsd">
Now everything works automagically !!
It is the right schema definition for 3.1 servlet specification:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
Related
I have this configuration in my application.yml
server:
contextPath: /appname
session:
timeout: 7200 # 2 hours in seconds
This works fine when i run in Intellij IDEA, but when i deploy the build .war file to a tomcat instance this is ignored. Is this a bug or is it not expected to work like this?
Also i seem to be unable to locate a specification of what can be written in application.yml. Anyone know where this can be found?
How about the application.groovy config file? Cant seem to locate a specification for this?
My environment:
Grails version: 3.2.8
Gradle version: 3.4.1
Intellij IDEA version: 2017.1.2
Tomcat version: 8.0.26
JDK Version: 1.8.0_45
When you deploy a Grails 3 app to a standalone tomcat application you should not use springboot server.session.timeout configuration property. That it is only for an embeedded server.
To configure a session timeout in a SpringBoot app (Grails 3 app is built on top of SpringBoot app) deployed into a standalone tomcat you have two choices:
A) Timeout for every app deployed in that tomcat instance.
You could edit the session timeout directly in tomcat configuration files:
$TOMCAT_HOME/conf/web.xml
Look out for the block:
<!-- ==================== Default Session Configuration ================= -->
<!-- You can set the default session timeout (in minutes) for all newly -->
<!-- created sessions by modifying the value below. -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
B) You can add a web.xml file in your Grails 3 app, with the timeout you need per app.
Create a file in the path 'src/main/webapp/WEB-INF/web.xml' with the content:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
C) You can also use tomcat's HttpSession setMaxInactiveInterval(seconds) method to set in your Groovy code.
if (grailsApplication.config.getProperty("session.timeout")?.isInteger())
// session timeout in seconds
session.setMaxInactiveInterval(grailsApplication.config.session.timeout as int)
Note that with the (current latest) Grails 5.x and spring boot 2.5 the correct property name is server.servlet.session.timeout and hence the application.yml config would go like this:
server:
servlet:
session:
timeout: 3600 #seconds
Spring boot docs:
https://docs.spring.io/spring-boot/docs/2.5.5/reference/html/application-properties.html#application-properties.server.server.servlet.session.timeout
I have followed this blog: A programmer's blog. All upload images go to
Z:\glass_server_upload and I added a file named ImageView#img.xml in the tomcat C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\Catalina\localhost. And the file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="Z:/glass_server_upload" reloadable="true" crossContext="true" path="/ImageView/img" debug="9"></Context>
And now I want to display the images, so I enter the browser like this: localhost:8080/ImageView/img/pulpit.jpg.
But the result is sadly 404.
According to the post the file should be
<Context docBase="Z:/glass_server_upload">
</Context>
What do you need to do:
Locate $CATALINA_BASE/conf/Catalina/localhost
Create a textfile there named ImageView#img.xml with the contents above
Start/restart Tomcat
Enter in the browser via http://localhost:8080/ImageView/img/yourimage.jpg
if the file exists and you have permission to read the file, then it will be shown.
We're running grails 2.0 + jetty 7.6.6 and need to set JSESSIONID cookie to be httpOnly.
All of the answers on stackoverflow seem to refer to either Servlet 3.0 (which requires jetty 8) or to tomcat.
Can anyone provide me with a clear way of setting the JSESSIONID cookie be httpOnly for jetty 7.x?
I have tried adding jetty-web.xml file with the following contents, but it still didn't work (i.e. the JSESSIONID wasn't marked as httpOnly):
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Get name="sessionHandler">
<Get name="sessionManager">
<Set name="httpOnly" type="boolean">true</Set>
</Get>
</Get>
</Configure>
All I had to do is to put the jetty-web.xml in the right folder. Initially I was putting into jetty/etc folder, but instead it should have been in the WEB-INF directory.
Is there an issue to set the app.servlet.version to 3.0 in the application.properties for grails 2.0?
I created a new app, added the line app.servlet.version=3.0 to the application.properties and executed grails war (even tried clean before). However the web.xml still starts with:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Iwould have expected to see 3.0. I also tried this Procedere with 2.4 and it is still 2.5. Is it the wrong place, which I am looking at?
It looks like, that you need to change the BuildConfig.groovy as well, in order to achieve servlet version 3.0 in your web.xml. Add the following line into a plain grails project and the web.xml will start with desired version 3.0:
grails.servlet.version = "3.0"
Recently I have explored the possibilities to integrate a regular JSF 2.0 application as a portlet a portlal.
The first thing I've done is downloaded Pluto 2.0 (bundled with tomcat) and Myfaces Portlet Bridge 2. I have created a small webapp (Core JSF 2.0 chapter 2 quiz application).
As I saw from the tutorials I have created portlet.xml file in WEB-INF with the following content:
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
<portlet>
<portlet-name>QPortlet</portlet-name>
<portlet-class>javax.portlet.faces.GenericFacesPortlet</portlet-class>
<expiration-cache>0</expiration-cache>
<init-param>
<name>javax.portlet.faces.defaultViewId.view</name>
<value>faces/index.xhtml</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<supports>
<mime-type>application/xhtml+xml</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<portlet-info>
<title>QPortlet</title>
<short-title>QPortlet</short-title>
</portlet-info>
</portlet>
</portlet-app>
Then I added several lines in the web.xml:
<servlet>
<servlet-name>QPortlet</servlet-name>
<servlet-class>org.apache.pluto.container.driver.PortletServlet</servlet-class>
<init-param>
<param-name>portlet-name</param-name>
<param-value>QPortlet</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>QPortlet</servlet-name>
<url-pattern>/PlutoInvoker/QPortlet</url-pattern>
</servlet-mapping>
Have copied the corresponding bridge Jar to the lib folder, packaged as war file and deployed to Pluto. Pluto itself recognized my webapp as a portlet. Cool but when I opened the window with the portlet it was just empty. The web application works nice separately, But not as a portlet.
I have tried the examples from MyFaces but the most I can get is the following exception:
Error rendering portlet portlet-bridge-carstore.
java.lang.IllegalArgumentException: Only supported in a portlet environment
at org.apache.myfaces.portlet.faces.util.map.PortletRequestMap.(PortletRequestMap.java:42)
…
Am I doing something wrong?
I have also tried JBoss Portlet Bridge, but I get the same result…