Why extend servlet
Provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user. Objects that are bound to a session may listen to container events notifying them that sessions will be passivated and that session will be activated. Class Summary Class Description Cookie Creates a cookie, a small amount of information sent by a servlet to a Web browser, saved by the browser, and later sent back to the server. Provides a convenient implementation of the HttpServletRequest interface that can be subclassed by developers wishing to adapt the request to a Servlet.
Provides a convenient implementation of the HttpServletResponse interface that can be subclassed by developers wishing to adapt the response from a Servlet. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Ask Question. Asked 4 years, 9 months ago. Active 4 years, 9 months ago. Viewed times. Improve this question. Let me ask you a counter question.
Why do you need the JDK? Add a comment. Any clue you can give me will be a great help. How do you know it's failing? Post the actual code used to bind the object to scope and then the code used to retrieve it. I think it is failing because the jsp is not getting compiled. If I comment out this statement to get this attribute from the servletContext, the page is getting rendered.
May be since this class extends another servlet, this class has to be in web. What JSP is not being compiled? Are you doing this in a JSP scriptlet or in a servlet? I do have a servlet, say Servlet1. And I also have a class, say Class1 that extends Servlet1. In the init of Servlet1, I set some attributes to the ServletContext. In my jsp, I am calling a method, say method1 which is in Class1. But if I commented out getServletContext. I wrote this just to clarify the issue.
Please ask me if this is not clear. I will post the code. I appreciate your effort to solve this issue. Ok, I think it's getting clearer. There is no need to do this. If it is instanciated by the container, you aren't really going to have a way to access it from your JSP anyway. Servlets weren't meant to be used this way see 1. If you want to move your logic out of your servlet and JSP, which is a good idea, put it in a plain old Java object.
If that object needs something like an object that is in context scope get a reference to that object from your servlet and pass it to the POJO. Once you've done this, call your POJO's method from the servlet. Doing this will allow your JSPs to access these objects.
We have a very simple MVC application in our codebarn that does some of this. But if I comment out the statements to get from the servlet context, the jsp is getting compiled. Any solution is highly appreciated.
I think our posts just crossed.
0コメント