最近在学习java web的开发,本人并不太喜欢java,可是生活所需.struts是基于MVC,当我们在修改一个
数据库里的表数据时,一般都会把它从数据库里读出来,然后request给jsp页面的<html:text>的标签,下
面是一个操作过程:
---------- 获得数据 --------------
| action |----------------| database |
|---------| |------------- |
|传给jsp |
|初始化text |
|-----------| 修改数据库 |
| jsp |---------------------|
|-----------|
一般从数据库获得数据,都很简单,一条select语句,select *from 表名;把数据存入一个对象中,这个
对象中,这个对象要在原文件的bean包中有,然后我们通过action,request.setAttribute(Object obj,Object obj);
比如,我们的获得的对象并且申明对象变量是student,那我们就request.setAttribute("student",student);并且转
发给jsp,return mapping.finForward("studenjsp");
那我们在jsp中就可以获得request,在页面中可以这样写
假设student中有studentId,studentName,studentSex,studentAge
<logic:present name="student">
<bean:define id="id" name="student" property="studentId"/>
<bean:define id="name" name="student" property="studentName"/>
<bean:define id="sex" name="student" property="studentSex"/>
<bean:define id="age" name="student" property="studentAge"/>
<html:form action="/studentjsp.do">
<html:hidden name="" value="${id}"/>
<html:text name="" value="${name}"/>
<html:text name="" value="${sex}"/>
<html:text name="" value="${age}"/>
<html:submit/> <html:cancel />
</html:form >
</logic:present>
这样就可以初始化<html:text>并且修改内容提交修改数据了!!
(我的
个人主页:地址:http://www.basketwill.com