web.xml

What is the difference between session-timeout and max-age in web.xml?

本小妞迷上赌 提交于 2019-12-19 06:14:11
问题 I am not sure if I understand: <session-config> <session-timeout>30</session-timeout> <!-- 30 minutes! --> <cookie-config> <http-only>true</http-only> <max-age>1800</max-age> <!-- 1800 seconds: 30 minutes! --> </cookie-config> <tracking-mode>COOKIE</tracking-mode> </session-config> Also, is there any way to configure ALL cookies in web.xml? This seems to apply to session cookies only. Do I need a filter for such feature? 回答1: Why do we even need this? Quoting the Servlet 3.0 specification: In

Dependency Injection inside of HttpSessionListener implementation

两盒软妹~` 提交于 2019-12-19 04:15:25
问题 Problem: This injected dependency will always return 0 from SimpleController Why does the context get lost for this bean when trying to do dependency injection into an HttpSessionListener implementation? What is principles behind this am I missing/confusing for this not to be working? How do I fix this? Project on Github webApp project Source Consider the following: SessionCounterListener public class SessionCounterListener implements HttpSessionListener { @Autowired private SessionService

context.xml vs web.xml in web application

纵饮孤独 提交于 2019-12-18 13:27:17
问题 I am developing a small web application application. The objective is to create one welcome index.html page with Ajax + one servlet to handle ajax requests. Although I thought I would be fine with a web.xml only, I don't want to deploy to / , but to /MyApp . NetBeans's project properties offers options to set a context path, which helps me deploying to /MyApp . However, it automatically adds a /META-INF/context.xml file, which is a bit confusing. My questions are: 1) Do I really need a

Filter mapping url-pattern that excludes subdirectories

僤鯓⒐⒋嵵緔 提交于 2019-12-18 12:40:46
问题 Is there any way to make a filtermapping not include subdirectories? For example. I have .xhtml files in my context root, and I also have a subfolder named "test" with files with the same extension. Is there any may to map a filter to the files in context root and not to the files in the "test" directory? 回答1: The url-pattern is indeed restrictive in matching. It only allows exact, prefix or suffix matchnig. Not midst/overall/regex matching. So e.g. /*.xhtml what you intend to do ain't going

load-on-startup Tomcat

前提是你 提交于 2019-12-18 11:48:05
问题 How can I load a class on startup in Tomcat? I saw load-on-startup tag for web.xml file, but can I use it and how should I write my class? EDIT: How can I implements this class and xml? <servlet-name>??</servlet-name> <servlet-class>??</servlet-class> <load-on-startup>10</load-on-startup> 回答1: Those are meant to specify the loading order for servlets. However, servlets are more meant to control, preprocess and/or postprocess HTTP requests/responses while you sound like to be more looking for

Can you render a file without a .jsp extension as a JSP?

梦想的初衷 提交于 2019-12-18 07:40:13
问题 Is it possible to tell a standard Java EE servlet container to interpret and render a file as a JSP even if it doesn't have a .jsp extension? Say I have a file called foo.xyz in the root directory of my WAR. This file contains some jstl logic as you would expect in a .jsp file. If I request http://myserver/myapp/foo.xyz I'm going to see the literal code from that file rendered as text. Is there a way to configure the web app such that it renders the file using the JSP interpreter without

How to retrieve <servlet><init-param> value from web.xml in Servlet?

房东的猫 提交于 2019-12-18 07:02:28
问题 I need to retrieve init-param value from xml to Servlet i used following code <servlet> <servlet-name>LoginServlet</servlet-name> <servlet-class>LoginServlet</servlet-class> <init-param> <param-name>jdbcDriver</param-name> <param-value>com.mysql.jdbc.Driver</param-value> </init-param> </servlet> servlet code public void init(ServletConfig config) throws ServletException { super.init(config); System.out.println(config.getInitParameter("jdbcDriver")); } But It displayed null .. could any one

How to retrieve <servlet><init-param> value from web.xml in Servlet?

时间秒杀一切 提交于 2019-12-18 07:01:02
问题 I need to retrieve init-param value from xml to Servlet i used following code <servlet> <servlet-name>LoginServlet</servlet-name> <servlet-class>LoginServlet</servlet-class> <init-param> <param-name>jdbcDriver</param-name> <param-value>com.mysql.jdbc.Driver</param-value> </init-param> </servlet> servlet code public void init(ServletConfig config) throws ServletException { super.init(config); System.out.println(config.getInitParameter("jdbcDriver")); } But It displayed null .. could any one

How do I provide basic http authentication for static tomcat webapps without changing tomcat-users.xml?

天大地大妈咪最大 提交于 2019-12-18 04:44:12
问题 I have access to the tomcat manager and can upload war-files. One of these wars is a static web project (zipped html + media files, renamed to *.war). I want add a Web-INF/web.xml file to this war to protect the content with basic http auth. I know how to do this by adding global users and assigning roles in the tomcat-users.xml , but I want to have all usernames and passwords defined in my war-file. Can this be done without touching the tomcat's tomcat-users.xml ? And if yes, how do I

How to add filters to servlet without modifying web.xml

无人久伴 提交于 2019-12-17 23:36:08
问题 I'd like the ability to modify/configure filters in a different way than web.xml. Here is a static configuration of 2 filters. I'd like the ability to have one filter statically configured and allow that filter to load additional filters. I just wanted to know if anyone knows of lib that already has this. Using Servlet API 2.5 <web-app> ... <filter> <filter-name>MyFilter1</filter-name> <filter-class>com.me.MyFilter1</filter-class> </filter> <filter-mapping> <filter-name>MyFilter1</filter-name