报错,For input String“name”,input输入的值能查询,但是input报错

数据库的表名报错情况eclipse报错情况,但是这里可以看出了以及查询成功了,连查询的size为1都显示出来了
查询界面的input框
![下面就是后台 java查询数据库的代码,先提取input框里面的值,input的name=“liuyan”,这里先检查story表里面有没有这个小说名,然后再查询该小说留言表。]

 @RequestMapping(value="/liuyan")
public ModelAndView liuyan(@RequestParam(value="liuyan", required=false) String liuyan, 
        HttpSession httpSession){
    System.out.println(liuyan);
    String sql = "select * from story where sname = '"+liuyan+"'";
    System.out.println(sql);
    String viewname="";
    final int[] isExist = new int[1];
    isExist[0] = 0;
    jt.query(sql, new RowCallbackHandler(){
        public void processRow(ResultSet rs) throws SQLException {
            if (rs.isFirst()) {
                isExist[0]=1;
            }
        }
    });
    if(isExist[0]==1) {
        String sql1 ="select * from "+liuyan+" limit 0,1000";
        System.out.println(sql1);
          viewname = "liuyan";
            final List<liuyan>liuyans = new ArrayList<liuyan>();
            jt.query(sql1, new RowCallbackHandler(){
                public void processRow(ResultSet rs1) throws SQLException {
                    System.out.println(rs1.getFetchSize());
                    while (!rs1.isAfterLast()) {
                        liuyan liuyanss = new liuyan(rs1.getString(1),
                                                rs1.getInt(2),
                                                rs1.getString(3),
                                                rs1.getString(4));
                        liuyans.add(liuyanss);
                        System.out.println(liuyans);
                        rs1.next();
                    }
                }
            });
            httpSession.setAttribute("liuyan", liuyan);
            System.out.println(liuyans.size());
            ModelAndView mv = new ModelAndView(viewname);
            mv.addObject("liuyans", liuyans);
            return mv;
    } else {
        httpSession.setAttribute("liuyan", liuyan);
        viewname = "chaxun_failed";
        ModelAndView mv = new ModelAndView(viewname);
        mv.addObject("liuyan", liuyan);

        return mv;

    }
   }

10个回答

${ liuyans.lname } 这个应该有问题吧,liuyans是个list,没有lname属性。parseInt可能是渲染标签带来的,最好是列一下第2个exception图的全部内容。

feelcycle_07
默默悟问 另外一般也要实现implements Serializable
2 年多之前 回复
feelcycle_07
默默悟问 回复qq_24932993: model类一般属性用private,然后实现set和get方法。有些bean是根据方法来找属性的,所以可能是因为没有get方法导致。
2 年多之前 回复
qq_24932993
qq_24932993 我两种都贴出来了,lname在package com.cx.shixun.model;这个下面的一个数据封装包中,我在下面贴出来了的
2 年多之前 回复

String sql1 ="select * from "+liuyan+" limit 0,1000"; 这是什么鬼

qq_24932993
qq_24932993 就是根据前台输入到input框里面的值,然后就是这里的liuyan这个对象的值多嘛,以此为对象查询该表的前1000条结果
2 年多之前 回复

你可以看看在你转到mv视图里面把liuyans遍历出来的时候是不是正确的

jsp:

 <div id="c1" class="content">
        <form action="liuyan" method="post">
        <table>
        <tr>
        <td style="width:400px">留言信息</td>
        <td style="width:150px"></td>
        <td style="width:150px"></td>
        </tr>
                             查询小说留言:<input type="text" name="liuyan"/><input type="submit" style="float-left:50px" value="查询" />
        </table>
        </div>

java:

 @RequestMapping(value="/liuyan")
public ModelAndView liuyan(@RequestParam(value="liuyan", required=false) String liuyan, 
        HttpSession httpSession){
    System.out.println(liuyan);
    String sql = "select * from story where sname = '"+liuyan+"'";
    System.out.println(sql);
    String viewname="";
    final int[] isExist = new int[1];
    isExist[0] = 0;
    jt.query(sql, new RowCallbackHandler(){
        public void processRow(ResultSet rs) throws SQLException {
            if (rs.isFirst()) {
                isExist[0]=1;
            }
        }
    });
    if(isExist[0]==1) {
        String sql1 ="select * from "+liuyan+" limit 0,1000";
        System.out.println(sql1);
          viewname = "liuyan";
            final List<liuyan>liuyans = new ArrayList<liuyan>();
            jt.query(sql1, new RowCallbackHandler(){
                public void processRow(ResultSet rs1) throws SQLException {
                    System.out.println(rs1.getFetchSize());
                    while (!rs1.isAfterLast()) {
                        liuyan liuyanss = new liuyan(rs1.getString(1),
                                                rs1.getInt(2),
                                                rs1.getString(3),
                                                rs1.getString(4));
                        liuyans.add(liuyanss);
                        System.out.println(liuyans);
                        rs1.next();
                    }
                }
            });
            httpSession.setAttribute("liuyan", liuyan);
            System.out.println(liuyans.size());
            ModelAndView mv = new ModelAndView(viewname);
            mv.addObject("liuyans", liuyans);
            return mv;
    } else {
        httpSession.setAttribute("liuyan", liuyan);
        viewname = "chaxun_failed";
        ModelAndView mv = new ModelAndView(viewname);
        mv.addObject("liuyan", liuyan);

        return mv;

    }
   }

目的jsp页面:

 <%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
        <%@page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!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=utf-8">
<title>Insert title here</title>
</head>
<body>
<a href="admin">回到管理页面</a>
${ liuyans.lname }的热门留言:
<div class="link">      <table><tr><td>用户名</td><td>留言</td><td>电话号码</td><td></td></tr>
<c:forEach items="${liuyans}" var="item">
<tr><td>${ item.lname }</td><td><p>${ item.text }</p></td><td><a>${ item.lphone }</a></td><td><a herf="/liuyan/${item.id}">删除</a></td>
</tr>
</c:forEach>
</table></div>
</body>
</html>

把前面的那个${ liuyans. lname}删除后就是这样的报错

就只有目的jsp修改了,其他都没有改;下面是目的jsp修改后的代码

 <%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!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=utf-8">
<title>Insert title here</title>
</head>
<body>
<a href="admin">回到管理页面</a>
的热门留言:
<div class="table" style="overflow:auto;height:300px" >
<table border="1px" bordercolor="red"><tr><td>用户名</td><td>留言</td><td>电话号码</td><td></td></tr>
<tr><td style="width:400px">小说名</td><td style="width:150px"></td></tr>
<c:forEach items="${liuyans}" var="item">
<tr><td>${ item.lname }</td><td><p>${ item.text }</p></td><td><a>${ item.lphone }</a></td><td><a herf="/liuyan/${item.id}">删除</a></td>
</tr>
</c:forEach>
</table></div>
</body>
</html>

莫名其妙什么都没做就成了这样的错误了

这是被java后台引用的数据封装的包

 package com.cx.shixun.model;

public class liuyan {
           public String lname;
           public int id;
           public String text;
           public String lphone;
        public liuyan() {
            super();
            // TODO Auto-generated constructor stub
        }
        @Override
        protected Object clone() throws CloneNotSupportedException {
            // TODO Auto-generated method stub
            return super.clone();
        }
        @Override
        public boolean equals(Object obj) {
            // TODO Auto-generated method stub
            return super.equals(obj);
        }
        @Override
        protected void finalize() throws Throwable {
            // TODO Auto-generated method stub
            super.finalize();
        }
        @Override
        public int hashCode() {
            // TODO Auto-generated method stub
            return super.hashCode();
        }
        @Override
        public String toString() {
            // TODO Auto-generated method stub
            return super.toString();
        }
        public liuyan(String lname, int id, String text, String lphone) {
            super();
            this.lname = lname;
            this.id = id;
            this.text = text;
            this.lphone = lphone;
        }


}

第一个错误:

 HTTP Status 500 – Internal Server Error

Type Exception Report

Message An exception occurred processing JSP page [/WEB-INF/pages/liuyan.jsp] at line [17]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.jasper.JasperException: An exception occurred processing JSP page [/WEB-INF/pages/liuyan.jsp] at line [17]

14: <div class="table" style="overflow:auto;height:300px" >
15: <table border="1px" bordercolor="red"><tr><td>鐢ㄦ埛鍚�</td><td>鐣欒█</td><td>鐢佃瘽鍙风爜</td><td></td></tr>
16: <c:forEach var="item" items="${ liuyans }">
17: <tr><td><p>${ item.lname }</p></td><td><p>${ item.text }</p></td><td><a>${ item.lphone }</a></td><td><a herf="/liuyan/${item.id}">鍒犻櫎</a></td>
18: </tr>
19: </c:forEach>
20: </table></div>


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:588)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:481)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1243)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

Root Cause

javax.el.PropertyNotFoundException: Property [lname] not found on type [com.cx.shixun.model.liuyan]
    javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:260)
    javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:212)
    javax.el.BeanELResolver.property(BeanELResolver.java:347)
    javax.el.BeanELResolver.getValue(BeanELResolver.java:92)
    org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
    org.apache.el.parser.AstValue.getValue(AstValue.java:169)
    org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:944)
    org.apache.jsp.WEB_002dINF.pages.liuyan_jsp._jspx_meth_c_005fforEach_005f0(liuyan_jsp.java:179)
    org.apache.jsp.WEB_002dINF.pages.liuyan_jsp._jspService(liuyan_jsp.java:133)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1243)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/8.5.23

第二个错误:

 HTTP Status 500 – Internal Server Error
Type Exception Report

Message javax.el.PropertyNotFoundException: Property [lname] not found on type [com.cx.shixun.model.liuyan]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: Property [lname] not found on type [com.cx.shixun.model.liuyan]
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:565)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:481)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1243)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Root Cause

javax.el.PropertyNotFoundException: Property [lname] not found on type [com.cx.shixun.model.liuyan]
    javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:260)
    javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:212)
    javax.el.BeanELResolver.property(BeanELResolver.java:347)
    javax.el.BeanELResolver.getValue(BeanELResolver.java:92)
    org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
    org.apache.el.parser.AstValue.getValue(AstValue.java:169)
    org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:944)
    org.apache.jsp.WEB_002dINF.pages.liuyan_jsp._jspx_meth_c_005fforEach_005f0(liuyan_jsp.java:179)
    org.apache.jsp.WEB_002dINF.pages.liuyan_jsp._jspService(liuyan_jsp.java:133)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1243)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Note The full stack trace of the root cause is available in the server logs.

Apache Tomcat/8.5.23

看看Exception的parseInt是哪里调用的,直接问题是你渲染的一个值被parseInt,但是string是"name"。问题可能是你传或取的值不对。

qq_24932993
qq_24932993 回复feelcycle_07: 我把两种错误显示都贴出来了,数据库中没有空数据。在目的jsp之前都正常执行,到了liuyan.jsp就出错,我把<c:ForEach>这一部分删除就能直接到达liuyan.jsp,后台查询仍然成功,只是在liuyan.jsp中没有展示出来,可能就是查询了,但是值的问题。
2 年多之前 回复
feelcycle_07
默默悟问 回复qq_24932993: 日志那应该有具体的exception内容吧,最好核对那个,这样看不好确认。是不是字段名不对,或者存在为null的字段。
2 年多之前 回复
qq_24932993
qq_24932993 回复feelcycle_07: 我又贴了新的目的jsp的代码了,前面的没改了,应该出在目的jsp上面,因为后台能够执行操作,能够查询数据库表中我自己添加的那一行数据,但是在目的jsp中没法读出来
2 年多之前 回复
feelcycle_07
默默悟问 回复qq_24932993: 另外问题不好解决就再列下。
2 年多之前 回复
qq_24932993
qq_24932993 回复qq_24932993: 我发现了一个问题就是我把目的的${ liuyans.name }删除后就没有这个问题了 但是出现了另外一个问题 ,上面贴出来的${ liuyans.name}是我把name改为lname之前的报错。
2 年多之前 回复
qq_24932993
qq_24932993 我贴出来了,所有相关的代码
2 年多之前 回复
qq_24932993
qq_24932993 回复feelcycle_07: 我好像没有用parselnt
2 年多之前 回复
feelcycle_07
默默悟问 回复qq_24932993: 你把exception的内容贴全看下。
2 年多之前 回复
qq_24932993
qq_24932993 就是前台jsp里面的那个input框下面的name=“liuyan”,传送到后台的多嘛,然后后台提取name=“liuyan”的字段,放到新的liuyan这个对象里面,然后拿去查询
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问