《Java Web应用开发实用教程》练习答案(6)

2018-11-23 21:09

public void settxtSize(String txtSize) { this.txtSize = txtSize; } public String gettxtSize() { return this.txtSize; } public void settxtFont(String txtFont) { this.txtFont = txtFont; } public String gettxtFont() { return this.txtFont; } public void settxtColor(String txtColor) { this.txtColor = txtColor; } public String gettxtColor() { return this.txtColor; } }

文件pageJavaBean.jsp文件调用定义的JavaBean,通过JavaBean实现页面属性的设置。文件代码如下:

<%@ page language=\<%@ page import=\ 通过JavaBean设置页面属性 <% request.setCharacterEncoding(\ %> >


8.5 习题

1. 单选题

(1) MVC中的M是指( )。

A. Model B. View C. Controller D. 以上都不对 答案:A

(2) MVC中的V是指( )。

A. Model B. View C. Controller D. 以上都不对 答案:B

(3) MVC中的C是指( )。

A. Model B. View C. Controller D. 以上都不对

答案:C

(4) 有关struts 2的说法不正确的是( )

A. Struts是一个用于简化MVC框架(Framework)开发的Web应用框架 B. 应用Struts 2不需要进行配置 C. Struts 2 含有丰富的标签

D. Struts2采用了WebWork的核心技术 答案:B

2. 上机练习

参考例8.2,用Struts 2编写一个用户登录的简单Web应用程序。 答案:

配置文件web.xml文件代码如下:

struts2 org.apache.struts2.dispatcher.FilterDispatcher struts2 /*

loginAction.java文件代码如下: package user;

import com.opensymphony.xwork2.ActionSupport;

public class loginAction extends ActionSupport { private String userName; private String password; public String execute() throws Exception { if (isInvalid(getUserName())) return \ if (isInvalid(getPassword())) return \

return \ } private boolean isInvalid(String value) { return (value == null || value.length() == 0); } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }

该文件中只要用户名和密码都不为空即可通过验证。 struts.xml文件代码如下:

\ \

用户登录界面文件login.jsp文件代码如下:

<%@ page contentType=\<%@taglib prefix=\ 登录页面


《Java Web应用开发实用教程》练习答案(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:宏观经济学练习及答案(高鸿业,人大版)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: