这是JSP页面:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="com.hello.DAO.*, com.hello.userImpl.* , com.hello.User.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head><%
request.setCharacterEncoding("GBK");
UserDAO UD = new UserDAOImpl();
int id = 0;
if(request.getParameter("id")!=null && request.getParameter("id")!=""){
id = Integer.parseInt(request.getParameter("id"));
}
else{
out.println("id不能为空!");
// return;
}
User u = UD.loadById(id);
String action = request.getParameter("action");
if(action != null && action.trim().equals("updateUser")){
String name = request.getParameter("name");
String password = request.getParameter("password");
User user = new User();
user.setId(id);
user.setName(name);
user.setPassword(password);
UD.updateUser(user);
out.println("更新成功!");
} %><body>
<form action="updateUser.jsp" method="post">
<input type="hidden" name = "action" value = "updateUser"/>
<input type="hidden" name="action" value="<%=id %>"/>
<input type= "text" name="name" value="<%=u.getName()%>" ><br>
<input type= "password" name="password" value="<%=u.getPassword()%>" ><br>
<input type= "submit" name="submit" value="修改" >
</form>
<a href="index.jsp">返回首页</a>
</body>
</html>
所报的错信息如下:
java.lang.NullPointerException
at org.apache.jsp.updateUser_jsp._jspService(updateUser_jsp.java:104)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="com.hello.DAO.*, com.hello.userImpl.* , com.hello.User.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head><%
request.setCharacterEncoding("GBK");
UserDAO UD = new UserDAOImpl();
int id = 0;
if(request.getParameter("id")!=null && request.getParameter("id")!=""){
id = Integer.parseInt(request.getParameter("id"));
}
else{
out.println("id不能为空!");
// return;
}
User u = UD.loadById(id);
String action = request.getParameter("action");
if(action != null && action.trim().equals("updateUser")){
String name = request.getParameter("name");
String password = request.getParameter("password");
User user = new User();
user.setId(id);
user.setName(name);
user.setPassword(password);
UD.updateUser(user);
out.println("更新成功!");
} %><body>
<form action="updateUser.jsp" method="post">
<input type="hidden" name = "action" value = "updateUser"/>
<input type="hidden" name="action" value="<%=id %>"/>
<input type= "text" name="name" value="<%=u.getName()%>" ><br>
<input type= "password" name="password" value="<%=u.getPassword()%>" ><br>
<input type= "submit" name="submit" value="修改" >
</form>
<a href="index.jsp">返回首页</a>
</body>
</html>
所报的错信息如下:
java.lang.NullPointerException
at org.apache.jsp.updateUser_jsp._jspService(updateUser_jsp.java:104)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
解决方案 »
- 求助!!谁有jive项目源码??
- struts2+spring+hibernate使用HttpSessionBindingListener监听session时
- 各位老大 这个问题我搞了一天了 帮忙看看怎么回事
- eclipse3.2支持什么版本的jboss
- tomcat:Caused by: java.lang.OutOfMemoryError: PermGen space 问题?
- 请教jre目录的选择问题
- 在线请高手帮忙:WEBLOGIC7.02上怎么样发布两个路径?
- struts2问下载报错java.lang.IllegalStateException: getOutputStream() has already been
- tomcat和hudson邮件乱码问题
- redis安装失败
- 各位大侠,给推荐一个比较好的j2ee项目,练习一下。。。
- 搞了半天也不懂!! 求高手指点!!
这句没得到对象 是id或者loadById()的问题 通常是id没得到想要 的值
pageEncoding="GB18030"%>
<%@ page import="com.hello.DAO.*, com.hello.userImpl.* , com.hello.User.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here </title>
</head>
<%
request.setCharacterEncoding("GBK");
UserDAO UD = new UserDAOImpl();
String id = request.getParameter("id");
User u = null;
if(id !=null && id!=""){
u = UD.loadById(Integer.parseInt(id));
}
else{
out.println("id不能为空!");
response.sendRedirect(" 返回到你的前一个页面");
}
String action = request.getParameter("action");
if(action != null && action.trim().equals("updateUser")){
String name = request.getParameter("name");
String password = request.getParameter("password");
User user = new User();
user.setId(id);
user.setName(name);
user.setPassword(password);
UD.updateUser(user);
out.println("更新成功!");
}
%> <body>
<form action="updateUser.jsp" method="post">
<input type="hidden" name = "action" value = "updateUser"/>
<input type="hidden" name="action" value="<%=id %>"/>
<input type= "text" name="name" value="<%=u.getName()%>" > <br>
<input type= "password" name="password" value=" <%=u.getPassword()%>" > <br>
<input type= "submit" name="submit" value="修改" >
</form>
<a href="index.jsp">返回首页 </a>
</body>
</html>
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: An exception occurred processing JSP page /updateUser.jsp at line 4542: <input type="hidden" name = "action" value = "updateUser"/>
43: <input type="hidden" name="action" value="<%=id %>"/>
44:
45: <input type= "text" name="name" value="<%=u.getName()%>" ><br>
46: <input type= "password" name="password" value="<%=u.getPassword()%>" ><br>
47: <input type= "submit" name="submit" value="修改" >
48: </form>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause java.lang.NullPointerException
org.apache.jsp.updateUser_jsp._jspService(updateUser_jsp.java:103)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.烦死了,折腾我好几天了.
<input type= "text" name="name" value=" <%=u.getName()%>" > <br>
<input type= "password" name="password" value=" <%=u.getPassword()%>" > <br> 使用get方法的时候,还是会报空指针异常,那么这里,还是需要判断对象u是否为空呢
<input type= "text" name="name" value=" <%=u!=null?u.getName(): "" %>" > <br>
<input type= "password" name="password" value=" <%= u!=null? u.getPassword() : ""%>" > <br> 这里使用三元运算,再判断一次,如果为u为null,值name,和password都为" "空字符串,或者你定义其他的值,作为后台判断依据~
打印出来看看是否存在值
org.apache.jsp.updateUser_jsp._jspService(updateUser_jsp.java:104)