servlets

How to forcibly create a new session in Java Servlets

百般思念 提交于 2020-01-11 13:12:02
问题 I am storing session ids in database at log in time. The problem I am facing is that if a different user logs in after first one, same session is entered in DB and welcome username still reflects the name of the one who logged in first on the same machine. I want to create a new session id each time a user logs in, but somehow my code doesn't work. HttpSession session = request.getSession(); String sessionID; request.getSession(true); sessionID = session.getId(); Note: the above code is

servlet response time is slow for first request

与世无争的帅哥 提交于 2020-01-11 11:13:26
问题 Servlet response time slow only for 1st request Response time 1st request is 10.5 seconds. further request 2.5 seconds. From few java resources i got to know that the servlet loads the required classes for the first time during the first request and reuses the same for further requests and hence the delay Fix 1: I created a dummy request within the servlet immediately after the execution of init() method. Response time : 2.5 seconds for all requests through user agents. Fix 2: I tried loading

How to drop body of a request after checking headers in Servlet

大城市里の小女人 提交于 2020-01-11 10:38:06
问题 I want to check the header of the request whether it contains a certain header or not before continuing with the body. For example, I want to check whether a multipart/form-data contains "Authorization" in the header or not. If it is not then there is no need to continue with uploading the multipart body which are generally quite large for file uploading. Does servlet allow you to do this? I have tried to search on google randomly but there is no luck. Here is the code i try in my servlet but

How to drop body of a request after checking headers in Servlet

倾然丶 夕夏残阳落幕 提交于 2020-01-11 10:37:45
问题 I want to check the header of the request whether it contains a certain header or not before continuing with the body. For example, I want to check whether a multipart/form-data contains "Authorization" in the header or not. If it is not then there is no need to continue with uploading the multipart body which are generally quite large for file uploading. Does servlet allow you to do this? I have tried to search on google randomly but there is no luck. Here is the code i try in my servlet but

How do I extract the username and password out of a URL in a servlet filter?

折月煮酒 提交于 2020-01-11 09:48:11
问题 I've created a BasicAuthFilter and it has this signature: @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException This is working if someone calls the filter with an Authorization header set the right way. But, if someone on chrome or firefox visits the url like this: http://username:password@localhost:8888 The browsers are not populating the Authorization header with that information (which surprised me). I

How do I detect the TLS version of an HttpServletRequest?

你说的曾经没有我的故事 提交于 2020-01-11 09:26:07
问题 I am in the process of phasing out support for TLS 1.0 and TLS 1.1 for a web application. I would like to detect users this will impact based on the connections they are making to my servers. I am running Tomcat 7 and Java 8. How do I detect the TLS version of an HttpServletRequest? 回答1: This is not practical to do in Java. It requires modifying the JSSE implementation or plugging in an alternative. I eventually solved this by deploying How's My SSL and using cross-domain AJAX from the client

Rest easy and init params - how to access?

*爱你&永不变心* 提交于 2020-01-11 08:45:22
问题 I'd like to have some init params in my web.xml and retrieve them later in the application, I know I can do this when I have a normal servlet. However with resteasy I configure HttpServletDispatcher to be my default servlet so I'm not quite sure how I can access this from my rest resource. This might be completely simple or I might need to use a different approach, either way it would be good to know what you guys think. Following is my web.xml, <web-app xmlns:xsi="http://www.w3.org/2001

How to import JDBC driver into Dynamic Web Project?

核能气质少年 提交于 2020-01-11 06:55:12
问题 I have a local MySQL database. When I created a simple Java project, with one class which contained only main, I successfully retrieved some data from the database using JDBC connector jar, imported with Build path -> Add external jars, and it worked perfectly. Then I tried to use a similar approach, but now in a Dynamic Web Project , in which I am using Servlets, but I get java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/ePay . I have been looking for several hours

JasperReports: Calling report from servlet [duplicate]

给你一囗甜甜゛ 提交于 2020-01-11 02:31:48
问题 This question already has answers here : JasperReports: How to call the report in jsp page (6 answers) Closed 3 years ago . I'm new to JasperReports and dont know how to call jasper file from servlet. My report contains the pie chart. 回答1: You can prepare the Jasper file and stream it to the client. bytes[] byteStream = JasperRunManager.runReportToPdf("myJasperReport.jasper",paramMap,databaseConn); OutputStream outStream = servletResponse.getOutputStream(); response.setHeader("Content

Reverse Ajax + JSP-Servlet

假装没事ソ 提交于 2020-01-10 20:11:44
问题 We are trying to create a reverse ajax in our project. I've checked on the net and didn't find something concrete. I was unable to run any of the tutorials provided successfully. My object is: to provide on-screen alerts (like a pop-up) when ever there is an even pushed from the server (it could be high cpu usage/ram, anything). 回答1: The HTTP protocol (fortunately, after all) doesn't support PUSH, so it stops there. Best what you can do is to let the client fire ajax poll requests at timed