servlets

Default session expiration timeout?

可紊 提交于 2020-01-13 09:06:12
问题 By default the JSESSIONID cookie is expired when you close the browser, but how long is the associated HttpSession really valid on the server side? 回答1: It defaults to 30 minutes on most containers which you can configure by <session-config> in your webapp's web.xml . <session-config> <session-timeout>10</session-timeout> </session-config> The above example will change the server side session timeout to 10 minutes. So in other words, when the client do not interact with the server for more

Why is it considered a good practice to make session scoped objects Serializable?

好久不见. 提交于 2020-01-13 06:13:26
问题 I often hear people saying that session scoped objects should implement Serializable ? Why it is so ? What will be the result if one doesn't do this ? Why not make this a part of the servlet specification then ? I know Tomcat doesn't complain if we do not do this . What about other app servers like JBoss, WebSphere or Weblogic ? 回答1: This allows the servlet container to either store the contents of a session on disk, or to transfer session contents over the network to another server. Why does

Invoking servlet from java main method

放肆的年华 提交于 2020-01-13 05:54:21
问题 import java.net.*; import java.io.*; public class sample { public static void main (String args[]) { String line; try { URL url = new URL( "http://localhost:8080/WeighPro/CommPortSample" ); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); line = in.readLine(); System.out.println( line ); in.close(); } catch (Exception e) { System.out.println("Hello Project::"+e.getMessage()); } } } My Servlet is invoking another Jsp page like the below, RequestDispatcher rd

jetty webSocket : java.lang.IllegalStateException: Committed

一个人想着一个人 提交于 2020-01-13 03:40:11
问题 I am using Jetty Websockets in my Web Application . When i am trying to redirect to a logoff jsp , i am getting this error oejs.ServletHandler:/test java.lang.IllegalStateException: Committed at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1069) at javax.servlet.ServletResponseWrapper.resetBuffer(ServletResponseWrapper.java:232) at org.eclipse.jetty.http.gzip.GzipResponseWrapper.resetBuffer(GzipResponseWrapper.java:273) at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher

How to Call java Rest WebService inside a Servlet

点点圈 提交于 2020-01-12 08:00:08
问题 I have a java Rest WebService URL http://localhost:8080/WebServiceEx/rest/hello/dgdg When i execute the URL ,the WebService Method Returns a String My Requirement is to call the above WebService URL inside a Servlet ,Could any one Help? ServletCode: public Class StoreServlet extends HttpServlet{ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { //Invoke WebService and Get Response String Here } WebService Code: public class

Servlet buffering response despite calls to flush()

人走茶凉 提交于 2020-01-12 07:15:27
问题 We have a system where a client makes an HTTP GET request, the system does some processing on the backend, zips the results, and sends it to the client. Since the processing can take some time, we send this as a ZipOutputStream wrapping the response.getOutputStream() . However, when we have an exceptionally small amount of data in the first ZipEntry , and the second entry takes a long time, the browser the client is using times out. We've tried flushing the stream buffer, but no response

Servlet buffering response despite calls to flush()

孤者浪人 提交于 2020-01-12 07:14:45
问题 We have a system where a client makes an HTTP GET request, the system does some processing on the backend, zips the results, and sends it to the client. Since the processing can take some time, we send this as a ZipOutputStream wrapping the response.getOutputStream() . However, when we have an exceptionally small amount of data in the first ZipEntry , and the second entry takes a long time, the browser the client is using times out. We've tried flushing the stream buffer, but no response

checking session in servlet and jsp

匆匆过客 提交于 2020-01-12 07:09:34
问题 In my web application i neet to check session already exist or not. i want to check this in my servlet and in jsp also. is there any way to check this. Thanks 回答1: You can test it with HttpServletRequest#getSession(boolean create) with create=false . It will return null if not created yet. HttpSession session = request.getSession(false); if (session == null) { // Session is not created. } else { // Session is already created. } If you actually want to create the session anyway if it doesn't

Multiple filters with same url mapping

Deadly 提交于 2020-01-12 06:54:09
问题 Is it possible to use two filters that have the same url-mapping? <filter> <filter-name>TeeFilter</filter-name> <filter-class>filter1r</filter-class> </filter> <filter-mapping> <filter-name>TeeFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <display-name>CredentialsFilter</display-name> <filter-name>CredentialsFilter</filter-name> <filter-class>filter2</filter-class> </filter> <filter-mapping> <filter-name>CredentialsFilter</filter-name> <url-pattern>/*</url

Does a RequestDispatcher forward maintain the original request's HTTP method?

浪子不回头ぞ 提交于 2020-01-12 06:52:08
问题 I want to intercept a request using the RequestDispatcher, and then I want to forward the request along to another servlet -- something like this: RequestDispatcher dispatcher = request.getRequestDispatcher("/servlet/some.ThirdPartyServlet" + "?" + "param_name=" + "somevalue"); dispatcher.forward(request, response); If the incoming request were a POST, will the request dispatcher take my new parameters, and include them in the message body, or does this forward now become a GET? 回答1: It