jsp
<body>
<html:form action="addinstitution.do" method="post">
<table bgcolor='limt' width='100%'>
<tr>
<td>
<FONT color='white' ><b>学生奖惩信息录入 </b></FONT>
</td>
</tr>
</table>
<br>
<br> <tr>
<td width="100%" >
<fieldset style="height:45%;width:80%">
<legend>奖惩信息</legend>
<br>
<table width="650" border="0" cellpadding="2" cellspacing="1" height="130">
<tr>
<td nowrap align="right" width="9%">奖惩名称:</td>
<td width="36%">
<input name="institution_name" type="text" class="input" id="institution_name"/>
<font color="red">*<html:errors property="institution_name"/></font></td>
</tr>
<tr>
<td nowrap align="right" width="9%">学号:</td>
<td width="36%">
<input name="student_id" type="text" class="input" id="student_id"/>
<font color="red">*<html:errors property="student_id"/></font></td>
</tr>
<tr>
<td width="11%" nowrap align="right">奖惩说明:</td>
<td><textarea name="institution_content" cols="40" rows="6" class="input" id="institution_content"></textarea>
<font color="red">*<html:errors property="institution_content"/></font></td>
</tr>
</table>
</fieldset>
</td>
</tr>
<br>
<table align="center" >
<tr>
<td colspan="3" align="center">
<html:submit value="添加" />
<html:reset value="重置" /></td>
</tr>
</table>
<br>
</html:form>
<br>
<center><font color=red><html:errors property="sucaddinstitution"/></font></center>
<center><font color=red><html:errors property="loseaddinstitution"/></font></center>
</body>Action
String studentid=institutionForm.getStudent_id();
String institutionname=institutionForm.getInstitution_name();
String institutioncontent=institutionForm.getInstitution_content();
String pageFoword="";
try {
Connection conn=null;
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123"); String sql1="insert into b_institution(student_id,institution_name,institution_content,createtime) values(?,?,?,?)"; PreparedStatement ps=conn.prepareStatement(sql1);
ps.setString(1, studentid);
ps.setString(2, institutionname);
ps.setString(3, institutioncontent); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String createtime = sdf.format(new Date());
ps.setString(4, createtime);
int count=ps.executeUpdate(); if(count!=0)
{
ActionMessages mgs=new ActionMessages();
mgs.add("sucaddinstitution", new ActionMessage("add.suc"));
this.addErrors(request, mgs);
pageFoword ="addinstitutionreturn";
}
else
{
ActionMessages mg=new ActionMessages();
mg.add("loseaddinstitutiont", new ActionMessage("add.lose"));
this.addErrors(request, mg);
pageFoword ="addinstitutionreturn";
}
}
catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward(pageFoword);
.xml文件
<action
attribute="institutionForm"
input="/addinstitution.jsp"
name="institutionForm"
path="/addinstitution"
scope="request"
type="com.institution.struts.action.AddInstitutionAction">
<set-property property="cancellable" value="true" />
</action> <forward name="addinstitutionreturn" path="/addinstitution.jsp" />当没输入信息点添加按钮会进入validate验证, 当输入信息后点添加按钮,没执行任何的Action操作, 只是刷新了一次页面,并且输入信息刷空. 请问这是为什么?
<body>
<html:form action="addinstitution.do" method="post">
<table bgcolor='limt' width='100%'>
<tr>
<td>
<FONT color='white' ><b>学生奖惩信息录入 </b></FONT>
</td>
</tr>
</table>
<br>
<br> <tr>
<td width="100%" >
<fieldset style="height:45%;width:80%">
<legend>奖惩信息</legend>
<br>
<table width="650" border="0" cellpadding="2" cellspacing="1" height="130">
<tr>
<td nowrap align="right" width="9%">奖惩名称:</td>
<td width="36%">
<input name="institution_name" type="text" class="input" id="institution_name"/>
<font color="red">*<html:errors property="institution_name"/></font></td>
</tr>
<tr>
<td nowrap align="right" width="9%">学号:</td>
<td width="36%">
<input name="student_id" type="text" class="input" id="student_id"/>
<font color="red">*<html:errors property="student_id"/></font></td>
</tr>
<tr>
<td width="11%" nowrap align="right">奖惩说明:</td>
<td><textarea name="institution_content" cols="40" rows="6" class="input" id="institution_content"></textarea>
<font color="red">*<html:errors property="institution_content"/></font></td>
</tr>
</table>
</fieldset>
</td>
</tr>
<br>
<table align="center" >
<tr>
<td colspan="3" align="center">
<html:submit value="添加" />
<html:reset value="重置" /></td>
</tr>
</table>
<br>
</html:form>
<br>
<center><font color=red><html:errors property="sucaddinstitution"/></font></center>
<center><font color=red><html:errors property="loseaddinstitution"/></font></center>
</body>Action
String studentid=institutionForm.getStudent_id();
String institutionname=institutionForm.getInstitution_name();
String institutioncontent=institutionForm.getInstitution_content();
String pageFoword="";
try {
Connection conn=null;
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123"); String sql1="insert into b_institution(student_id,institution_name,institution_content,createtime) values(?,?,?,?)"; PreparedStatement ps=conn.prepareStatement(sql1);
ps.setString(1, studentid);
ps.setString(2, institutionname);
ps.setString(3, institutioncontent); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String createtime = sdf.format(new Date());
ps.setString(4, createtime);
int count=ps.executeUpdate(); if(count!=0)
{
ActionMessages mgs=new ActionMessages();
mgs.add("sucaddinstitution", new ActionMessage("add.suc"));
this.addErrors(request, mgs);
pageFoword ="addinstitutionreturn";
}
else
{
ActionMessages mg=new ActionMessages();
mg.add("loseaddinstitutiont", new ActionMessage("add.lose"));
this.addErrors(request, mg);
pageFoword ="addinstitutionreturn";
}
}
catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward(pageFoword);
.xml文件
<action
attribute="institutionForm"
input="/addinstitution.jsp"
name="institutionForm"
path="/addinstitution"
scope="request"
type="com.institution.struts.action.AddInstitutionAction">
<set-property property="cancellable" value="true" />
</action> <forward name="addinstitutionreturn" path="/addinstitution.jsp" />当没输入信息点添加按钮会进入validate验证, 当输入信息后点添加按钮,没执行任何的Action操作, 只是刷新了一次页面,并且输入信息刷空. 请问这是为什么?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货