用ssh框架做的的管理系统,怎么更新?

pengjiang8508 2011-04-18 01:14:34
如题,我用ssh框架做了一个管理系统。删除更新都可以。删除是根据id号删的,就是每一个学生后面有一个删除按钮,点击就可以删除。现在我要更新,点击更新按钮后,跳转到edit.jsp页面,吧输入的信息输入后,提交给action去做。现在,id号可以传给edit页面,但是更改的数据是显示
javax.servlet.ServletException: java.lang.NumberFormatException: null
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:415)
java.lang.Integer.parseInt(Integer.java:497)
mystruts.action.EditAction.execute(EditAction.java:47)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)。
代码如下
editaction:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
EditForm editForm = (EditForm) form;// TODO Auto-generated method stub
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
StudentDAO crud=(StudentDAO)context.getBean("StudentDAO");
String ID=request.getParameter("ID");
int id=Integer.parseInt(ID);
Student student=crud.findById(id);
student.setInformation(editForm.getInformation());
student.setAge(editForm.getAge());
student.setName(editForm.getName());
crud.update(student);
return mapping.findForward("mywork");
}


edit.jsp:
<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>

<html>
<head>
<title>JSP for EditForm form</title>
</head>
<body>
<html:form action="/edit">
information : <html:text property="information"/><html:errors property="information"/><br/>
name : <html:text property="name"/><html:errors property="name"/><br/>
age : <html:text property="age"/><html:errors property="age"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
mywork.jsp: (负责跳转到edit页面)
<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ page import="java.sql.*" %>
<script type="text/javascript">
function check1(ID){
if(confirm("delete")){
location.href = "delete.do?ID=" + ID;
}
}
function check2(ID){
if(confirm("search")){
location.href = "search.do?ID=" + ID;
}
}
function check3(ID){
if(confirm("edit")){
location.href = "form/edit.jsp? ID=" + ID ;

}
}
</script>
<body>
<input type="button" value="insert" onclick="javascript:location.href='http://localhost:8080/manage/form/insert.jsp'">
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","8616158");
Statement sql=con.createStatement();
ResultSet rs=sql.executeQuery("select * from student");
if (rs.next())
{
%>
<table><tr><th>id</th><th>name</th></tr>
<% do{
%>
<tr>
<td><%=rs.getString("name")%></td>
<td><%=rs.getString("id")%></td>
<td><input type= button value= delete onclick=check1(<%=rs.getString("id")%>)></td>
<td><input type=button value=search onclick=check2(<%=rs.getString("id")%>)></td>
<td><input type=button value=edit onclick=check3(<%=rs.getString("id")%>)></td>
</tr>
<%
}while(rs.next());
%>
</table>
<%
}
%>
</body>

...全文
200 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengjiang8508 2011-04-19
  • 打赏
  • 举报
回复
问题已经解决。谢谢诶
墙角等红杏 2011-04-18
  • 打赏
  • 举报
回复
JDK1.5版本以下的不能自动装箱和拆箱,你看看是不是这个问题。
pengjiang8508 2011-04-18
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 harkue 的回复:]
引用 5 楼 pengjiang8508 的回复:
引用 3 楼 cbxjj 的回复:
edit.jsp
加上<html:hidden property="id"/>
int id=Integer.parseInt(ID);
这句发生错误了 空指针 很常见的错误

是空指针错误,现在我已经吧id号赋值给了jsp页面,现在要获取edit页面的那个id号,从而进行更新


你赋值的……
[/Quote]3楼的方法我也试了,在edit页面加了那句话还是不行
许亚洲 2011-04-18
  • 打赏
  • 举报
回复
调试一下啊,看id到底有没有值啊,再改
harkue 2011-04-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 pengjiang8508 的回复:]
引用 3 楼 cbxjj 的回复:
edit.jsp
加上<html:hidden property="id"/>
int id=Integer.parseInt(ID);
这句发生错误了 空指针 很常见的错误

是空指针错误,现在我已经吧id号赋值给了jsp页面,现在要获取edit页面的那个id号,从而进行更新
[/Quote]

你赋值的id是进入edit.jsp的时候用的。但是edit.jsp提交到edit.do必须按照3楼所说的,重新提交一次id,否则id是空值。
pengjiang8508 2011-04-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 cbxjj 的回复:]
edit.jsp
加上<html:hidden property="id"/>
int id=Integer.parseInt(ID);
这句发生错误了 空指针 很常见的错误
[/Quote]
是空指针错误,现在我已经吧id号赋值给了jsp页面,现在要获取edit页面的那个id号,从而进行更新
DT_C_XU_Y 2011-04-18
  • 打赏
  • 举报
回复
NumberFormatException.....
问题都已经说出来了...
自己看一下吧...
剑神一笑 2011-04-18
  • 打赏
  • 举报
回复
edit.jsp
加上<html:hidden property="id"/>
int id=Integer.parseInt(ID);
这句发生错误了 空指针 很常见的错误
zyr860122 2011-04-18
  • 打赏
  • 举报
回复
错误不都已经说了是Numberformat错了.....看看你输入的信息呗
pengjiang8508 2011-04-18
  • 打赏
  • 举报
回复
来个高手解决下啊,谢谢了

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧