servlets

Is doFilter() executed before or after the Servlet's work is done?

自闭症网瘾萝莉.ら 提交于 2019-12-28 05:14:55
问题 The javax.servlet.Filter object can be used both for authentication (where the Filter needs to catch the request before any servlet work needs to be done) and for XSLT translation (where the servlet needs to be completely finished generating content). When does it actually get executed? I know this is implementation dependent (on the web container), but this seems to be problem that needs to be solved by all of them. Maybe there is a configuration option set somewhere for each Filter

ServletContext.getRequestDispatcher() vs ServletRequest.getRequestDispatcher()

北城余情 提交于 2019-12-28 03:35:07
问题 why getRequestDispatcher(String path) of the ServletRequest interface cannot extend outside the current servlet context where as getRequestDispatcher(String path) of the ServletContext can use the getContext(String uripath) method to obtain RequestDispatcher for resources in foreign contexts. and how?? Please help 回答1: If you use an absolute path such as ( "/index.jsp" ), there is no difference. If you use relative path, you must use HttpServletRequest.getRequestDispatcher() . ServletContext

How to add response headers based on Content-type; getting Content-type before the response is committed

梦想的初衷 提交于 2019-12-28 02:59:28
问题 I want to set the Expires header for all image/* and text/css . I'm doing this in a Filter . However: before calling chain.doFilter(..) the Content-type is not yet "realized" after calling chain.doFilter(..) the Content-type is set, but so is content-length, which forbids adding new headers (at least in Tomcat implementation) I can use the extensions of the requested resource, but since some of the css files are generated by richfaces by taking them from inside jar-files, the name of the file

How can I map a “root” Servlet so that other scripts are still runnable?

笑着哭i 提交于 2019-12-28 02:42:07
问题 I'm trying to build a Servlet that calls a JSP page similar to the following: public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { req.getRequestDispatcher("/WEB-INF/main.jsp").forward(req, resp); } I need this Servlet to respond to the domain's root (eg: http://example.com/) so I'm using the following mapping in the web.xml: <servlet-mapping> <servlet-name>MainServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> The

How to inject dependencies into HttpSessionListener, using Spring?

只谈情不闲聊 提交于 2019-12-28 02:06:14
问题 How to inject dependencies into HttpSessionListener, using Spring and without calls, like context.getBean("foo-bar") ? 回答1: Since the Servlet 3.0 ServletContext has an "addListener" method, instead of adding your listener in your web.xml file you could add through code like so: @Component public class MyHttpSessionListener implements javax.servlet.http.HttpSessionListener, ApplicationContextAware { @Override public void setApplicationContext(ApplicationContext applicationContext) throws

Logging user activity in web app

筅森魡賤 提交于 2019-12-27 19:13:58
问题 I'd like to be able to log user activities in a web app. I'm currently using log4j which works well for logging errors etc, but I'm unsure what the best approach is to log the user, executed servlet method, and method params. I'm using spring security for the authentication. A typical servlet could look like: public class BankAccountServlet { @RequestMapping("/deposit") public void deposit(double amount) { ... } @RequestMapping("/checkBalance") public double checkBalance() { ... } } If there

Logging user activity in web app

南楼画角 提交于 2019-12-27 19:13:30
问题 I'd like to be able to log user activities in a web app. I'm currently using log4j which works well for logging errors etc, but I'm unsure what the best approach is to log the user, executed servlet method, and method params. I'm using spring security for the authentication. A typical servlet could look like: public class BankAccountServlet { @RequestMapping("/deposit") public void deposit(double amount) { ... } @RequestMapping("/checkBalance") public double checkBalance() { ... } } If there

Create an excel file for users to download using Apache POI

。_饼干妹妹 提交于 2019-12-27 19:13:28
问题 I'm able to create an excel file using apache poi. however, i want users to be able to download this as a "true" excel file. the effect i want to achieve would be to have a popup box allowing the user to download the file. this is similar to using <%@ page contentType="application/vnd.ms-excel" pageEncoding="ISO-8859-1"%> <%response.setHeader("Content-Disposition", "attachment;filename=myfile.xls"); %> with one critical exception: i must allow the user to download a proper excel file. i read

Pass data from Java Servlet to JSP? [duplicate]

放肆的年华 提交于 2019-12-27 19:12:55
问题 This question already has answers here : Show JDBC ResultSet in HTML in JSP page using MVC and DAO pattern (5 answers) Closed 3 years ago . I've been a PHP developer but recently need to work on some project using Google App Engine (Java). In PHP I can do something like this (in term of MVC model): // controllers/accounts.php $accounts = getAccounts(); include "../views/accounts.php"; // views/accounts.php print_r($accounts); I take a look at some demos of Google App Engine Java using Servlet

Howto get rid of <mvc:annotation-driven />?

坚强是说给别人听的谎言 提交于 2019-12-27 13:56:38
问题 Up to now, <mvc:annotation-driven /> has caused plenty of trouble for me, so I would like to get rid of it. Although the spring framework docs clearly say what it is supposed to be doing, a listing of tags actually summar <mvc:annotation-driven /> is lacking. So I'm stuck with removing <mvc:annotation-driven /> and now getting the error WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/webapp/trainees] in DispatcherServlet with name 'workoutsensor' for all Urls