1.servlet 对象是在服务器端还是在客户端创建的? 2.servlet 对象被创建后首选调用 init 方法还是 service 方法? 3.servlet 第一次被请求加载时调用 init 方法,当后续的客户请求 servlet对象,servlet 对象不再调用 init 方法”,这样的说法是否正确? 4. 假设创建servlet 的类是 tom.fiafei.Dalian.创建的 servlet 对象的名字是 mvservlet.应当怎样配置 web.sml 文件? 5.如果 Servlet 类不重写 service 方法,那么应当重写哪两个方法? 6. HttpServetResponse 类的 sendRedirect 方法和 RequestDispatcher 类的 forward 方法有何不同? 7. Servlet 对象怎样获得用户的会话对象? 1. 在JSP中,MVC 模式中的数据模型之角色由谁担当? 2.在JsP 中.MVC模式中的控制器之角色由谁担当? 3. 在JsP 中.MVC模式中的视图之角色由谁担当? 4.MVC的好处是什么? 5.MVC模式中用到的Javabean 是由 JSP 页面还是servlet 负责创建?
时间: 2024-02-16 21:00:45 浏览: 42
1. Servlet对象是在服务器端创建的。
2. Servlet对象被创建后首先调用init方法。
3. 这样的说法是不正确的。每当有一个新的请求到达时,服务器都会创建一个新的线程用于处理该请求,并创建新的Servlet实例对象,调用其service方法进行处理。因此,每个请求都会调用service方法,而不是init方法。
4. 在web.xml文件中添加如下配置:
```
<servlet>
<servlet-name>mvservlet</servlet-name>
<servlet-class>tom.fiafei.Dalian</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>mvservlet</servlet-name>
<url-pattern>/mvservlet</url-pattern>
</servlet-mapping>
```
5. 如果Servlet类不重写service方法,则应重写doGet和doPost方法。
6. sendRedirect方法用于将请求重定向到另一个URL,而forward方法用于将请求转发到另一个资源(Servlet、JSP或HTML等)。
7. Servlet对象可以通过HttpServletRequest的getSession方法获得用户的会话对象。
8. 在JSP中,MVC模式中的数据模型的角色由JavaBean担当。
9. 在JSP中,MVC模式中的控制器的角色由Servlet担当。
10. 在JSP中,MVC模式中的视图的角色由JSP页面担当。
11. MVC的好处包括代码重用、可维护性、可扩展性和可测试性等。
12. Javabean可以由Servlet或JSP页面创建。通常情况下,Servlet负责创建JavaBean对象并将其存储到请求或会话范围中,而JSP页面负责使用JavaBean对象来呈现视图。
相关推荐
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)