图上的知识点都可以在我其他的文章内找到相应内容。
监听器常见面试题
监听器有哪些作用和用法?
Java Web开发中的监听器(listener)就是application、session、request三个对象创建、销毁或者往其中添加修改删除属性时自动执行代码的功能组件,如下所示:
- ① Servlet ContextListener:对Servlet上下文的创建和销毁进行监听。
- ②ServletContextAttributeListener:监听Servlet上下文属性的添加、删除和替换。
- ③HttpSessionListener:对Session的创建和销毁进行监听。
- session超时(可以在web.xml中通过
- <session- config>/<session-timeout>标签配置超时时间);
- 通过调用session对象的invalidate()方 法使session失效。
- 补 充:session的销毁有两种情况:
- ④HttpSessionAttributeListener:对Session对象中属性的添加、删除和替换进行监听。
- ⑤ServletRequestListener:对请求对象的初始化和销毁进行监听。
- ⑥ServletRequestAttributeListener:对请求对象属性的添加、删除和替换进行监听。
常见的监听器用途主要包括: 网站在线人数技术、监听用户的行为(管理员踢人) 。
过滤器常见面试题
过滤器有哪些作用和用法?
过滤器有哪些作用和用法?
Java Web开发中的过滤器( filter )是从Servlet 2.3规范开始增加的功能,并在Servlet 2.4规范中得到增强。对Web应用来说, 过滤器是一个驻留在服务器端的Web组件 ,它可以截取客户端和服务器之间的请求与响应信息,并对这些信息进行过 滤。当Web容器接受到一个对资源的请求时,它将判断是否有过滤器与这个资源相关联。如果有,那么容器将把请求交给过滤器进行处理。在过滤器中, 你可以改 变请求的内容,或者重新设置请求的报头信息,然后再将请求发送给目标资源。当目标资源对请求作出响应时候,容器同样会将响应先转发给过滤器,再过滤器中, 你可以对响应的内容进行转换,然后再将响应发送到客户端。
常见的过滤器用途主要包括: 对用户请求进行统一认证、对用户的访问请求进行记录和审核、对用户发送的数据进行过滤或替换、转换图象格式、对响应内容进行压缩以减少传输量、对请求或响应进行加解密处理、触发资源访问事件、对XML的输出应用XSLT等 。
和过滤器相关的接口主要有:Filter、FilterConfig、FilterChain
Java Web常见面试题
web.xml 的作用?
web.xml 的作用?
答:用于配置Web应用的相关信息,如: 监听器(listener)、过滤器(filter)、 Servlet、相关参数、会话超时时间、安全验证方式、错误页面等 。例如:
①配置Spring上下文加载监听器加载Spring配置文件:
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>
②配置Spring的OpenSessionInView过滤器来解决延迟加载和Hibernate会话关闭的矛盾:
<filter> <filter-name>openSessionInView</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class> </filter> <filter-mapping> <filter-name>openSessionInView</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
③配置会话超时时间为10分钟:
<session-config> <session-timeout>10</session-timeout> </session-config>
④配置404和 Exception 的错误页面:
[html] view plaincopy在CODE上查看代码片派生到我的代码片
<error-page>
<error-code>404</error-code>
<location>/error. jsp </location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>
⑤配置安全认证方式:
<security-constraint> <web-resource-collection> <web-resource-name>ProtectedArea</web-resource-name> <url-pattern>/admin/*</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <auth-constraint> <role-name>admin</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> </login-config> <security-role> <role-name>admin</role-name> </security-role>
【补 充1】从Servlet 3开始,可以不用在web.xml中部署Servlet(小服务)、Filter(过滤器)、Listener(监听器)等Web组件, Servlet 3提供了基于注解的部署方式,可以分别使用@WebServlet、@WebFilter、@WebListener三个部署小服务、过滤器、监听器。
【补充2】如果Web提供了有价值的商业信息或者是敏感数据,那么站点的安全性就是必须考虑的问题。安全认证是实现安全性的重要手段,认证就是要解决“Are you who you say you are?”的问题。认证的方式非常多,简单说来可以分为三类:
A.What you know? –口令
B.What you have? –数字证书(U盾、密保卡)
C.Who you are? — 指纹识别、虹膜识别
在Tomcat中可以通过建立安全套接字层(Secure Socket Layer, SSL)以及通过基本验证或表单验证来实现对安全性的支持。
Servlet 3中的异步处理指的是什么?
Servlet 3中的异步处理指的是什么?
答: 在Servlet 3中引入了一项新的技术可以让Servlet异步处理请求。有人可能会质疑,既然都有 多线程 了,还需要异步处理请求吗?答案是肯定的,因为如果一个任务处 理时间相当长,那么Servlet或Filter会一直占用着请求处理线程直到任务结束,随着并发用户的增加,容器将会遭遇线程超出的风险,这这种情况下 很多的请求将会被堆积起来而后续的请求可能会遭遇拒绝服务,直到有资源可以处理请求为止。异步特性可以帮助应用节省容器中的线程,特别适合执行时间长而且 用户需要得到结果的任务,如果用户不需要得到结果则直接将一个Runnable对象交给Executor(如果不清楚请查看前文关于多线程和线程池的部 分)并立即返回即可 。
开启异步处理代码:
@WebServlet(urlPatterns = {"/async"}, asyncSupported = true) public class AsyncServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // 开启Tomcat异步Servlet支持 req.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true); final AsyncContext ctx = req.startAsync(); // 启动异步处理的上下文 // ctx.setTimeout(30000); ctx.start(new Runnable() { @Override public void run() { // 在此处添加异步处理的代码 ctx.complete(); } }); } }
文章来源:
作者:Java3y
Thank you! Loads of tips!
online assignment writing service essay writing service ratings
Valuable information. With thanks.
thematic thesis making a good thesis statement
Awesome tips. Appreciate it!
pay someone to write a research paper [url=https://seoqmail.com/]pay to get essays written[/url]
Thanks a lot, I value it.
who can write my essay write my essay same day
Awesome material. Appreciate it.
what i do in my spare time essay while revising an argumentative essay a writer should
Regards! Useful stuff.
rsweeps online casino casino gambling online
You explained that perfectly.
essay writer for you website that writes your essay for you
Position effectively regarded!!
can someone write a song for me write my essay for me website
Well expressed of course! .
can you write my essay write a paragraph for me using these words
Nicely put, Thanks a lot.
papers writing service buy a literature review paper
This is nicely expressed. !
write my research paper for me paper writer service
Whoa quite a lot of excellent knowledge.
essay writter paid essay writers
Many thanks, Loads of information!
coursework writing uk cpm homework help
Superb stuff, Thanks a lot.
ai essay writer help me write my essay
Awesome material, Regards.
dissertation writing services cost dissertation abstracts international
Terrific material. Cheers.
write essay for you strengths as a writer essay
Thanks, I value it.
essay writing service uk cheap custom writing service
With thanks. Quite a lot of material!
can someone do my essay what should i write my persuasive essay on
Cheers, I appreciate it!
i forgot to do my essay write my thesis for me
This is nicely expressed. !
where can you buy resume paper buy a paper
Nicely put, Cheers.
are essay writing services safe writing essays services
Helpful knowledge. With thanks.
how to write a reaction paper writing paper
Regards. A good amount of postings.
grad school essay writing service writing a good essay
Nicely put. With thanks.
buy essay online writing service essay writing service buy
Thank you! Ample knowledge.
homework do my chemistry homework
Helpful postings. Kudos.
reddit do my homework do my math homework
Beneficial forum posts. Thanks.
online coursework do my college homework
Great postings, Thanks!
phd dissertation writing proquest dissertations
Really a lot of useful facts!
coursework do my math homework
With thanks. Lots of material!
essay writting service custom essay writing
Great knowledge. Thanks!
phd dissertation writing dissertation definition
Thanks! Numerous stuff!
homework help cpm do my homework for money
Fantastic postings, Thanks a lot!
writing dissertation dissertation proposal
Thank you, Numerous forum posts!
my homework my homework
Cheers, A lot of postings!
essay writing service help me write my essay
Nicely put. With thanks.
write paper service best essay writing service
Thanks. Ample stuff.
pay someone to do my homework homework help cpm
Well voiced indeed! !
definition of dissertation what is a phd
Nicely put. Kudos.
writing proposal writing proposal
Cheers. Lots of information.
pay someone to write paper paper writing services
Tips clearly taken.!
writing an essay outline writing an essay outline
Amazing loads of beneficial information!
pay someone to write my college essay pay someone to write my college essay
Reliable content. With thanks!
do my math homework for me cpm homework help
You expressed that fantastically!
research proposal cover page elements of a research proposal
Information clearly used!!
buy an essay buy essays
Thanks a lot, Fantastic information!
essay writing service oxford essay writing service blog
You expressed that wonderfully!
dissertation writing services dissertation writing services reviews
Amazing facts. Regards.
pay for college papers pay for paper
Fantastic data. With thanks!
buy essay service writing a scholarship essay
Good postings, Thanks.
write my essay for free persuasive essay writer
You’ve made your position extremely nicely!!
dissertation paper doctoral dissertation
Truly loads of valuable material.
do my finance homework hire someone to do my homework
Regards. A good amount of facts.
writing help dissertation help services
Superb facts. Many thanks.
hire someone to do my homework reddit do my homework
Kudos. Lots of write ups.
dissertations online phd weight loss
Info effectively used!.
pay to write my essay pay someone to write my college essay
Beneficial write ups. Thanks a lot!
dissertation service what is a phd
You actually expressed this exceptionally well!
writing a personal essay help me write my essay
Truly all kinds of good facts!
best essay writing service argumentative essay
This is nicely expressed. !
pay for an essay pay for an essay
Wonderful tips. Thanks.
dissertation abstract dissertation def
Point nicely applied..
pay to write paper buy college essays
Terrific stuff, Thanks a lot.
best essay writers how to write an apa paper
Many thanks. Ample information.
essay writing service reviews professional paper writing service
You made your point!
best rated essay writing service unique essay writing service
Really lots of excellent knowledge!
college essays writing which essay writing service is the best
Thank you, I like it.
dissertation writing dissertation abstracts
Regards, Plenty of posts.
writing a good essay essay writer no plagiarism
dissertation writing services dissertation abstract
essay writing jobs
Whoa a lot of awesome information.
pay for research paper pay someone to write a paper
Cheers, Numerous advice!
help me write my essay write my paper for me
Fine stuff. Many thanks!
essay writing websites cheap essay writing service us
write my essay online write my essay online
how to write an exemplification essay
Truly tons of helpful facts.
dissertation data analysis help buy dissertations
You actually reported it superbly.
essay writer website writing essays for money
You’ve made your position extremely effectively..
do my essay for me essay writer no plagiarism
cheap essay writing service best finance essay writing service
help writing a thesis
Regards. I appreciate this.
buy essay writing service essay writing service dublin
You suggested it fantastically.
online check writing service professional essay writing service
Thanks a lot. Plenty of tips.
professional paper writers write my research paper for me
Thanks, Lots of stuff.
essay writer help cheap essay writing
You explained that well.
custom handwriting paper pay someone to write a paper
proposal research research proposal
pay someone to write my essay
Kudos. Numerous content!
thesis template define thesis
You actually mentioned that perfectly!
where to buy essays online pay for essay
Cheers, A good amount of write ups!
dissertation assistance writing dissertation
essay for sale pay someone to write your paper
good opening sentences for college essays
Nicely put, Many thanks.
do my paper writing a paper
Helpful facts. Many thanks!
pay for essay papers buy an essay online
Seriously loads of beneficial advice.
do my chemistry homework do my homework for me
essay writers online pay someone to write my paper
how to write a funny essay
Nicely put, Regards.
writing a thesis thesis statment
You made your point.
coursework online coursework
essays for sale buy essays
writing help for college students
Effectively expressed certainly. !
cpm homework help coursework
You made your point.
how to write thesis thesis binding
Lovely data, Thank you!
phd weight loss dissertation writing service
best essay writing service 2016 letter writing service
national honor society essay help
Lovely material, Many thanks.
pay to write my essay buy essays online
You actually revealed it superbly!
college paper writing service professional paper writing service
Cheers. I appreciate this.
do my homework for me do my homework
writing essays for money writing a persuasive essay
writing helper
Nicely put, With thanks!
thesis statements thesis template
Great write ups. Thanks.
research paper writer services thesis proposal
Appreciate it, A good amount of information!
term paper research paper writer
write my essay cheap writing an opinion essay
custom thesis writing service
Kudos! Fantastic stuff!
term paper writing services term paper writing services
Regards! Lots of tips!
buying papers for college paper writing services
Kudos, I enjoy this.
writing essay service what is the best essay writing service
custom paper writing service best essay writing
rutgers essay help
This is nicely expressed! !
essay writing courses online free easy essay writing
You’ve made your point extremely nicely..
essay writing tips paper writing service reviews
Good information, Appreciate it.
linkedin profile writing service custom essay writing service
paperhelp how to write a college essay
write a comparison essay
Regards. I appreciate this.
parts of a research proposal term paper help
Awesome facts, With thanks!
college term papers buy a research paper
Good stuff. Regards.
good essay writing service writing a college application essay
college application essay help writing help
online custom writing services
You definitely made the point.
best resume writing service reddit spanish essay writing service