servlets

Servlet send image from server and save in client

邮差的信 提交于 2020-01-03 03:09:05
问题 I'm new and just developing on J2EE. I am modifying an existing application (an OpenSource project). I need to save an image on a client sent by the server, but I do not know how. This activity must be done in a transparent manner without affecting the existing operation of the application. From the tests done I get this error: java.lang.IllegalStateException: getWriter () has Already Been Called for this response. How should carry out this task, according to your own opinion? How do I save

How to handle unexpected exceptions in JAX-RS

萝らか妹 提交于 2020-01-03 03:01:30
问题 My technology stack is Tomcat (servlet 3.0), Jersey for JAX-RS, Spring and Hibernate. When something unexpect goes wrong like some data conversion error in Hibernate, I do not want the clients to see my stacktrace for those exceptions that the Tomcat tries to print by default. However I would like to log those exceptions so I can find what is wrong and fix things. My first try was using ExceptionMapper from JAX-RS and naively thinking that would solve my problems. But then I noticed that

How to use @WebServlet to accept arguments (in a RESTFul way)?

社会主义新天地 提交于 2020-01-03 02:32:06
问题 suppose that I want to accept the following urls: http://myserver/myapplication/posts http://myserver/myapplication/posts/<id> http://myserver/myapplication/posts/<id>/delete how can I use the servlet decorator @WebServlet to do so? I'm investigating value and urlPatterns but I don't get how to do so. For example, @WebServlet(urlPatterns={"/posts", "/posts/*"}) [..] String param = request.getPathInfo(); gives me some result, but how to use it? Also, request.getPathInfo() seems to return the

enabling CORS in TOMCAT 7 servlets for post request

我与影子孤独终老i 提交于 2020-01-03 02:24:27
问题 I'm using tomcat 7 to run my servlets on my Dynamic web project in java (eclipse ee). I've added to my web.xml file the following paragraph (from https://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#CORS_Filter/Introduction): <filter> <filter-name>CorsFilter</filter-name> <filter-class>org.apache.catalina.filters.CorsFilter</filter-class> </filter> <filter-mapping> <filter-name>CorsFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>" I am trying to use the post request

How to link a JSP ,servlet and a Java view bean?

…衆ロ難τιáo~ 提交于 2020-01-03 02:21:08
问题 How to link a JSP ,servlet and a Java view bean? I donot want to have any scriplet in JSP. How can i ask my JSP to invoke servlet to set the Implicit request and response objects and then display the properties from view bean on the jsp. I need to pass request and response objects from jsp to servlet and then i want to display the properties defined in view bean to a JSP page. JSP -> Servlet -> View Bean -> JSP How to achieve this? 回答1: No need to pass request and response to the bean/model

No default constructor when adding servlet filter in Spring Boot

怎甘沉沦 提交于 2020-01-03 02:04:07
问题 I read this other posting about how to add a servlet filter in Spring Boot, but I am getting a No Default Constructor error when I try to follow its example of adding an inner WebConfig class within the UiApplication.java class file. I am trying this because adding ignoring(/api-url to the app's SecurityConfig class caused a message stating the /api-url has an empty filter list . I want to add a servlet filter for /api-url so that its filter list is no longer empty. The code for the WebConfig

Why there are no constructor in servlet?

孤街醉人 提交于 2020-01-03 01:49:09
问题 I am studying servlets I read that servlets are java programs but there are no constructor in servlet... Can anybody elaborate on it? 回答1: There are as in any other java class, but you don't need to invoke it. The webcontainer will call it for you. Most servlets do not hold instance data, hence, most of adding code in the constructor doesn't make any sense. 回答2: If you need to initialize your servlet you'll have to override the init method. 回答3: There is a constructor in servlet (take a look

Why there are no constructor in servlet?

为君一笑 提交于 2020-01-03 01:46:06
问题 I am studying servlets I read that servlets are java programs but there are no constructor in servlet... Can anybody elaborate on it? 回答1: There are as in any other java class, but you don't need to invoke it. The webcontainer will call it for you. Most servlets do not hold instance data, hence, most of adding code in the constructor doesn't make any sense. 回答2: If you need to initialize your servlet you'll have to override the init method. 回答3: There is a constructor in servlet (take a look

How do I get the windows login username of a user running my web application?

≡放荡痞女 提交于 2020-01-02 18:05:56
问题 I'm trying to get the windows user name of the user in my web application. Can any one suggest how to get it? I'm developing a web application. So if a user is accessing my application, then I need to get the user's windows id and his host name. I tried a few different ways but it never worked. Any suggestions are highly appreciated. 回答1: Windows user details are not sent in plain HTTP requests, which makes it impossible for you to derive them from a user in a web application without

jQuery.ajax servlet return a file [duplicate]

六月ゝ 毕业季﹏ 提交于 2020-01-02 18:04:47
问题 This question already has an answer here : How to download file from httpServlet with Jquery? (1 answer) Closed 2 years ago . I'm pretty new to jQuery and ajax and i have a question. In a jsp I call function downloadDocument(documentId){ var action = "attachment.do"; var method = "downloadDocument"; var url = action + "?actionType="+method+"&documentId=" + documentId; $.ajax({ url: url, dataType: "json", type: 'POST', success: function(data){ alert("downloaded!"); }, error: function (request,