jsp里面的foreach如何正确获取从 servlet里list里的值

jsp页面
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

















宠物医院管理系统



系统首页 登录 注册

































用户ID:
用户登录名:
用户密码:
性别:
联系方式:
地址:
宠物ID:

请选择宠物ID..

${listpets}
/c:forEach

    </tr>






servlet页面
package www.bttc.manager.ownerservlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import www.bttc.manager.model.Pets;
import www.bttc.manager.model.Powner;
import www.bttc.manager.service.OwnerService;
import www.bttc.manager.service.PetsService;
import www.bttc.manager.service.impl.OwnerServiceImpl;
import www.bttc.manager.service.impl.PetsServiceImpl;
import www.bttc.manager.utils.ServiceException;

public class AddOwnerServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    doPost(request,response);       
}


public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setCharacterEncoding("UTF-8");// 设置请求的编码方式
    response.setCharacterEncoding("UTF-8");// 设置响应的编码方式
    response.setContentType("text/html;charset=utf-8");

    OwnerService ownerService=new OwnerServiceImpl();
    PetsService petsService=new PetsServiceImpl();
    HttpSession session=request.getSession();
    int ownerID=Integer.parseInt(request.getParameter("ownerID"));
    String osex=request.getParameter("osex");
    String oname=request.getParameter("oname");
    String opassword=request.getParameter("opassword");
    int phone=Integer.parseInt(request.getParameter("phone"));
    String address=request.getParameter("address");
    int petID=Integer.parseInt(request.getParameter("petID"));

    /*try {
        List<Pets> list=(List<Pets>) petsService.findAllPetID();
        //request.setAttribute("ownerID", ownerID);
        request.setAttribute("list", list);
    } catch (ServiceException e1) {
        e1.printStackTrace();
    }*/

    try {
        //Pets pets=new Pets();
        Pets pets=petsService.findPetsByPetsID(petID);
        if(ownerService.findOwnerByOwnerID(ownerID)!=null){
            session.setAttribute("message", "添加的普通用户记录已存在!");
            request.getRequestDispatcher("addowner.jsp").forward(request, response);
        }else{
            Powner owner=new Powner(ownerID,osex,oname,opassword,phone,address,pets);
            ownerService.addOwner(owner);
            //Powner owner=ownerService.addOwner(owner);
            session.setAttribute("message", "添加普通用户已成功!");
            request.getRequestDispatcher("/admin.jsp").forward(request, response);

        }
    } catch (ServiceException e) {
        e.printStackTrace();
    }



}

}
另一个servlet

package www.bttc.manager.ownerservlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import www.bttc.manager.model.Pets;
import www.bttc.manager.service.PetsService;
import www.bttc.manager.service.impl.PetsServiceImpl;
import www.bttc.manager.utils.ServiceException;

public class SelectPetID extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    doPost(request,response);

}

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    request.setCharacterEncoding("UTF-8");// 设置请求的编码方式
    response.setCharacterEncoding("UTF-8");// 设置响应的编码方式
    response.setContentType("text/html;charset=utf-8");

    //int petID=Integer.parseInt(request.getParameter("petID"));
    PetsService petsService=new PetsServiceImpl();

    try {
        List<Pets> pets = petsService.findAllPetID(); 
        request.setAttribute("listpets", pets);
        request.getRequestDispatcher("/addowner.jsp").forward(request, response);
    } catch (ServiceException e) {
        e.printStackTrace();
    }


}

}

2个回答

$(requestScope.listpets)这样就在前台获得了后台传来的list集合
关于遍历后台传来的list
可以用JSTL标签中的foreach
var就是后台传的list,item是遍历的元素。很长时间没写JavaWeb了,可能forEach里的属性我记错了

sinat_33164199
sinat_33164199 现在遇到的错误是这样的java.lang.NumberFormatException: For input string: ""
4 年多之前 回复
sinat_33164199
sinat_33164199 我现在遍历不了list的值,我该怎么改?
4 年多之前 回复

<%
List list = (List)request.getAttribute("listpets");
for(Object o: list){
Pets p = (Pets)o;

%>

<%=p.getName()%>

<%}%>

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
servlet里存储数据的list,用<c:forEach>方法一直显示不到jsp页面
servlet: public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); //获取所有的书本 List<Book> list=new ArrayList<Book>(); list=BookDB.findALLBook(); request.setAttribute("list", list); request.getRequestDispatcher("/main.jsp").forward(request, response); } ``` jsp: ```<c:forEach items="${list}" var="item"> ${item.bookId} ${item.bookName} ${item.bookPrice}<br/> </c:forEach>
JSP网页的EL表达式,无法获取另一个servlet类的request域对象中的数据。
jsp页面主要代码: <c:forEach items="${contacts }" var="con" varStatus="varSta"> <tr align="center"> <td>${varSta.count}</td> <td>${con.name }</td> <td>${con.gender }</td> <td>${con.age }</td> <td>${con.phone }</td> <td>${con.email}</td> <td>${con.city }</td> </tr> </c:forEach> servlet页面代码: ContactService cs=new ContactServiceImple(); List<Contact> list=cs.findContacts(); request.setAttribute("contacts", list);//设置request域对象 request.getRequestDispatcher("/contactList.jsp").forward(request, response); 问题补充: 如果我访问这个Servlet类,这个类会转发到上面那个jsp页面,并传入的还有数据,可是我先访问这个JSP页面,页面是没有request域对象数据。
在JSP中的<c:forEach items="${list}" var="publish" varStatus="status">想更换数据表publish为book,更换后无法显示,请问各位大神怎么解决该问题?
一开始在我的JSP项目中,正常运行显示,后来发现页面显示时,数据库中的数据表显示错误,我在页面当中显示的是数据库library中publish表中的数据信息,但实际上我需要的是数据库library中book表中的信息,替换数据表后,用<c:forEach>标签遍历查询,却显示空白,连表格框架都消失了,请问我该如何修改,才能将表publish成功替换成表book?恳求各位大佬指点,感激不尽! 如下,为publish表成功显示的图片 ![图片说明](https://img-ask.csdn.net/upload/202003/12/1583977874_80197.png) 如下,为book表显示失败的图片 ![图片说明](https://img-ask.csdn.net/upload/202003/12/1583978028_493291.png) ``` <!--以下为publish表显示成功的代码--> <c:forEach items="${list}" var="publish" varStatus="status"> <c:choose> <c:when test="${status.index%2 == '0'}"> <tr class="odd"> <td>${status.index+ 1}</td> <td>${publish.name}</td> <td>${publish.addr}</td> <td>${publish.tel}</td> <td>${book.price}</td> <td> <a href="<%=basePath%>publish/form?id=${book.id}">修改</a> <a href="<%=basePath%>publish/del?id=${book.id}" onclick="return confirm('你确认要删除吗?');"">删除</a> </td> </tr> </c:when> <c:otherwise> <tr class="even"> <td>${status.index+ 1}</td> <td>${publish.name}</td> <td>${publish.addr}</td> <td>${publish.tel}</td> <td>${book.price}</td> <td> <a href="<%=basePath%>publish/form?id=${book.id}">修改</a> <a href="<%=basePath%>publish/del?id=${book.id}" onclick="return confirm('你确认要删除吗?');"">删除</a> </td> </tr> </c:otherwise> </c:choose> </c:forEach> <!--以下为更改后book表显示失败的代码--> <!--以下为更改后book表显示失败的代码--> <!--以下为更改后book表显示失败的代码--> <!--以下为更改后book表显示失败的代码--> <c:forEach items="${list}" var="book" varStatus="status"> <c:choose> <c:when test="${status.index%2 == '0'}"> <tr class="odd"> <td>${status.index+ 1}</td> <td>${book.name}</td> <td>${book.code}</td> <td>${book.auther}</td> <td>${book.price}</td> <td> <a href="<%=basePath%>book/form?id=${book.id}">修改</a> <a href="<%=basePath%>book/del?id=${book.id}" onclick="return confirm('你确认要删除吗?');"">删除</a> </td> </tr> </c:when> <c:otherwise> <tr class="even"> <td>${status.index+ 1}</td> <td>${book.name}</td> <td>${book.code}</td> <td>${book.author}</td> <td>${book.price}</td> <td> <a href="<%=basePath%>book/form?id=${book.id}">修改</a> <a href="<%=basePath%>book/del?id=${book.id}" onclick="return confirm('你确认要删除吗?');"">删除</a> </td> </tr> </c:otherwise> </c:choose> </c:forEach> ``` 当运行publish表那张图显示的项目时,无报错 2020-3-12 10:12:16 org.apache.catalina.core.AprLifecycleListener init 信息: Loaded APR based Apache Tomcat Native library 1.1.29 using APR version 1.4.8. 2020-3-12 10:12:16 org.apache.catalina.core.AprLifecycleListener init 信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. 2020-3-12 10:12:17 org.apache.catalina.core.AprLifecycleListener initializeSSL 信息: OpenSSL successfully initialized (OpenSSL 1.0.1e 11 Feb 2013) 2020-3-12 10:12:17 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["http-apr-8080"] 2020-3-12 10:12:17 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["ajp-apr-8009"] 2020-3-12 10:12:17 org.apache.catalina.startup.Catalina load 信息: Initialization processed in 849 ms 2020-3-12 10:12:17 org.apache.catalina.core.StandardService startInternal 信息: Starting service Catalina 2020-3-12 10:12:17 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet Engine: Apache Tomcat/7.0.52 2020-3-12 10:12:17 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory D:\MyEclipse\Tomcat7.0\webapps\Code 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/core is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined 2020-3-12 10:12:28 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined 2020-3-12 10:12:28 org.apache.tomcat.websocket.server.WsSci onStartup 信息: JSR 356 WebSocket (Java WebSocket 1.0) support is not available when running on Java 6. To suppress this message, run Tomcat on Java 7, remove the WebSocket JARs from $CATALINA_HOME/lib or add the WebSocketJARs to the tomcat.util.scan.DefaultJarScanner.jarsToSkip property in $CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7 WebSocket API will be available. 2020-3-12 10:12:28 org.apache.catalina.core.ApplicationContext log 信息: No Spring WebApplicationInitializer types detected on classpath 2020-3-12 10:12:29 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring root WebApplicationContext 2020-3-12 10:12:41 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring FrameworkServlet 'springServlet' ========= Enabled refresh mybatis mapper ========= 2020-3-12 10:13:00 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory D:\MyEclipse\Tomcat7.0\webapps\docs 2020-3-12 10:13:00 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory D:\MyEclipse\Tomcat7.0\webapps\examples 2020-3-12 10:13:00 org.apache.catalina.core.ApplicationContext log 信息: ContextListener: contextInitialized() 2020-3-12 10:13:00 org.apache.catalina.core.ApplicationContext log 信息: SessionListener: contextInitialized() 2020-3-12 10:13:00 org.apache.catalina.core.ApplicationContext log 信息: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@fa4b23') 2020-3-12 10:13:00 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory D:\MyEclipse\Tomcat7.0\webapps\host-manager 2020-3-12 10:13:00 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory D:\MyEclipse\Tomcat7.0\webapps\igeek 2020-3-12 10:13:00 org.apache.catalina.loader.WebappClassLoader validateJarFile 信息: validateJarFile(D:\MyEclipse\Tomcat7.0\webapps\igeek\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class 2020-3-12 10:13:01 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory D:\MyEclipse\Tomcat7.0\webapps\library 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://www.springframework.org/tags/form is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://www.springframework.org/tags is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/core is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined 2020-3-12 10:13:04 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined 2020-3-12 10:13:04 org.apache.catalina.core.ApplicationContext log 信息: No Spring WebApplicationInitializer types detected on classpath 2020-3-12 10:13:04 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring root WebApplicationContext log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 2020-3-12 10:13:14 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory D:\MyEclipse\Tomcat7.0\webapps\manager 2020-3-12 10:13:14 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory D:\MyEclipse\Tomcat7.0\webapps\ROOT 2020-3-12 10:13:14 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory D:\MyEclipse\Tomcat7.0\webapps\springmvc03fAjax 2020-3-12 10:13:14 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory D:\MyEclipse\Tomcat7.0\webapps\springmvc03LYF 2020-3-12 10:13:16 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://www.springframework.org/tags/form is already defined 2020-3-12 10:13:16 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://www.springframework.org/tags is already defined 2020-3-12 10:13:16 org.apache.catalina.core.ApplicationContext log 信息: No Spring WebApplicationInitializer types detected on classpath 2020-3-12 10:13:16 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory D:\MyEclipse\Tomcat7.0\webapps\SSH 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/core is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined 2020-3-12 10:13:27 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined 2020-3-12 10:13:27 org.apache.catalina.core.ApplicationContext log 信息: No Spring WebApplicationInitializer types detected on classpath ====================================================================== 欢迎使用 JeeSite 快速开发平台 - Powered By http://jeesite.com ====================================================================== 2020-3-12 10:13:28 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring root WebApplicationContext 2020-03-12 10:13:32,591 WARN [net.sf.ehcache.DiskStorePathManager] - diskStorePath '..\temp\jeesite\ehcache' is already used by an existing CacheManager either in the same VM or in a different process. The diskStore path for this CacheManager will be set to ..\temp\jeesite\ehcache\ehcache_auto_created4673197487363253977diskstore. To avoid this warning consider using the CacheManager factory methods to create a singleton CacheManager or specifying a separate ehcache configuration (ehcache.xml) for each CacheManager instance. 2020-03-12 10:13:32,657 WARN [sf.ehcache.store.disk.DiskStorageFactory] - Data in persistent disk stores is ignored for stores from automatically created directories. Remove diskPersistent or resolve the conflicting disk paths in cache configuration. Deleting data file D:\MyEclipse\Tomcat7.0\bin\..\temp\jeesite\ehcache\ehcache_auto_created4673197487363253977diskstore\active%0053essions%0043ache.data 2020-3-12 10:13:41 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring FrameworkServlet 'springServlet' ========= Enabled refresh mybatis mapper ========= 2020-3-12 10:13:50 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-apr-8080"] 2020-3-12 10:13:50 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-apr-8009"] 2020-3-12 10:13:50 org.apache.catalina.startup.Catalina start 信息: Server startup in 92843 ms 当运行book表那张图显示的项目时,出现报错 报错信息: 2020-3-12 10:14:33 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring FrameworkServlet 'springmvc' 2020-3-12 10:14:36 org.apache.jasper.compiler.TldLocationsCache tldScanJar 信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 2020-3-12 10:14:38 org.apache.catalina.core.ApplicationDispatcher invoke 严重: Servlet.service() for servlet jsp threw exception javax.el.PropertyNotFoundException: Property 'code' not found on type com.library.entity.Publish at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:229) at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:206) at javax.el.BeanELResolver.property(BeanELResolver.java:317) at javax.el.BeanELResolver.getValue(BeanELResolver.java:85) at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104) at org.apache.el.parser.AstValue.getValue(AstValue.java:182) at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184) at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:967) at org.apache.jsp.WEB_002dINF.jsp.publishList_jsp._jspService(publishList_jsp.java:708) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338) at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) at javax.servlet.http.HttpServlet.service(HttpServlet.java:620) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:119) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) 2020-3-12 10:14:38 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [springmvc] in context with path [/library] threw exception [An exception occurred processing JSP page /WEB-INF/jsp/publishList.jsp at line 123 120: <tr class="odd"> 121: <td>${status.index+ 1}</td> 122: <td>${book.name}</td> 123: <td>${book.code}</td> 124: <td>${book.auther}</td> 125: <td>${book.price}</td> 126: <td> Stacktrace:] with root cause javax.el.PropertyNotFoundException: Property 'code' not found on type com.library.entity.Publish at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:229) at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:206) at javax.el.BeanELResolver.property(BeanELResolver.java:317) at javax.el.BeanELResolver.getValue(BeanELResolver.java:85) at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104) at org.apache.el.parser.AstValue.getValue(AstValue.java:182) at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184) at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:967) at org.apache.jsp.WEB_002dINF.jsp.publishList_jsp._jspService(publishList_jsp.java:708) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338) at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) at javax.servlet.http.HttpServlet.service(HttpServlet.java:620) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:119) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619)
Jsp/Java调用Servlet中实体类报错
public class EmpInfoClass { public static String empID; public static String empName; } ``` <c:forEach var = "listitem" items = "${list}"> ${listitem.empID } </c:forEach> # ``` 数据库查询一个字段添加到list中,jsp前台输出报错 ![图片说明](https://img-ask.csdn.net/upload/202003/05/1583374834_337115.jpg)
servlet 如何传值给JSP,并遍历
各位大佬本自学小白又来问问题 ``` resp.setCharacterEncoding("UTF-8"); req.setAttribute("list", list); req.getRequestDispatcher("/index.jsp").forward(req,resp); ``` 如何将servlet中的list传到,并遍历到表里 ``` <table border="1"> <tr> <th>员工编号</th> <th>员工姓名</th> <th>部门名称</th> <th>签到时间</th> </tr> </table> ``` ----------------------------------------------------------------- ``` <table border="1"> <tr> <th>员工编号</th> <th>员工姓名</th> <th>部门名称</th> <th>签到时间</th> </tr> <c:forEach items="${list}" var="dataList"> <tr> <td>${dataList.pin}</td> <td>${dataList.Name}</td> <td>${dataList.defaultdeptid}</td> <td>${dataList.checktime}</td> </tr> </c:forEach> </table> ``` 我在jsp页面遍历之后出错 ``` 重: Servlet.service() for servlet [indexervlet] in context with path [/zpyr] threw exception [An exception occurred processing JSP page /index.jsp at line 33 30: <c:forEach items="${list}" var="dataList"> 31: <tr> 32: <td>${dataList.pin}</td> 33: <td>${dataList.Name}</td> 34: <td>${dataList.defaultdeptid}</td> 35: <td>${dataList.checktime}</td> 36: </tr> Stacktrace:] with root cause ```
servlet进行修改操作,jsp页面传值list不知道该怎么做
<form action="delete.do" method="get"> <table border="1" cellspacing="0" cellpadding="0" width="100%" style="align:center;"> <tr bgcolor="ff9900" style="font-weight:bold;"> <th >操作</th> <th>ID</th><th>姓名</th><th>性别</th><th>学历</th><th>生日</th><th>籍贯</th><th>登录密码</th><th>工资</th></tr> <%//循环显示数据 ArrayList<User> list=(ArrayList)session.getAttribute("list"); System.out.print(list.size()); // 取request里面的对象队列 //判断长度是否为0,即空 if(list.size()!=0){ //根据长度循环 for(int i=0;i<list.size();i++){ User use1 =new User(); //新建对象use1 use1 = list.get(i); //每循环一次后取到的list值将此时的值保存到对象里 %> <tr> <td><input type="checkbox" value=<%=use1.getId() %> name="test" > </td> <td><%=use1.getId() %></td> <td><%=use1.getName() %></td> <td><%=use1.getSex() %></td> <td><%=use1.getWorking()%></td> <td><%=use1.getBirth()%></td> <td><%=use1.getBorth()%></td> <td><%=use1.getLoginpass()%></td> <td><%=use1.getSalary()%></td> </tr> <% System.out.print(use1);%> <% } } else{ %><tr><td colspan="6">数据库中没有数据!</td></tr><% }%> </table> </form> <input type="button" name="test" onclick="takeId()" value="删除"> <input type="button" name="test" onclick="updateId()" value="修改"> <input type="button" onclick="window.location.href='user.jsp'" value="增加"> <input type="button" onclick="window.location.href='login.jsp'" value="退出"> </body> </html> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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"> </head> <body> <form action="add.do" method="get" > <h4>修改用户</h4> <c:forEach items="${list}" var="list"> 用户名ID: <input type="text" name="AB" value="${id}"/><br/> 登录密码: <input type="text" name="loginpass" value="${list.loginpass}"/></input><br/> 确认密码: <input type="text" name="loginpass" ></input><br/> 性别:<input type="radio" name="sex">男 <input type="radio" name="sex">女 <br> 用户姓名:<input type="text" name="username" value="${list.username}"><br> 出生日期: <input type="text" name="birth" value="${list.birth}"/></input><br/> 工 资 : <input type ="text" name="salary" value="${list.salary}"/><br> <select id="working" > <option >学历:</option> <option >大专</option> <option >本科</option> <option >硕士</option> <option >博士</option> </select><br> <select name=" borth"> <option selected>籍贯:</option> <option >南京</option> <option >芜湖</option> </select><br> </c:forEach> <input type="submit" value="保存修改" > </form> <!-- form表单的作用能将多条信息整合起来进行传送。 submit是一个提交按钮,与button不同的是,submit会提交表单。 而button是单纯的一个按钮--> </body> </html>
关于jsp用session传递list 在另一页面获取并遍历输出list
如题 ``` List<shuxing> list = new ArrayList<shuxing>(); shuxing s=new shuxing(); while(rs.next()){ s.setsShopName(rs.getString("sShopName")); s.setiNumbHj(rs.getString("iNumbHj")); s.setrMoneyHj(rs.getString("rMoneyHj")); list.add(s); } session.setAttribute("rs",list); response.sendRedirect("dian.jsp"); conn.close(); 获取 <c:forEach items="rs" var="user" > <c:out value="${user.sShopName}"/> </c:forEach> ``` 这样写报错HTTP Status 500 - type Exception report message 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 /dian.jsp at line 55 52: <!-- Codrops top bar --><!--/ Codrops top bar --> 53: <!-- <td><%Object q=session.getAttribute("rs"); %><%=q %></td>--> 54: <c:forEach items="rs" var="user" > 55: <c:out value="${user.sShopName}"/> 56: 57: </c:forEach> 58: </div> Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
jsp页面里的list确定为有值 报错: 没有为参数号1设置值
<!-- 下面是jsp代码 目的是把jsp里的值传到servlet里面 --> <form action="ShopSrvlet" method="post"> <table border="2" align="center"> <tr style="white-space: nowrap;"> <td>图书编号</td> <td>图书名称</td> <td>图书作者</td> <td>图书出版社</td> <td>图书出版日期</td> <td>图书页数</td> <td>图书价格</td> </tr> <c:forEach var="as" items="${list}"> <tr> <td><a href="ShowById?id=${as.id}" >${as.id}</a></td> <td>${as.name} </td> <td>${as.author}</td> <td>${as.publish}</td> <td>${as.pdate}</td> <td>${as.isbn}</td> <td>${as.page}</td> </tr> </c:forEach> <tr> <td colspan="7" align="center"><input type="submit" value="提交"/></td> </tr> </table> </form> <!-- 下面是ShowById的代码 这是一个servlet--> @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); int Id = Integer.parseInt( request.getParameter("id")) ; Shop sp = new ShopDaoImpl().ShowAllById(Id); System.out.println(Id); request.setAttribute("sp",sp); request.getRequestDispatcher("dds.jsp").forward(request, response); }
用servlet打出数据库在jsp页面列表展示,但是jsp页面始终不出现数据库中的值
这是servlet: public class OrderListServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ List<Order> list = new ArrayList<Order>(); OrderDAO dao=new OrderDAOImpl(); String sql = "select * from order"; response.setContentType("text/html"); try { list = dao.getorderList(sql); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } request.setAttribute("orderlist", list); request.getRequestDispatcher("OrderList.jsp").forward(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ } } function: public List<Order> getorderList(String sql) throws Exception{ List<Order> list = new ArrayList<Order>(); // sql = "select * from order"; //String sql2 = "select * from productinfo"; PreparedStatement pstmt = null ; DBConnect dbc = null; java.sql.ResultSet rs=null; try{ dbc = new DBConnect() ; pstmt = dbc.getConnection().prepareStatement(sql) ; rs = pstmt.executeQuery(sql); while(rs.next()){ String buyername = rs.getString("buyername"); // String productname = rs.getString("productname"); // String productimage = rs.getString("productimage"); // String unitnum = rs.getString("unitnum"); // String unitvalue = rs.getString("unitvalue"); String id = rs.getString("id"); String sum = rs.getString("sum"); Order order = new Order(); order.setId(id); order.setBuyername(buyername); // order.setProductname(productname); // order.setUnitvalue(unitvalue); // order.setUnitnum(unitnum); order.setSum(sum); list.add(order); } rs.close(); pstmt.close(); }catch (SQLException e){ System.out.println(e.getMessage()); }finally{ dbc.close() ; } return list; } jsp: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page import="java.io.*,java.util.*,java.sql.*"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%@ page import="jspservlet.servlet.*"%> <body> <form method="post" action="./orderlist"> <table border="1"cellpadding="0" cellspacing="0"width="80%" align="center"> <tr> <th>ID</th> <th>buyer name</th> <th>sum</th> </tr> <c:forEach items="${request.orderlist}" var="ordert"> <tr> <td>${order.id }</td> <td>${order.buyername }</td> <td>${order.sum }</td> </tr> </c:forEach> </table> </form> </body>
jsp与servlet数组怎么传值接收
<script type="text/javascript"> function se(){ var stno=document.getElementById("date1").value; var stno1=document.getElementById("date2").value; var stno2=document.getElementById("year1").value; var stno3=document.getElementById("month1").value; var stno4=document.getElementById("man").value; window.location="${pageContext.request.contextPath}/servlet/GrowthOwnerServlet?stno="+stno+"&stno1="+stno1+"&stno2="+stno2+"&stno3="+stno3+"&stno4="+stno4+""; } function se1(){ var stno=document.getElementById("date1").value; var stno1=document.getElementById("date2").value; var stno2=document.getElementById("year1").value; var stno3=document.getElementById("month1").value; var stno4=document.getElementById("man").value; window.location="${pageContext.request.contextPath}/servlet/GrowthOwnerExcel?stno="+stno+"&stno1="+stno1+"&stno2="+stno2+"&stno3="+stno3+"&stno4="+stno4+""; } function checkAll(field) { var selectFlags = document.getElementsByName("selectFlag"); for (var i=0; i<selectFlags.length; i++) { selectFlags[i].checked = field.checked; } } function see(){ var stno=document.getElementById("date1").value; var stno1=document.getElementById("date2").value; var stno2=document.getElementById("year1").value; var stno3=document.getElementById("month1").value; var stno4=document.getElementById("man").value; var selectFlags=[]; var selectFlags = document.getElementsByName("selectFlag"); var flag = false; for (var i=0; i<selectFlags.length; i++) { if (selectFlags[i].checked) { flag = true; break; } } alert(selectFlags); window.location="${pageContext.request.contextPath}/servlet/GrowthOwnersServlet?stno="+stno+"&stno1="+stno1+"&stno2="+stno2+"&stno3="+stno3+"&stno4="+stno4+"&selectFlags="+selectFlags+""; } </script> </head> <body class="body1"> <form name="matterForm" id="matterForm" > <div align="left" > 需求日期<input type="text" id="date1" name="date1" onclick="new Calendar().show(this);" value="${date1}" readonly="true" autocomplete="off" /> <input type="text" id="date2" name="date2" onclick="new Calendar().show(this);" value="${date2}" readonly="true" autocomplete="off" /> 需求年月<select name="year1" id="year1" onchange="onselectd();"> <option value="2017">2017年</option> <option value="2018">2018年</option> <option value="2019">2019年</option> <option value="2020">2020年</option> <option value="2021">2021年</option> <option value="2022">2022年</option> <option value="2023">2023年</option> </select> <select name="month1" id="month1" onchange="onselectd();"> <option value="01">1月</option> <option value="02">2月</option> <option value="03">3月</option> <option value="04">4月</option> <option value="05">5月</option> <option value="06">6月</option> <option value="07">7月</option> <option value="08">8月</option> <option value="09">9月</option> <option value="10">10月</option> <option value="11">11月</option> <option value="12">12月</option> </select> 店面区域范围<select name="man" id="man" onchange="onselectd();"> <option value="222104112">孙xx</option> <option value="222104360">张xx</option> <option value="222103816">谌xx</option> <option value="222103226">刘xx</option> <option value="222104891">罗xx</option> <option value="111222333">管xx</option> </select> <input type="button" id="button" onclick="see()" class="button1" value="查询" > <input type="button" id="button" onclick="se1()" class="button1" value="导出execl" > <c:forEach items="${fault}" var="i"> <tr> <td width="37" class="rd8"> <input name="selectFlag" type="checkbox" class="checkbox1" id="selectFlag" value="${i.shopid}"> </td> <td width="100" class="rd8"> <c:out value="${i.shopid}"></c:out> </td> </tr> </c:forEach> </div> ============================================== 后台servlet部分 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("text/html;charset=utf-8"); String date1=request.getParameter("stno"); String date2=request.getParameter("stno1"); String year1=request.getParameter("stno2"); String month1=request.getParameter("stno3"); String man=request.getParameter("stno4"); String [] ss= request.getParameterValues("selectFlags"); // System.out.println(date1); // System.out.println(man); // System.out.println(ss); DataManage mn=new DataManage(); request.getSession().setAttribute("date1", date1); request.getSession().setAttribute("date2", date2); request.getSession().setAttribute("year1", year1); request.getSession().setAttribute("month1", month1); request.setAttribute("qc",mn.getGrowthOwners(date1,date2,year1,month1,man,ss)); request.getRequestDispatcher("/page/model/alliance/growthOwner.jsp").forward(request, response); } ============= service 里的方法 public List<GrowthOwner> getGrowthOwners(String date1,String date2,String year1,String month1,String man,String[] ss){ List<GrowthOwner> pre=new ArrayList<GrowthOwner>(); Connection cn=null; PreparedStatement pr=null; ResultSet rs=null; try { cn=getConnection(); pr=cn.prepareCall("{ call companyreport.[dbo].[店成长率报表_个人] (?,?,?,?,?)}"); pr.setString(1,date1); pr.setString(2,date2); pr.setString(3, year1+"-"+month1); pr.setString(4,man); pr.setString(5, ss); rs=pr.executeQuery(); while(rs.next()){ pre.add(new GrowthOwner(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getString(9),rs.getString(10), rs.getString(11),rs.getString(12),rs.getString(13),rs.getString(14),rs.getString(15))); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { rs.close(); pr.close(); cn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return pre; }
jsp+servlet+sqlserver分页,前台获取的ID总为每一页信息的最后一项的ID?
# 求教大神:JSP+servlet+sqlserver分页查询后,在页面获取ID时,不管点击哪一项,传到后台的ID值都为每一页信息的最后一项的ID? ![这是前台页面](https://img-ask.csdn.net/upload/201704/12/1491958509_846310.png) serverlt代码: int pageIndex = 1;//页数 int pageCount = 0;//总页数 int count = 0;//总数据条数 Session session = HibernateUtil.openSession(); //数据总条数查询 SQLQuery sqlquery1 = session.createSQLQuery("select count(userID) from t_user"); List<Integer> numList = sqlquery1.list(); count = numList.get(0); pageCount = count/20+(count/20!=0?1:0);//总页数 //按钮处理分页 String indexnum = request.getParameter("pageindex"); if(indexnum!=null&&Integer.parseInt(indexnum)<=pageCount&&Integer.parseInt(indexnum)>0){ pageIndex = Integer.parseInt(indexnum); } //数据查询 SQLQuery sqlquery = session.createSQLQuery("select top 20 " + "u.userID,u.name,ad.address, ad.communityID,c.community,ad.building,ad.unit,ad.houseNum,u.phone,u.openDate,u.chageDate,u.isPrePaid,u.buyTimes "+ " from t_user as u left join t_address as ad on u.addressID=ad.addressID left join t_area as ar on ad.areaID=ar.areaID "+ " left join t_community as c on c.communityID=ad.communityID " +"where userID not in (select top "+20*(pageIndex-1)+" userID from t_user ) order by userID"); List<Object[]> olist = sqlquery.list(); //将要显示的字段传到userInfo.jsp request.setAttribute("olist", olist);//用户信息 request.setAttribute("count", count);//数据总条数 request.setAttribute("pageCount", pageCount);//数据总页数 request.setAttribute("pageIndex", pageIndex);//当前页数 request.getRequestDispatcher("userInfo.jsp").forward(request, response); ``` 前端代码: <c:forEach items="${olist }" var="o" > <tr> <td height="20" bgcolor="#FFFFFF"><div align="center"> <input type="checkbox" name="checkbox2" value="checkbox" /> </div></td> <td height="20" bgcolor="#FFFFFF"><div align="center" class="STYLE1"> <div align="center">${o[0] }</div> </div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${o[1] }</span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${o[2] }</span></div></td> <td bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${o[3] }</span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${o[4] }</span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${o[5] }</span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${o[6] }</span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${o[7] }</span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${o[8] }</span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${o[9] }</span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${o[10] }</span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${o[11] }</span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${o[12] }</span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE4"> <a><img src="images/edt.gif" width="13" height="13" />编辑</a>&nbsp; <a href="#" onclick="del()"><img src="images/del.gif" width="13" height="13" />删除</a> <script> function del(){ if(window.confirm("是否删除用户?")==true){ window.location.href="moduser?type=2&id="+${o[0] }; } } </script> </span></div></td> </tr> # </c:forEach> ```
通过Servlet显示数据库中的数据,报404
``` public class userListServlet { public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ Model model=new Model(); List<User>list=model.userSelect(); request.getSession().setAttribute("list", list); response.sendRedirect("listUsers1.jsp"); } } Model中的userSelect()方法如下: public List<User> userSelect(){ List users=new ArrayList(); try{ conn=s.getConncetion(); String sql="select * from user"; stat=conn.createStatement(); rs=stat.executeQuery(sql); User user; while(rs.next()){ user=new User(); user.setId(rs.getInt("id")); user.setName(rs.getString("name")); user.setPassword(rs.getString("password")); users.add(user); } s.closeAll(conn, stat, rs); }catch(SQLException e){ e.printStackTrace(); } return users; } listUsers1.jsp页面如下: <body> 数据库中所有用户: <table border="1"> <c:forEach items="${sessionScope.list }" var="user" varStatus="num"> <tr> <td>${user.id }</td> <td>${user.name }</td> <td>${user.password }</td> </tr> </c:forEach> </table> </body> web.xml配置如下: <servlet> <servlet-name>userListServlet</servlet-name> <servlet-class>control.userListServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>userListServlet</servlet-name> <url-pattern>/userListServlet</url-pattern> </servlet-mapping> ```
利用SERVLET跳转到JSP页面时显示乱码
单独打开SERVLET或者JSP,网页显示全部正常,在SERVLET里输出数据也显示正常,可是一转到JSP就全部乱码了。不仅是数据,只要是JSP里的中文就都成了? ``` package SERVLET; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import JDBC.S; import JDBC.SDao; @WebServlet("/ShowSServlet") public class ShowSServlet extends HttpServlet { private static final long serialVersionUID = 1L; public ShowSServlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().append("Served at: ").append(request.getContextPath()); request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); String currentpage=request.getParameter("currentpage"); if(null==currentpage || "".equals(currentpage)){ currentpage="1"; } List<S> list=SDao.selectPage(Integer.parseInt(currentpage)); int totalcount=SDao.selectS().size(); int row=5; int totalpage=(totalcount%row==0)?(totalcount/row):(totalcount/row+1); for(S l:list){ System.out.println(l.getSname()); } request.setAttribute("currentpage", currentpage); request.setAttribute("totalcount", totalcount); request.setAttribute("row", row); request.setAttribute("totalpage", totalpage); request.setAttribute("list", list); request.getRequestDispatcher("ShowS.jsp").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } } ``` ``` <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <!-- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> --> <title>信息一览</title> <style> table { border:thin solid black; border-collapse:collapse; width:60%; text-align:center; } th { border:thin solid black; } td { border:thin solid black; } </style> <script type="text/javascript"> function gotos(page){ location.href="ShowSServlet?currentpage="+page; } function gotod(sno){ location.href="DeleteSServlet?sno="+sno; } </script> </head> <body> <table align="center" > <tr> <th>学号</th> <th>姓名</th> <th>年龄</th> <th>院系</th> <th>操作</th> </tr> <c:forEach var="l" items="${list }"> <tr> <td>${l.sno }</td> <td>${l.sname }</td> <td>${l.age }</td> <td>${l.depart }</td> <td><a href="javascript:gotod(${l.sno })">删除</a></td> </tr> </c:forEach> </table> <center> <c:choose> <c:when test="${currentpage==1 }">首页&nbsp&nbsp上一页</c:when> <c:otherwise> <a href="javascript:gotos(1)">首页</a> <a href="javascript:gotos(${currentpage-1 })">上一页</a> </c:otherwise> </c:choose> <c:choose> <c:when test="${currentpage==totalpage }">下一页&nbsp&nbsp末页</c:when> <c:otherwise> <a href="javascript:gotos(${currentpage+1 })">下一页</a> <a href="javascript:gotos(${totalpage })">末页</a> </c:otherwise> </c:choose></br> 共有${totalcount }条记录,每页显示${row }条记录,当前为第${currentpage }页 </center> </body> </html> ``` ![图片说明](https://img-ask.csdn.net/upload/201612/30/1483063322_263678.png) ![图片说明](https://img-ask.csdn.net/upload/201612/30/1483063332_740186.png) ![图片说明](https://img-ask.csdn.net/upload/201612/30/1483063340_428375.png)
我使用iframe实现了点击左边栏 只有右边的内容变化 但在跳转到servlert并转向jsp时,jsp的表格样式无法显示
![图片说明](https://img-ask.csdn.net/upload/202002/13/1581587866_147157.png) <div id="header1" class="panel-heading" style="padding-top:15px"> <i class="glyphicon glyphicon-dashboard" ></i> <a href="${pageContext.request.contextPath }/DoctorServlet" target="mainiframe">&nbsp咨询师管理</a> </div> <div id="page_content"> <iframe name="mainiframe" src="admin_shouye.jsp" id="mainiframe" scrolling="no" onload="resizeFrameHeight()" frameborder="0" width="100%"></iframe> </div> servlet: protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DoctorDao ddao = new DoctorDao(); List<Doctor> findAll = ddao.findAllDoctor(); System.out.println(findAll); request.setAttribute("doc", findAll); request.getRequestDispatcher("Admin/doctor_find.jsp").forward(request, response); //response.sendRedirect("admin/doctor_find.jsp"); } jsp:<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <!-- 引入所使用的bootstrap文件 --> <link href="../css/bootstrap.min.css" rel="stylesheet"> <script src="../js/jquery-3.0.0.min.js"></script> <script src="../js/bootstrap.min.js"></script> <style type="text/css"> <style> #outer { width: 800px; height: 500px; position: absolute; } </style> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <div id="outer"> <center> <table class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr class="active"> <td>编号</td> <td>姓名</td> <td>个人照片</td> <td>密码</td> <td>性别</td> <td>年龄</td> <td>手机号</td> <td>邮箱</td> <td>等级</td> <td>技能</td> <td>状态</td> </tr> </thead> <tbody> <c:forEach items="${doc}" var="doc"> <tr> <td>${doc.doctor_id}</td> <td>${doc.doctor_name}</td> <td>${doc.img}</td> <td>${doc.doctor_pwd}</td> <td>${doc.sex}</td> <td>${doc.age}</td> <td>${doc.phone}</td> <td>${doc.email}</td> <td>${doc.level}</td> <td>${doc.skill}</td> <td>${doc.active}</td> </tr> </c:forEach> </tbody> </table> </center> </div> </body> </html>
没找到问题在哪!!大神帮忙看一下代码(JSP使用JSTL的c:forEach标签显示数据怎么不管用
``` <form name="myform" method="post" action="newstypeservlet?op=batchDelete"> <table border="1"> <tr> <th>编号</th> <th>类型名</th> <th>编辑</th> <th>删除</th> </tr> <c:forEach items="${requestScope.newsTypeList }" var="newsType" varStatus="status"> <tr style="background-color: ${status.index%2==0?'red':'green' } "> <td> <input type="checkbox" name="ids" value="${newsType.id }"/> ${newsType.id } </td> <td>${newsType.typeName }</td> <td><a href="newstypeservlet?op=toEdit&id=${newsType.id }">编辑</a></td> <td><a href="newstypeservlet?op=delete&id=${newsType.id }">删除</a></td> </tr> </c:forEach> <tr> <td colspan="4" > <input type="button" value="批量删除" onclick="checkSelected()"/> </td> </tr> </table> </form> ``` Servlet里的代码: ``` protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // System.out.println("进入sevlet"); request.setCharacterEncoding("UTF-8");// 解决Post提交时的乱码问题 String op = request.getParameter("op");// 注意:此处的JSP页面不放在根目录下,Servlet就无法接收到页面传来的数据,因为web.xml配置信息无法覆盖 if ("add".equals(op)) { addNewsType(request, response); } else if ("list".equals(op)) { listNewsType(request, response); } else if ("batchDelete".equals(op)) { batchDelete(request, response); } else if ("delete".equals(op)) { deleteById(request, response); } } // 新闻列表 private void listNewsType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { NewsTypeService newsTypeService = new NewsTypeService(); List<NewsType> newsTypeList = newsTypeService.findAll(); request.setAttribute("newsTypeList", newsTypeList); request.getRequestDispatcher("../listNewsType.jsp").forward(request, response); } private void deleteById(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); String idStr = request.getParameter("id"); if (idStr == null || "".equals(idStr)) { out.write("<script>alert('密码不能为空');history.back();</script>"); return; } int id = Integer.parseInt(idStr); NewsTypeService newsTypeService = new NewsTypeService(); newsTypeService.delete(id); // 删除数据后,返回列表 listNewsType(request, response); } private void batchDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String[] ids = request.getParameterValues("ids"); NewsTypeService newsTypeService = new NewsTypeService(); newsTypeService.batchDelete(ids); // 删除数据后,返回列表 listNewsType(request, response); } ``` service代码: ``` public class NewsTypeService { public int save(NewsType newsType) { return new NewsTypeDao().save(newsType); } public int batchDelete(String[] ids) { return new NewsTypeDao().batchDelete(ids); } public List<NewsType> findAll() { return new NewsTypeDao().findAll(); } public int delete(int id) { return new NewsTypeDao().delete(id); } ``` DAO里的代码 ``` public class NewsTypeDao { DBUtil dbUtil = new DBUtil(); // 保存新闻类型 public int save(NewsType newsType) { String sql = "insert into newstype(typeName) values (?)"; Object[] params = { newsType.getTypeName() }; return dbUtil.executeUpdate(sql, params); // executeUpdate的返回值是一个整数,指示受影响的行数(即更新计数) } public List<NewsType> findAll() { List<NewsType> newsTypeList = new ArrayList<NewsType>(); String sql = "select * from newstype"; ResultSet rs = dbUtil.executeQuery(sql, null); try { while (rs.next()) { NewsType newsType = new NewsType(rs.getInt("id"), rs.getString("typeName")); newsTypeList.add(newsType); } } catch (SQLException e) { e.printStackTrace(); return newsTypeList; } finally { dbUtil.closeAll(); } return newsTypeList; } /** * 批量删除 * * @param ids * 指定的ID集合 * @return */ public int batchDelete(String[] ids) { // TODO Auto-generated method stub String sql = "delete from newstype where id in(?)"; Object[] params = { ArrayUtil.array2String(ids, ",") }; return dbUtil.executeUpdate(sql, params); } /** * 根据Id进行删除 * * @param id * @return */ public int delete(int id) { String sql = "delete from newsType where id=?"; Object[] params = { id }; return dbUtil.executeUpdate(sql, params); } ## # }谢谢大神**** ```
javaweb如何实现点击商品页面跳转到本商品的详情页面
以上是jsp页面的代码,我是通过将从数据库获取到的所有商品封装到一个list集合中,使用request域存储数据,在jsp页面使用el获取的所有商品。我现在能否在这个基础上面实现点击商品,进入到本商品的详情界面,页面已经写好了。我自己的实现逻辑是:通过某个域存储商品的id信息,在servlet中获取到,去数据库中查找这件商品的所有信息,这个商品存这储到域空间中,在新的页面通过el获取,但是目前我无法实现将这个商品的id信息传存储到域空间中。我不知道这样能不能实现,是不是我的想法有错误,希望大神帮个忙!!! ``` <c:forEach items="${productList }" var="product"> <div class="col-md-2" style="height:250px"> <a href="product_info.htm"> <img src="${pageContext.request.contextPath }/${product.pimage }" width="170" height="170" style="display: inline-block;"> </a> <p> <a href="/WEB18/productOne" style='color: green'>${product.pname }</a> </p> <p> <font color="#FF0000">商城价:&yen;${product.shop_price }</font> </p> </div> </c:forEach> ``` 上面是所有商品的jsp页面的代码。
在foreach下拉列表中,选中一个字段进行查找(字段对应多个值)。
****** 在foreach下拉列表中,选中一个字段进行查找(字段对应多个值)。找到后怎样用foreach遍历出来??****** 一, 根据 传入的cellphone值在数据库中的进行查找: public List<Customer> selectBycell(String cellphone) { if(cellphone==null) throw new IllegalArgumentException(); Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; List<Customer> cs= new ArrayList<Customer>(); try{ conn=JdbcUtil.getConnection(); stmt = conn.prepareStatement("select id,name,gender,birthday,cellphone,email,hobby,type,description from customer where cellphone=?"); stmt.setString(1,cellphone); rs = stmt.executeQuery(); while(rs.next()){ Customer c = new Customer(); c.setId(rs.getString("id")); c.setName(rs.getString("name")); c.setGender(rs.getString("gender")); c.setBirthday(rs.getDate("birthday")); c.setCellphone(rs.getString("cellphone")); c.setEmail(rs.getString("email")); c.setHobby(rs.getString("hobby")); c.setType(rs.getString("type")); c.setDescription(rs.getString("description")); cs.add(c); } return cs; }catch(Exception e){ throw new DaoException(e); }finally{ JdbcUtil.release(rs, stmt, conn); } } } 二、servlet中的的方法 private void selectcell(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String selecbyell =request.getParameter("cellphone");      cs.selectByCell(selecbyell); request.setAttribute("selecbyell", selecbyell); request.getRequestDispatcher("/selectcustomer.jsp").forward(request, response); } 三、在foreach中动态获取的下拉列表中,选中一个字段进行查找,这个字段可以对应多个值 <form method="post" action="${pageContext.request.contextPath}/servlet/SelectBycell?operation=selectcell"> <select name="cellphone" id="cell" align="center"> <option value="">==按电话查询==</option> <c:forEach items="${cellphone}" var="cell" varStatus="vs"> <option value="${cell}"><span align="center">${cell}</span></option> </c:forEach> </select> <input type="image" id="submit" src="<c:url value='/images/select1.png'/>" class="loginBtn"/> </form>
jstl在session中取出的值是空的?Why?
servlet代码: List success = xcwxService.verificationUser(user_name); System.out.println(success); req.setAttribute("success", success); req.getRequestDispatcher("/jsp/index1.jsp").forward(req, resp); 调试打印出结果是: [{XC_USER_JF=600, XC_USER_NAME=admin, XC_USER_TIME=2015-01-25 00:00:00.0, XC_USER_VIP=1, XC_USER_PASSWORD=admin, XC_USER_ID=10000, XC_USER_SUM=6,}] jsp前台应该怎样取xc_user_name,xc_user_jf,_xc_user_sum中的值 <c:forEach var="success" items="${success}"> ${success.xc_user_name} ${success.xc_user_jf} ${success.xc_user_sum} </c:forEach> 取出来的值都是空的,为什么,是哪里错了?
ssm中Controller跳转到jsp中,不能显示参数值问题
这是spring的配置: ``` <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀(如果最后一个还是表示文件夹,则最后的斜杠不要漏了) 使用JSP--> <!-- 默认的视图解析器 在上边的解析错误时使用 (默认使用html)- --> <bean id="defaultViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!--设置JSP文件的目录位置--> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean> ``` 以下是我的jsp代码: ``` <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>ssm ${test}</title> </head> <body> <table width="100%" border=1> <tr> <td>商品名称</td> <td>商品价格</td> <td>商品描述</td> </tr> <c:forEach var="item" items="${itemList}"> <tr> <td>${item.name}</td> <td>${item.price}</td> <td>${item.detail}</td> </tr> </c:forEach> </table> </body> </html> ``` controller代码: ``` @RequestMapping("/findAllItem") public ModelAndView showItem(HttpSession session){ List<Item> itemList=itemService.findAllItem(); for(int i=0;i<itemList.size();i++){ Item item=itemList.get(i); System.out.println("Item:[ id= "+item.getId()+" | name= "+item.getName()+" | price= "+item.getPrice()+" | detail= "+item.getDetail()+" ]"); } session.setAttribute("aa","success"); //创建ModelAndView的对象 ModelAndView mv=new ModelAndView(); mv.setViewName("index"); mv.addObject("test","测试"); mv.addObject("itemList",itemList); return mv; } ``` 项目运行后可以正常跳转到对应的jsp,但是页面没有值,如图 ![图片说明](https://img-ask.csdn.net/upload/201710/12/1507821054_327718.png) 请问,这是什么原因????
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
【JSON解析】浅谈JSONObject的使用
简介 在程序开发过程中,在参数传递,函数返回值等方面,越来越多的使用JSON。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,同时也易于机器解析和生成、易于理解、阅读和撰写,而且Json采用完全独立于语言的文本格式,这使得Json成为理想的数据交换语言。 JSON建构于两种结构: “名称/值”对的集合(A Collection of name/va...
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我...
2019年还剩1天,我从外包公司离职了
这日子过的可真快啊,2019年还剩1天,外包公司干了不到3个月,我离职了
我一个37岁的程序员朋友
周末了,人一旦没有点事情干,心里就瞎想,而且跟几个老男人坐在一起,更容易瞎想,我自己现在也是 30 岁了,也是无时无刻在担心自己的职业生涯,担心丢掉工作没有收入,担心身体机能下降,担心突...
计算机网络的核心概念
这是《计算机网络》系列文章的第二篇文章 我们第一篇文章讲述了计算机网络的基本概念,互联网的基本名词,什么是协议以及几种接入网以及网络传输的物理媒体,那么本篇文章我们来探讨一下网络核心、交换网络、时延、丢包、吞吐量以及计算机网络的协议层次和网络攻击。 网络核心 网络的核心是由因特网端系统和链路构成的网状网络,下面这幅图正确的表达了这一点 那么在不同的 ISP 和本地以及家庭网络是如何交换信息的呢?...
python自动下载图片
近日闲来无事,总有一种无形的力量萦绕在朕身边,让朕精神涣散,昏昏欲睡。 可是,像朕这么有职业操守的社畜怎么能在上班期间睡瞌睡呢,我不禁陷入了沉思。。。。 突然旁边的IOS同事问:‘嘿,兄弟,我发现一个网站的图片很有意思啊,能不能帮我保存下来提升我的开发灵感?’ 作为一个坚强的社畜怎么能说自己不行呢,当时朕就不假思索的答应:‘oh, It’s simple. Wait for me for a ...
一名大专同学的四个问题
【前言】   收到一封来信,赶上各种事情拖了几日,利用今天要放下工作的时机,做个回复。   2020年到了,就以这一封信,作为开年标志吧。 【正文】   您好,我是一名现在有很多困惑的大二学生。有一些问题想要向您请教。   先说一下我的基本情况,高考失利,不想复读,来到广州一所大专读计算机应用技术专业。学校是偏艺术类的,计算机专业没有实验室更不用说工作室了。而且学校的学风也不好。但我很想在计算机领...
复习一周,京东+百度一面,不小心都拿了Offer
京东和百度一面都问了啥,面试官百般刁难,可惜我全会。
Java 14 都快来了,为什么还有这么多人固守Java 8?
从Java 9开始,Java版本的发布就让人眼花缭乱了。每隔6个月,都会冒出一个新版本出来,Java 10 , Java 11, Java 12, Java 13, 到2020年3月份,...
达摩院十大科技趋势发布:2020 非同小可!
【CSDN编者按】1月2日,阿里巴巴发布《达摩院2020十大科技趋势》,十大科技趋势分别是:人工智能从感知智能向认知智能演进;计算存储一体化突破AI算力瓶颈;工业互联网的超融合;机器间大规模协作成为可能;模块化降低芯片设计门槛;规模化生产级区块链应用将走入大众;量子计算进入攻坚期;新材料推动半导体器件革新;保护数据隐私的AI技术将加速落地;云成为IT技术创新的中心 。 新的画卷,正在徐徐展开。...
轻松搭建基于 SpringBoot + Vue 的 Web 商城应用
首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute): 函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。Fun: Fun 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API ...
讲真,这两个IDE插件,可以让你写出质量杠杠的代码
周末躺在床上看《拯救大兵瑞恩》 周末在闲逛的时候,发现了两个优秀的 IDE 插件,据说可以提高代码的质量,我就安装了一下,试了试以后发现,确实很不错,就推荐给大家。 01、Alibaba Java 代码规范插件 《阿里巴巴 Java 开发手册》,相信大家都不会感到陌生,其 IDEA 插件的下载次数据说达到了 80 万次,我今天又贡献了一次。嘿嘿。 该项目的插件地址: https://github....
Python+OpenCV实时图像处理
目录 1、导入库文件 2、设计GUI 3、调用摄像头 4、实时图像处理 4.1、阈值二值化 4.2、边缘检测 4.3、轮廓检测 4.4、高斯滤波 4.5、色彩转换 4.6、调节对比度 5、退出系统 初学OpenCV图像处理的小伙伴肯定对什么高斯函数、滤波处理、阈值二值化等特性非常头疼,这里给各位分享一个小项目,可通过摄像头实时动态查看各类图像处理的特点,也可对各位调参、测试...
2020年一线城市程序员工资大调查
人才需求 一线城市共发布岗位38115个,招聘120827人。 其中 beijing 22805 guangzhou 25081 shanghai 39614 shenzhen 33327 工资分布 2020年中国一线城市程序员的平均工资为16285元,工资中位数为14583元,其中95%的人的工资位于5000到20000元之间。 和往年数据比较: yea...
为什么猝死的都是程序员,基本上不见产品经理猝死呢?
相信大家时不时听到程序员猝死的消息,但是基本上听不到产品经理猝死的消息,这是为什么呢? 我们先百度搜一下:程序员猝死,出现将近700多万条搜索结果: 搜索一下:产品经理猝死,只有400万条的搜索结果,从搜索结果数量上来看,程序员猝死的搜索结果就比产品经理猝死的搜索结果高了一倍,而且从下图可以看到,首页里面的五条搜索结果,其实只有两条才是符合条件。 所以程序员猝死的概率真的比产品经理大,并不是错...
害怕面试被问HashMap?这一篇就搞定了!
声明:本文以jdk1.8为主! 搞定HashMap 作为一个Java从业者,面试的时候肯定会被问到过HashMap,因为对于HashMap来说,可以说是Java集合中的精髓了,如果你觉得自己对它掌握的还不够好,我想今天这篇文章会非常适合你,至少,看了今天这篇文章,以后不怕面试被问HashMap了 其实在我学习HashMap的过程中,我个人觉得HashMap还是挺复杂的,如果真的想把它搞得明明白...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
程序员如何通过造轮子走向人生巅峰?
前言:你所做的事情,也许暂时看不到成果。但不要灰心,你不是没有成长,而是在扎根。 程序员圈经常流行的一句话:“不要重复造轮子”。在计算机领域,我们将封装好的组件、库,叫做轮子。因为它可以拿来直接用,直接塞进我们的项目中,就能实现对应的功能。 有些同学会问,人家都已经做好了,你再来重新弄一遍,有什么意义?这不是在浪费时间吗。 殊不知,造轮子是一种学习方式,能快速进步,造得好,是自己超强能力的表...
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
阿里面试,面试官没想到一个ArrayList,我都能跟他扯半小时
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
良心推荐,我珍藏的一些Chrome插件
上次搬家的时候,发了一个朋友圈,附带的照片中不小心暴露了自己的 Chrome 浏览器插件之多,于是就有小伙伴评论说分享一下我觉得还不错的浏览器插件。 我下面就把我日常工作和学习中经常用到的一些 Chrome 浏览器插件分享给大家,随便一个都能提高你的“生活品质”和工作效率。 Markdown Here Markdown Here 可以让你更愉快的写邮件,由于支持 Markdown 直接转电子邮...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
Idea 中最常用的10款插件(提高开发效率),一定要学会使用!
学习使用一些插件,可以提高开发效率。对于我们开发人员很有帮助。这篇博客介绍了开发中使用的插件。
立即提问