2013年10月30日星期三

struts1.3 get less than the value of the jsp page , solving

In struts form classes and services in classes and class actions , the configuration file is also written a corresponding and , but still fail to get value , how is it ? Brother just learning struts. .
------ Solution ---------------------------------------- ----
still use struts1.x ah. . Good old , you also can not say to you to find the problem , at least to the point code
------ For reference only ------------------- --------------------


No way , the teacher said to be familiar with struts1.x, proficient 2.x. . .

action code :
// 删除
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
StudentService service = new StudentService();
StudentForm studentForm = new StudentForm();
System.out.println(studentForm.getSid());
if (service.Delete(studentForm.getSid())) {
response.getWriter().print("<script>alert('" + studentForm.getSname() + "删除成功!');</script>");
return mapping.findForward("to_index");
}
return null;
}


form code ( with get and set up )
public class StudentForm extends ActionForm {
private Integer sid;
private String sname;
private Integer ssex;
private String semail;


Then the configuration file :
<struts-config>
<form-beans>
<form-bean name="StudentForm" type="com.accp.forms.StudentForm"></form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action name="StudentForm" path="/student"
type="com.accp.actions.StudentAction" parameter="op">
<forward name="to_index" path="/index.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="com.accp.ApplicationResources" />
</struts-config>

The final step is the jsp :
<body>
<form method="post" action="student.do?op=delete" >
<table border="1" align="center">
<tr>
<th>学生编号</th>
<th>学生姓名</th>
<th>学生性别</th>
<th>学生邮箱</th>
<th>操作</th>
</tr>
<c:forEach var="student" items="${student}">
<tr>
<td>
<input type="hidden" value="${student.sid}" name="sid" />
${student.sid}
</td>
<td>${student.sname}</td>
<td>${student.ssex}</td>
<td>${student.semail}</td>
<td><input type="submit" value="删除" /></td>
</tr>
</c:forEach>
</table>
</form>

------ For reference only ----------------------------------- ----

  
No way , the teacher said to be familiar with struts1.x, proficient 2.x. . .   
  
action code :   
// 删除
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
StudentService service = new StudentService();
StudentForm studentForm = new StudentForm();
System.out.println(studentForm.getSid());
if (service.Delete(studentForm.getSid())) {
response.getWriter().print("<script>alert('" + studentForm.getSname() + "删除成功!');</script>");
return mapping.findForward("to_index");
}
return null;
}
  
  
form code ( with get and set up )   
public class StudentForm extends ActionForm {
private Integer sid;
private String sname;
private Integer ssex;
private String semail;
  
  
Then the configuration file :   
<struts-config>
<form-beans>
<form-bean name="StudentForm" type="com.accp.forms.StudentForm"></form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action name="StudentForm" path="/student"
type="com.accp.actions.StudentAction" parameter="op">
<forward name="to_index" path="/index.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="com.accp.ApplicationResources" />
</struts-config>
  
The final step is the jsp :   
<body>
<form method="post" action="student.do?op=delete" >
<table border="1" align="center">
<tr>
<th>学生编号</th>
<th>学生姓名</th>
<th>学生性别</th>
<th>学生邮箱</th>
<th>操作</th>
</tr>
<c:forEach var="student" items="${student}">
<tr>
<td>
<input type="hidden" value="${student.sid}" name="sid" />
${student.sid}
</td>
<td>${student.sname}</td>
<td>${student.ssex}</td>
<td>${student.semail}</td>
<td><input type="submit" value="删除" /></td>
</tr>
</c:forEach>
</table>
</form>
 

First, you can go do the action ?
Second, you put your get set method sent to ?
------ For reference only -------------------------------------- -


can , action where I define a Syso output , the output value is null
get and set:
public Integer getSid() {
return sid;
}

public void setSid(Integer sid) {
this.sid = sid;
}

public String getSname() {
return sname;
}

public void setSname(String sname) {
this.sname = sname;
}

public Integer getSsex() {
return ssex;
}

public void setSsex(Integer ssex) {
this.ssex = ssex;
}

public String getSemail() {
return semail;
}

public void setSemail(String semail) {
this.semail = semail;
}

------ For reference only ----------------------------------- ----
problem is here, you new out of print attributes must be null
StudentForm studentForm = new StudentForm ();
System.out.println (studentForm.getSid ());

------ For reference only ---------------------------------- -----


So : StudentForm studentForm = (StudentForm) form?
------ For reference only -------------------------------------- -

  
So : StudentForm studentForm = (StudentForm) form?  

Yes, give it a try , 1.x me somewhat forgotten , anyway, is not new out
------ For reference only --------------- ------------------------

    
So : StudentForm studentForm = (StudentForm) form?          
  
Yes, give it a try , 1.x me somewhat forgotten , anyway, is not new out  

able to get to , but I deleted the last one, the number is 6 , the output is 1 . What is wrong ?

没有评论:

发表评论