servlets

How to get the IP address when a session is created?

喜欢而已 提交于 2019-12-30 09:38:36
问题 In my grails application, I have implemented the interface HttpSessionListener to listen for session creation as given below: class MyHttpSessionListener implements HttpSessionListener { public void sessionCreated(HttpSessionEvent event) { log.info "***************** Session created: id= ${event.getSession()?.id}" } } Now, I would like to log the IP address that is responsible for the session creation . How can I do that? 回答1: you can access the RequestContextHolder and get the value String

Configure web.xml (Tomcat 5) for one servlet to handle all incoming requests?

北城以北 提交于 2019-12-30 09:38:15
问题 Basically I want one servlet to handle all incoming request regardless of the path. I'm on shared hosting environment with access to configure my own web.xml file. I have the following configured in web.xml, but it doesn't work on Tomcat 5: <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee

Authorization header in Http Request in linkedin

ⅰ亾dé卋堺 提交于 2019-12-30 08:34:19
问题 Hi in my servlet code I am requesting the server with access_token on behalf of user i am able to request with below code: OAuthRequest request2 = new OAuthRequest(Verb.GET,"https://api.linkedin.com/v1/people/~:(first-name,last-name,email-address)?oauth2_access_token="+accesstok); But How i can request with Authorization Header like below: GET /v1/people/~ HTTP/1.1 Host: api.linkedin.com Connection: Keep-Alive Authorization: Bearer AQXdSP_W41_UPs5ioT_t8HESyODB4FqbkJ8LrV_5mff4gPODzOYR I am

Java filter failing to set response headers

删除回忆录丶 提交于 2019-12-30 08:07:32
问题 I am trying to create a Java "Filter" which detects a custom HTTP Request Header, and inserts response headers so that the file will download automatically. The response header that is most important for this is the "Content-Type = Attachment" response header. I have created an HTTP request object that inserts the custom Header: function myHttpObject(filePath){ function makeHttpObject() { return new XMLHttpRequest(); } var request = makeHttpObject(); request.open("GET", filePath, false);

Should I override service() or doPost()?

只愿长相守 提交于 2019-12-30 08:05:09
问题 I was reading a book on servlets, in that book a brief explanation is given about the servlet class, as well as the HttpServlet class. There is one example for filling in a form- for that form, the servlet's doPost() method is overridden by the class. But for another example of a login form, the service() method is overridden instead. I want to know why the 2 different approaches- I thought that usually we put our custom code into doPost() (or doGet() ) and let service() remain as it is. Is

Should I override service() or doPost()?

有些话、适合烂在心里 提交于 2019-12-30 08:05:08
问题 I was reading a book on servlets, in that book a brief explanation is given about the servlet class, as well as the HttpServlet class. There is one example for filling in a form- for that form, the servlet's doPost() method is overridden by the class. But for another example of a login form, the service() method is overridden instead. I want to know why the 2 different approaches- I thought that usually we put our custom code into doPost() (or doGet() ) and let service() remain as it is. Is

Java Servlet/Jsp image upload along with form values [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-30 07:55:10
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I have a jsp form that accepts details about Employee name, sex, age, E-mail address and a 回答1: Servlet 3.0 container's has standard support for multipart data. First you should be writing a HTML page which takes

java.net.HttpRetryException: cannot retry due to server authentication, in streaming mode

故事扮演 提交于 2019-12-30 07:51:19
问题 We have two parts in our app: Server - provide REST services Client - consume them via Spring restTemplate In addition to the HTTP status our server returns an HTTP body with JSON that describe error in detail. So, I've added custom Error handler to restTemplate to treat some error coded as non errors - it helps parse HTTP body very well. But I get an exception via parsing of the HTTP body in the case of an HTTP/1.1 401 Unauthorized. All other error codes are handled fine(400, 402, etc. ) We

How to create a PDF with iText+XMLWorker from servlet using custom font?

元气小坏坏 提交于 2019-12-30 07:31:33
问题 Playing with iText/XMLWorker samples (mostly this one), I could easily write simple applications able to create PDF files from HTML code using my own extra fonts, but as soon as tried to use my stuff in some web service code, I ended with exceptions like: Table 'name' does not exist in file:/C:/work/MyServer/target/classes/fonts/My%20Font.ttf ExceptionConverter: com.itextpdf.text.DocumentException: Table 'name' does not exist in file:/C:/work/MyServer/target/classes/fonts/My%20Font.ttf ..

How to create a PDF with iText+XMLWorker from servlet using custom font?

霸气de小男生 提交于 2019-12-30 07:31:32
问题 Playing with iText/XMLWorker samples (mostly this one), I could easily write simple applications able to create PDF files from HTML code using my own extra fonts, but as soon as tried to use my stuff in some web service code, I ended with exceptions like: Table 'name' does not exist in file:/C:/work/MyServer/target/classes/fonts/My%20Font.ttf ExceptionConverter: com.itextpdf.text.DocumentException: Table 'name' does not exist in file:/C:/work/MyServer/target/classes/fonts/My%20Font.ttf ..