老师,添加数据后的数据没有在列表显示

老师,添加数据后的数据没有在列表显示

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="a" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>新建</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/add.css">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/dept/list.do">
慕课网科室管理
                   </a>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Hello, XXX!</h1>
<p>请小心的新增科室分类,要是建了一个错误的就不好了。。。</p>
</div>
<div class="page-header">
<h3><small>新建</small></h3>
</div>
<form class="form-horizontal" action="/category/list.do" method="post">
<div class="form-group">
<label for="name" class="name">名称 :</label>
<div class="name">
<input name="name" class="form-control" id="name">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">保存</button>&nbsp;&nbsp;&nbsp;
                   </div>
</div>
</form>
</div>
<footer class="text-center" >
copy@imooc
</footer>
</body>
</html>
//    /category/add.do     /category.jsp
public void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("name");
Date createTime = null;
Date updateTime = null;
try {
createTime = new SimpleDateFormat("yyyy-MM-dd HH:MM").parse(request.getParameter("createTime"));
updateTime = new SimpleDateFormat("yyyy-MM-dd HH:MM").parse(request.getParameter("updateTime"));
} catch (ParseException e) {
e.printStackTrace();
}
Category category = new Category();
category.setName(name);
category.setCreateTime(createTime);
category.setUpdateTime(updateTime);
categoryService.add(category);
response.sendRedirect("list.do");

}


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕小尤 2021-04-26 10:08:04

同学你好,1、建议同学查看数据库,查看是的有成功添加数据。

2、同学也可以检查是否有查询到数据,然后添加都域中,请求转发到页面中。如下所示:

http://img1.sycdn.imooc.com//climg/60861ffd09ecadfc10560276.jpg

祝学习愉快!

  • 提问者 复java_n #1

    没有添加成功老师,我刚刚看了一哈是我的from提交表单位置不对,更改之后又出现了空指针异常,我看主要报错问题在添加createTime和updateTime上,在这两条数据中不是要在jsp页面中获得那个属性嘛,但是这两个时间又是自动更改,我在jsp中就没有设置,也不知道怎么设置。不知道自己理解对没有,希望老师给予解答

    createTime = new SimpleDateFormat("yyyy-MM-dd HH:MM").parse(request.getParameter("createTime"));
    updateTime = new SimpleDateFormat("yyyy-MM-dd HH:MM").parse(request.getParameter("updateTime"));

    ava.lang.reflect.InvocationTargetException

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:498)

    at com.imooc.sm.global.DispatcherServlet.service(DispatcherServlet.java:58)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

    at com.imooc.sm.global.LoginFilter.doFilter(LoginFilter.java:25)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

    at com.imooc.sm.global.EncodingFilter.doFilter(EncodingFilter.java:18)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)

    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)

    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)

    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)

    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)

    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)

    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)

    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)

    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:615)

    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)

    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)

    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1626)

    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

    at java.lang.Thread.run(Thread.java:745)

    Caused by: java.lang.NullPointerException

    at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1439)

    at java.text.DateFormat.parse(DateFormat.java:364)

    at com.imooc.sm.controller.CategoryController.add(CategoryController.java:41)

    ... 33 more


    2021-04-26 19:11:57
  • 提问者 复java_n #2

    已经自己解决了,谢谢老师

    2021-04-26 19:52:20
  • 好帮手慕小尤 回复 提问者 复java_n #3

    同学解决了就好,继续加油!

    祝学习愉快!

    2021-04-27 09:32:25
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师