用servlet打出数据库在jsp页面列表展示,但是jsp页面始终不出现数据库中的值 2C

这是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 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.*"%>

ID buyer name sum
${order.id } ${order.buyername } ${order.sum }

6个回答

排除法。先在jsp页面使用<%=request.getAttribute("orderlist")%> 看有没有结果(jsp页面会展示很多个对象值带地址的那种)。。如果页面显示有的话就说明后台取到值并成功传到前台jsp页面啦。就能说明是jsp取值的问题。没问题的话就先用C标签取一个orderlist的值。看C标签有没有起效。如果还没问题就是循环的问题啦。

qq_31045649
qq_31045649 回复qq_31045649: 是servlet的问题导致没有取值成功吗?怎么改servlet啊~~·
接近 5 年之前 回复
qq_31045649
qq_31045649 <%=request.getAttribute("orderlist")%>用这个显示的是null该怎么办啊?
接近 5 年之前 回复

jsp那一段的代码是:

 <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>

  <c:forEach items="${orderlist}" var="ordert">

这样修改一下试试。

qq_31045649
qq_31045649 回复dcxy0: 我都改了,可还是不行
接近 5 年之前 回复
dcxy0
Q544471255 <c:forEach items="${orderlist}" var="order"> 你的代码var多了一个t
接近 5 年之前 回复

自己先通过Debug看看具体错误在哪里,var=“order” 不是ordert,细节多注意。

ordert

不是因为这个吧..........


  <td>${order.id }</td>
  <td>${order.buyername }</td>
  <td>${order.sum }</td>

</tr>

/c:forEach
改成

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
jsp页面调用Servlet后进入Servlet页面空白不跳转了

各位大大,小弟正在用java做毕业设计,遇到一个问题,就是想实现获取页面的学生姓名sname和学号sno,然后到数据库中执行查询,将这个学生的成绩从数据库中输出到新的页面。可是,问题来了:在查询页面点击提交按钮后,页面跳转到ChengjiServlet2页面,web浏览器就一片空白,在ChengjiServlet2页面的sendRedirect也没了作用。。。希望各位大大们看在我操心做毕业设计的份儿上帮帮我吧,说白了就是一个查询输出,望大大们指点!跪谢!! //查询页面,jsp。放在一个文件夹里。路径没出错 不支持直接使用html标签,所以我改了一下 《body》 《form id="form1" name="chengjiFrom" method="post" action="../ChengjiServlet2"》《h1 align="center"》成绩查询页面《/h1》 《p>姓名: 《input name="sname" type="text" id="sname" /> 《/p> 《p>学号: 《input name="sno" type="text" id="sno" /> 《/p> 《p> 《input type="submit" name="Submit" value="查询成绩" /> 《/p> 《/form> 《/body> >//这是我编写的ChengjiServlet2类 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List chengji = new ArrayList(); //获取chengjichaxun.jsp页面的各个控件属性 String Sname = request.getParameter("sname"); String Sno = request.getParameter("sno"); String SelectScore = request.getParameter("select"); ChengjiSQLUtil chengjiSql = new ChengjiSQLUtil(); Connection conn =null; Statement stmt=null; ResultSet rs = null; conn = chengjiSql.getConn_Bendi(); try { if(SelectScore.equals("score_1")) { //创建Statement实例,并执行sql语句 String sql = "SELECT * FROM 'renwu'.'score_da1' where sno='"+Sno+"' and sname='"+Sname+"'"; stmt = conn.createStatement(); rs = stmt.executeQuery(sql); while(rs.next()) { String sno = rs.getString("sno"); String sname = rs.getString("sname"); String ke1_a = rs.getString("ke1_a"); String ke1_b = rs.getString("ke1_b"); String ke1_c = rs.getString("ke1_c"); String ke1_d = rs.getString("ke1_d"); String ke1_e = rs.getString("ke1_e"); String ke1_f = rs.getString("ke1_f"); chengji.add(sno); chengji.add(sname); chengji.add(ke1_a); chengji.add(ke1_b); chengji.add(ke1_c); chengji.add(ke1_d); chengji.add(ke1_e); chengji.add(ke1_f); } HttpSession session = request.getSession(); session.setAttribute("score", chengji); response.sendRedirect("chaxun_chengji/chengji_jieguo.jsp"); } else if(SelectScore.equals("score_2")) { String sql = "SELECT * FROM 'renwu'.'score_da2' where sno='"+Sno+"' and sname='"+Sname+"'"; stmt = conn.createStatement(); rs = stmt.executeQuery(sql); while(rs.next()) { String sno = rs.getString("sno"); String sname = rs.getString("sname"); String ke2_a = rs.getString("ke2_a"); String ke2_b = rs.getString("ke2_b"); String ke2_c = rs.getString("ke2_c"); String ke2_d = rs.getString("ke2_d"); String ke2_e = rs.getString("ke2_e"); String ke2_f = rs.getString("ke2_f"); chengji.add(sno); chengji.add(sname); chengji.add(ke2_a); chengji.add(ke2_b); chengji.add(ke2_c); chengji.add(ke2_d); chengji.add(ke2_e); chengji.add(ke2_f); } HttpSession session = request.getSession(); session.setAttribute("score", chengji); response.sendRedirect("chaxun_chengji/chengji_jieguo.jsp"); } else if(SelectScore.equals("score_3")) { String sql = "SELECT * FROM 'renwu'.'score_da3' where sno='"+Sno+"' and sname='"+Sname+"'"; stmt = conn.createStatement(); rs = stmt.executeQuery(sql); while(rs.next()) { String sno = rs.getString("sno"); String sname = rs.getString("sname"); String ke3_a = rs.getString("ke3_a"); String ke3_b = rs.getString("ke3_b"); String ke3_c = rs.getString("ke3_c"); String ke3_d = rs.getString("ke3_d"); String ke3_e = rs.getString("ke3_e"); String ke3_f = rs.getString("ke3_f"); chengji.add(sno); chengji.add(sname); chengji.add(ke3_a); chengji.add(ke3_b); chengji.add(ke3_c); chengji.add(ke3_d); chengji.add(ke3_e); chengji.add(ke3_f); } HttpSession session = request.getSession(); session.setAttribute("score", chengji); response.sendRedirect("chaxun_chengji/chengji_jieguo.jsp"); } else if(SelectScore.equals("score_4")) { String sql = "SELECT * FROM 'renwu'.'score_da4' where sno='"+Sno+"' and sname='"+Sname+"'"; stmt = conn.createStatement(); rs = stmt.executeQuery(sql); while(rs.next()) { String sno = rs.getString("sno"); String sname = rs.getString("sname"); String ke4_a = rs.getString("ke4_a"); String ke4_b = rs.getString("ke4_b"); String ke4_c = rs.getString("ke4_c"); String ke4_d = rs.getString("ke4_d"); String ke4_e = rs.getString("ke4_e"); String ke4_f = rs.getString("ke4_f"); chengji.add(sno); chengji.add(sname); chengji.add(ke4_a); chengji.add(ke4_b); chengji.add(ke4_c); chengji.add(ke4_d); chengji.add(ke4_e); chengji.add(ke4_f); } HttpSession session = request.getSession(); session.setAttribute("score", chengji); response.sendRedirect("chaxun_chengji/chengji_jieguo.jsp"); } }catch(Exception e) { e.printStackTrace(); }finally { chengjiSql.releaseResources(conn, stmt, rs); } } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } > //这块是web.xml的相关信息 <servlet> <servlet-name>chengjiServlet2</servlet-name> <servlet-class>org.afan.course.servlet.ChengjiServlet2</servlet-class> </servlet> <servlet-mapping> <servlet-name>chengjiServlet2</servlet-name> <url-pattern>/chengjiServlet2</url-pattern> </servlet-mapping> //这块是查询成功后要跳转的页面代码,目前还没能走到这个页面。我用list将数据输出,因为不会其他的将java类查询结果输出到jsp页面的方法。。 《body><P>成绩情况</P> 《table> <% List list = (List)session.getAttribute("score"); for(int i=0;i<list.size();i++) { out.print("成绩:" + list.get(i) + "<br/>"); } %> 《/table> 《/body>

JSP如何从数据库获取对象信息并放入session进行调用?

之前提过一个问题,大家给出了解决方法,但都说得比较笼统,我是个初学者,没法稍微点一点,说个思路就能理解,所以还是想求个简单的例子来学习一下。 我用的数据库是MySQL,如题,我做了一个简单的注册登录系统,注册帐号的时候有很多信息,假设除了帐号和密码,还有性别sex,年龄age,电话tel等信息,但是登录只需要验证帐号和密码就可以了,登录之后我想调用当前登录用户的信息并在其他页面的table中打印出来,大家给出的方法都是验证帐号后从数据库中获取用户对象并将其他信息存入session,只有这样的一个解决思路,然而作为一个刚接触这方面不久的人,我还是想求一段简单的示例代码来学习一下,非常感谢!

struts2 我在jsp页面中获取到了list集合中的对象但是就是不显示值

我用struts2在jsp中遍历了一个集合,集合中也有数据就是没法显示,如果用el表达式取对象 可以打印出来,但是取对象的属性就报错 先上代码 // action层 @Controller public class NreportAction extends BaseAction { /** * 内部审计S相关的封装 */ @Resource private NreportService nreportService; // 内审service private List<Nreport> nreportList; private Nreport nreport; public NreportAction(){ System.out.println("进来了"); } // 内审填报页面 public String addUI(){ System.out.println("时空裂缝"); try { // System.out.println("1.先查出上一年没有完成的任务"); // System.out.println("2.查询出纪检监察室下发状态 , 如果下发了,就显示一条记录,让下级部门填写"); nreportList = nreportService.findNotDoPro(); if(nreportList!=null && nreportList.size()>0){ System.out.println("上一年未完成的项目有"+nreportList.size()+"个"); } } catch (Exception e) { System.out.println(e.getMessage()); } return "reportUI"; } DAO层 public class NreportDaoImpl extends BaseDaoImpl<Nreport> implements NreportDao { @Override public List<Nreport> findNotDoPro() { Calendar c=new GregorianCalendar();//新建日期对象 int year=c.get(Calendar.YEAR);//获取年份 int month=c.get(Calendar.MONTH);/ // 获取当前年份 int year=c.get(Calendar.YEAR); // sql语句 select proid from record where state=1 and (year like '%2015%') // 从【记录表】查询 出上一年没有完成的记录,然后根据记录从【内部表】查出项目的List List list = getSession().createSQLQuery( "select proid from record where state=0 and deptType = '内部审计' and (year like \'%" + String.valueOf(year-1) + "%\')").list(); // 遍历List然后根据这个id来去查找林外一张表 String sql = "select * from nreport where nid in("; for(int i=0;i<list.size();i++){ // sql = "where id in(1,2,3)"; // 如果当前获取的这个id不是最后一个id,那么加上‘,’ if(list.get(i)!= list.get(list.size()-1)){ sql+=list.get(i)+","; }else{ sql+=list.get(i)+")"; } } System.out.println(sql+"看看sql长啥样"); // 从【内部表】查出未完成项目的List List<Nreport> list2= getSession().createSQLQuery(sql).list(); return list2; } } jsp <form action="" method="post" enctype="multipart/form-data"> <table width="100%" border="0"> <tr class="t_tit"> <td width="40" align="center">序号</td> <td width="80" align="center">项目名称</td> <td width="80" align="center">审计类型</td> <td width="40" align="center">送审金额</td> <td width="40" align="center">预计审计费</td> <td width="160" align="center">预计审计时间</td> <td width="140" align="center">经费来源</td> <td width="100" align="center">资金性质</td> <td width="60" align="center">状态</td> <td width="60" align="center">备注</td> <td width="60" align="center">删除</td> </tr> <!-- 如果有上一年的已经启动但是没有完成的计划也显示在这里 --> <s:iterator value="nreportList" status="st"> ${nreportList[0] } <s:if test="nreportList!=null"> <tr <s:if test="#st.odd">bgcolor="f8f8f8"</s:if> > <td align="center"><s:property value="nid"/></td> <td align="center"><s:property value="proname"/></td> <td align="center"><s:property value="audittype"/></td> <td align="center"><s:property value="ssmoney"/></td> <td align="center"><s:property value="expeauditmoney"/></td> <td align="center"><s:property value="expeaudittime"/></td> <td align="center"><s:property value="moneyfrom"/></td> <td align="center"><s:property value="moneyfunds"/></td> <td align="center"><s:property value="state"/></td> <td align="center"><s:property value="memo"/></td> </tr></s:if> <s:else>没数据?</s:else> </s:iterator> 如果我 我jsp中写成上面这样 ${nreportList[0] } 就会输出toString格式的对象 [Ljava.lang.Object;@20d77d7d 如果写成 ${nreportList[0].getNid }就报错 错误信息: 十一月 17, 2016 5:09:16 下午 org.apache.catalina.core.ApplicationDispatcher invoke 严重: Servlet.service() for servlet jsp threw exception java.lang.NumberFormatException: For input string: "getNid" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:492) at java.lang.Integer.parseInt(Integer.java:527) at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:161) at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:45) ... ... 页面显示出来表格了,是迭代出来的就是没有数据,都是空的格子 ![图片说明](https://img-ask.csdn.net/upload/201611/17/1479374227_31350.jpg) 求大神指导怎么才能迭代出来数据??? 没有C币 , 下次有了一定加倍赏。。。

controller 测试通过数据库有数据可以查到,为什么网页端不显示呢???

目标是在网页端能显示出一组数据库中查找出的json格式的数据。 但是 通过junit分层测试后在数据层,业务处理层,显示层都能够顺利的通过显示, 为什么连接完tomcat服务器后在网页端就不显示了呢,问题是也不报错并且一直处于加载状态但又没数据? 单独测试tomcat 返回json字符串没有问题, @Controller @RequestMapping("/td") public class ItemController { @Resource private ItemService itemService; @RequestMapping("/item/{itemId}") @ResponseBody public TbItem getItemById(@PathVariable Long itemId) { TbItem tbItem = itemService.getItemById(itemId); return tbItem; } @RequestMapping("/aa") @ResponseBody public String getString(){ return "hello"; } @RequestMapping("/bb") @ResponseBody public TbItem getItemById(){ TbItem tbItem = itemService.getItemById(536563); return tbItem; } } /aa 可以测试通过 /bb和/item/536563就是不行

页面如何获取表单提交后返回的数据

$("#loginForm").submit(function(){ $("#msg").text(""); var bool = true; $(".input").each(function() { var inputName = $(this).attr("name"); if(!invokeValidateFunction(inputName)) { bool = false; } }); return bool; }); 用户名和密码数据正确后 会调用后台的servlet servlet会返回一个bol值 我前台怎么获取这个值呢?

Servlet不能读取表单数据

如下代码: ``` public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); String testdbName = request.getParameter("testdbName"); String introduce = request.getParameter("introduce"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.println(testdbName); out.println(introduce); out.println(" </BODY>"); out.println("</HTML>"); ``` 本意是要读取jsp页面表单内的数据并写进数据库,但是发现Servlet没有把数据读出来,为此专门写了后面的out.println打印,页面完全空白。 各位大侠帮忙看下到底是哪儿出问题了?谢谢!

java web项目本地运行正常发布到阿里云服务器上之后出错

``` <%@ page language="java" import="java.util.*,db.DBLink,java.sql.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% DBLink db=new DBLink("my_test_db"); Connection con=db.getDefaultCon(); Statement sta=con.createStatement(); ResultSet rs=sta.executeQuery("select * from users"); if(rs.next()){ out.print(rs.getString(1)+" "+rs.getString(2)); } %> </body> </html> //数据库连接 DBLink.java package db; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; public class DBLink { Connection con; Statement sta; ResultSet rs; PreparedStatement psta; ResultSetMetaData rsm; //119.23.240.242 private String user = null, pwd = null, dataBaseName = "my_test_db", id = "localhost", port = "3306"; public DBLink(String dataBaseName) { this.user = "root"; this.pwd = "abc"; this.dataBaseName = dataBaseName; try { Class.forName("com.mysql.jdbc.Driver"); } catch (Exception e) { } } public Connection getDefaultCon() { String uri = "jdbc:mysql://localhost:3306/" + dataBaseName+"?useUnicode=true&characterEncoding=utf-8&useSSL=false"; setUser("root"); setPwd("lfy"); try { con = DriverManager.getConnection(uri, "root", "abc"); return con; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } } } ``` java web在本地可以正常运行 ![图片说明](https://img-ask.csdn.net/upload/201706/30/1498784601_196563.png) 但是发布到阿里云服务器上就不能运行 ![图片说明](https://img-ask.csdn.net/upload/201706/30/1498784682_119043.png) 错误信息: HTTP Status 500 - An exception occurred processing JSP page /index.jsp at line 27 type Exception report message An exception occurred processing JSP page /index.jsp at line 27 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 /index.jsp at line 27 24: <% 25: DBLink db=new DBLink("my_test_db"); 26: Connection con=db.getDefaultCon(); 27: Statement sta=con.createStatement(); 28: ResultSet rs=sta.executeQuery("select * from users"); 29: if(rs.next()){ 30: out.print(rs.getString(1)+" "+rs.getString(2)); Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:469) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause java.lang.NullPointerException org.apache.jsp.index_jsp._jspService(index_jsp.java:126) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) note The full stack trace of the root cause is available in the Apache Tomcat/8.0.18 logs.

Java在触发事务回滚之后为什么会再一次回到Servlet开始的地方重新走一次流程?

## 代码流程 1. 前台点击"提交订单"进入`BaseServlet.class` 2. `BaseServlet.class`分发至子类`OrderServlet.class`的`submitOrder()`方法 3. `submitOrder()`调用Service层的`submitOrder()`方法. 4. 关键是Service层`submitOrder()`中使用了事务回滚. 这里调用了`Dao`层两个方法: `fun01()`和`fun02()`, 其中`fun01`执行成功, `fun02()`执行时抛出异常. 5. catch到异常后, 执行回滚. 然后关闭连接. 然后, **异常诡异的是, 程序并没有在回滚、关闭连接后结束,而是再一次进入`BaseServlet`。** 再一次执行一次上述流程,而这一次,由于第一次已经将*线程绑定的连接*关闭了。所以自然出现异常:不能操作已经关闭的连接。 **我的疑惑是:为什么它走了两次这个流程?是因为我调用了个`dao`层的插入数据的方法吗?** 还是或事物回滚就是从头在执行要一遍流程呢? 这个异常, 导致回滚技术无法实现呀. ## 代码片段(图片) ![图片说明](https://img-ask.csdn.net/upload/201711/12/1510464901_837407.png) ## 代码片段源码 ### Servlet层 ``` public String submitOrder(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ... Debug.log("进入方法:submitOrder..."); // 打印信息 boolean flag = false; // 调用service层方法 flag = orderService.submitOrder( pids, checkeds, quantitys, user ); // 提交成功 --> order_info.jsp页面 失败 --> info.jsp if( flag ) { return goOrderInfoUI(req, resp); }else { req.setAttribute("error", "提交订单失败!"); return "/info.jsp"; } } ``` ### service层 ``` ... // 获得*线程绑定的连接* Connection conn = null; try { conn = C3P0Util.getConnection(); Debug.log("连接=="+conn); // 开启事务 // 由于插入要么都成功, 要么都失败, 所以需要用事务操作 Debug.log("进入try"); conn.setAutoCommit(false); Debug.log("开启事务"); // 调用dao插入数据库 // 插入订单 orderDao.insertOrder(order); Debug.log("order插入走完"); // 插入订单项 orderDao.insertOrderItmes( orderItems ); // 提交事务 conn.commit(); // 方法返回值为true Debug.log("事务已提交"); flag = true; }catch(Exception e) { Debug.log("进入外层catch"); // 回滚事务 try { conn.rollback(); Debug.log("事务已回滚"); } catch (SQLException e1) { // TODO Auto-generated catch block Debug.log("进入内存catch"); e1.printStackTrace(); } }finally { // 关闭连接 try { Debug.log("关闭连接"); conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Debug.log("service走完"); return flag; ... ``` 注:*`Debug.log()`是自定义方法用来打印信息.*

JS 从数据库取值表单自动填充

我想把数据库取出的值在页面加载后填充到表单,但是为什么没有填充呢?[code="java"]<body onload="initialise()" > <center> <h1 id="title">编辑题目</h1> </center> <% Questions q=null; if(request.getAttribute("q")!=null){ q= (Questions)request.getAttribute("q"); //获得QueryQueByIdservlet存储在request里的数据 //System.out.println(q.getQ_head()+"******q.getQ_head()"); }else{ q=null; } String url=""; if(request.getAttribute("isUpdate")!=null){ url="servlet/UpdateQueServlet"; } else{ url="servlet/AddQueServlet"; } int sID=0; if(request.getParameter("s_id")!=null){ sID=Integer.parseInt(request.getParameter("s_id")); } else{ sID=0; } int q_id=0; if(request.getParameter("q_id")!=null){ q_id=Integer.parseInt(request.getParameter("q_id")); }else{q_id=0;} %> <form action="<%=url %>" method="post" name="form" > url<input type="text" value="<%=url %>" readonly="readonly"><br> 问卷ID<input type="text" name="sID" value="<%=sID %>" readonly="readonly"><br> 题目ID<input type="text" name="q_id" value="<%=q_id %>" readonly="readonly"><br> 题目类型:<select name="question_type" onchange="change(this.value)"> <% List<QuestionType> list = new ArrayList<QuestionType>(); QuestionTypeDao dao = new QuestionTypeDaoImpl(); list = dao.findAllQueType();// 调用实现类的查询全部方法 for (int i = 0; i < list.size(); i++) { QuestionType qt = list.get(i); %> <option value="<%=qt.getQt_id()%>" <% if(q!=null){ if (qt.getQt_id() == q.getQ_type().getQt_id()) {%>selected <%}}%>> <%=qt.getQt_des()%></option> <% } %> </select><br> 这里没你想要的类型?请填写新的类型。<br> <input type="text" name="newType"><br> <input type="submit" value="添加" name="addNewType">&nbsp;&nbsp; <input type="reset" value="重置" name="reset"><br> 题目名称: <input type="text" id="q_head" name="q_head"/><br> 题目描述及备注:<br> <textarea cols="100" rows="4" id="q_remarks" name="q_remarks"></textarea><br> 题目个数: <input type="text" id="q_number" name="q_number" /><br> <span id="content"> 选项内容(一行一个选项):</span><br> <textarea cols="100" rows="5" id="q_body" name="q_body"></textarea><br> <input type="submit" value="提交" name="submit">&nbsp;&nbsp; <input type="reset" value="重置" name="reset"> </form> <script type="text/javascript"> function initialise(){ <%if(q!=null){ System.out.println(q.getQ_head()+"***JS******q.getQ_head()"); %> document.getElementById("q_head").value="<%=q.getQ_head()%>"; document.getElementById("q_remarks").value="<%=q.getQ_remarks()%>"; document.getElementById("q_number").value="<%=q.getQ_number()%>"; document.getElementById("q_body").value="<%=q.getQ_body()%>"; if(<%=q.getQ_type().getQt_des()%>=="单选+输入"||<%=q.getQ_type().getQt_des()%>=="多选+输入"){ document.getElementById("content").innerHTML ="选项内容(一行一个选项,最后一行为输入框的提示语):"; } else{ document.getElementById("content").innerHTML ="选项内容(一行一个选项):"; } <%}%> }; function change(type){ if(type==3||type==4){ document.getElementById("content").innerHTML ="选项内容(一行一个选项,最后一行为输入框的提示语):"; } else{ document.getElementById("content").innerHTML ="选项内容(一行一个选项):"; } } </script> </body>[/code]

java查询数据库中的数据会输出,输出的不是我的数据????

# ```数据封装在build,builds中 可是输出的不是数据库中的数据而是 ![图片说明](https://img-ask.csdn.net/upload/202004/02/1585822586_24417.jpg) # DormBuildDaoImpl.java package zj.shizhan.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import zj.shizhan.bean.DormBuild; import zj.shizhan.util.ConnectionFactory; public class DormBuildDaoImpl implements DormBuildDao { @Override public DormBuild findByName(String dormBuildName) { //获取连接(数据库地址 用户名 密码) Connection connection = ConnectionFactory.getConnection(); try { String sql = "select * from dormbuild where dormBuildName = ? "; //执行SQL语句 获取集装箱 或者说是 车 PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, dormBuildName); ResultSet rs = preparedStatement .executeQuery(); //因为查询出来的信息包括表头信息,所以指针下移一行,看是否有查询出的数据 //如有数据,就进入循环体封装该行数据 while (rs.next()) { DormBuild build = new DormBuild(); build.setDormBuildId(rs.getInt("dormBuildId")); build.setDormBuildName(rs.getString("dormBuildName")); build.setDetail(rs.getString("detail")); return build; } } catch (SQLException e) { e.printStackTrace(); } return null; } @Override public void save(DormBuild build) { //获取连接(数据库地址 用户名 密码) Connection connection = ConnectionFactory.getConnection(); try { String sql = "INSERT INTO dormbuild(dormBuildName,detail)VALUES(?,?)"; //执行SQL语句 获取集装箱 或者说是 车 PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, build.getDormBuildName()); preparedStatement.setString(2, build.getDetail()); preparedStatement .executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } } @Override public List<DormBuild> find() { //获取连接(数据库地址 用户名 密码) Connection connection = ConnectionFactory.getConnection(); try { String sql = "select * from dormbuild "; //执行SQL语句 获取集装箱 或者说是 车 PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet rs = preparedStatement .executeQuery(); //因为查询出来的信息包括表头信息,所以指针下移一行,看是否有查询出的数据 //如有数据,就进入循环体封装该行数据 List<DormBuild> builds = new ArrayList<DormBuild>(); while (rs.next()) { DormBuild build = new DormBuild(); build.setDormBuildId(rs.getInt("dormBuildId")); build.setDormBuildName(rs.getString("dormBuildName")); build.setDetail(rs.getString("detail")); builds.add(build); } return builds; } catch (SQLException e) { e.printStackTrace(); } return null; } @Override public DormBuild findById(Integer dormBuildId) { //获取连接(数据库地址 用户名 密码) Connection connection = ConnectionFactory.getConnection(); try { String sql = "select * from dormbuild where dormBuildId = ? "; //执行SQL语句 获取集装箱 或者说是 车 PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, dormBuildId); ResultSet rs = preparedStatement .executeQuery(); //因为查询出来的信息包括表头信息,所以指针下移一行,看是否有查询出的数据 //如有数据,就进入循环体封装该行数据 while (rs.next()) { DormBuild build = new DormBuild(); build.setDormBuildId(rs.getInt("dormBuildId")); build.setDormBuildName(rs.getString("dormBuildName")); build.setDetail(rs.getString("detail")); return build; } } catch (SQLException e) { e.printStackTrace(); } return null; } @Override public void update(DormBuild build ) { //获取连接(数据库地址 用户名 密码) Connection connection = ConnectionFactory.getConnection(); try { String sql = "UPDATE dormbuild SET dormBuildName = ?,detail = ? WHERE dormBuildId = ?"; //执行SQL语句 获取集装箱 或者说是 车 PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, build.getDormBuildName()); preparedStatement.setString(2, build.getDetail()); preparedStatement.setInt(3, build.getDormBuildId()); //执行更新 preparedStatement .executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } } } ``` # DormBuildServlet.java ``` package zj.shizhan.servlet; import java.io.IOException; import java.util.ArrayList; 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 zj.shizhan.bean.DormBuild; import zj.shizhan.service.DormBuildService; import zj.shizhan.service.DormBuildServiceImpl; /** * Servlet implementation class DormBuildServlet */ @WebServlet("/dormBuild.action") public class DormBuildServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public DormBuildServlet() { super(); } /** * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response) */ protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); String action = request.getParameter("action"); //通过request.getParameter("id")方式获取的值都是String类型的 String dormBuildId = request.getParameter("dormBuildId"); System.out.println("action:"+action); DormBuildService dormBuildService = new DormBuildServiceImpl(); if(action !=null & action.equals("list")) { List<DormBuild> builds = new ArrayList<DormBuild>(); if( dormBuildId== null || dormBuildId.equals("")) { //查询所有宿舍楼信息,跳转到宿舍楼列表页 builds = dormBuildService.find(); }else if(dormBuildId != null && !dormBuildId.equals("")) { //点击查询按钮搜索某一栋宿舍楼的信息 DormBuild build = dormBuildService.findById(Integer.parseInt(dormBuildId)); builds.add(build); System.out.println("build:"+build); } //查询所有宿舍楼。在select中遍历 List<DormBuild> buildSelects = dormBuildService.find(); request.setAttribute("buildSelects", buildSelects); request.setAttribute("dormBuildId", dormBuildId); System.out.println("builds:"+builds); request.setAttribute("builds", builds); request.getRequestDispatcher("BuildList.jsp").forward(request, response); }else if (action !=null & "preAdd".equals(action)) { //表示跳转到宿舍楼添加页面 request.getRequestDispatcher("AddOrAlterBuild.jsp").forward(request, response); }else if (action !=null & "save".equals(action)) { //保存数据 String n = request.getParameter("dormBuildName"); String dormBuildName = new String(n.getBytes("ISO-8859-1"), "utf-8"); String m = request.getParameter("detail"); String detail = new String(m.getBytes("ISO-8859-1"), "utf-8"); System.out.println("dormBuildName:"+dormBuildName+"detail:"+detail+"id:"+dormBuildId); //判断宿舍楼名字是否已存在 DormBuild dormBuild = dormBuildService.findByName(dormBuildName); System.out.println("dormBuildName:"+dormBuildName); System.out.println("id2:"+dormBuildId); if(dormBuildId !=null && !"".equals(dormBuildId)) { System.out.println("id3:"+dormBuildId); //修改 if (dormBuild != null && !dormBuild.getDormBuildId().equals(Integer.parseInt(dormBuildId))) { request.setAttribute("error", "该宿舍楼已存在"); //格局宿舍楼id,查询宿舍楼 DormBuild build = dormBuildService.findById(Integer.parseInt(dormBuildId)); //保存宿舍楼信息,到前端页面展示 request.setAttribute("build", build); request.getRequestDispatcher("AddOrAlterBuild.jsp").forward(request, response); }else { dormBuild = dormBuildService.findById(Integer.parseInt(dormBuildId)); dormBuild.setDormBuildName(dormBuildName); dormBuild.setDetail(detail); dormBuildService.update(dormBuild); //更新完成后,跳转到宿舍楼管理列表页,查询所有宿舍楼 List<DormBuild> builds = dormBuildService.find(); request.setAttribute("builds", builds); request.getRequestDispatcher("BuildList.jsp").forward(request, response); } }else { //保存 System.out.println("id4:"+dormBuildId); if (dormBuild != null) { //该宿舍楼已存在 request.setAttribute("error", "该宿舍楼已存在"); request.getRequestDispatcher("AddOrAlterBuild.jsp").forward(request, response); }else { //该宿舍楼已不存在 DormBuild build = new DormBuild(); build.setDormBuildName(dormBuildName); build.setDetail(detail); dormBuildService.save(build); List<DormBuild> builds = dormBuildService.find(); request.setAttribute("builds", builds); request.getRequestDispatcher("BuildList.jsp").forward(request, response); } } }else if (action !=null & "preUpdate".equals(action)) { //格局宿舍楼id,查询宿舍楼 DormBuild build = dormBuildService.findById(Integer.parseInt(dormBuildId)); System.out.println("id1:"+dormBuildId); //保存宿舍楼信息,到前端页面展示 request.setAttribute("build", build); //表示跳转到宿舍楼修改页面 request.getRequestDispatcher("AddOrAlterBuild.jsp").forward(request, response); } } } ``` # DormBuild.java ``` package zj.shizhan.bean; public class DormBuild { private Integer dormBuildId; private String dormBuildName; private String detail; public DormBuild() { super(); } public DormBuild(Integer dormBuildId,String dormBuildName, String detail) { super(); this.dormBuildId = dormBuildId; this.dormBuildName = dormBuildName; this.detail = detail; } public String getDormBuildName() { return dormBuildName; } public void setDormBuildName(String dormBuildName) { this.dormBuildName = dormBuildName; } public String getDetail() { return detail; } public void setDetail(String detail) { this.detail = detail; } public Integer getDormBuildId() { return dormBuildId; } public void setDormBuildId(Integer dormBuildId) { this.dormBuildId = dormBuildId; } } ```

项目发布到tomcat当时没问题,一天后就会出现数据访问不到的情况,重启tomcat又好了

写了一个手机网页浏览的小的计算器(关于六金缴税的计算),每次访问 该网页会先用ajax获取数据库中的六金城市数据。 整个项目就一个index.jsp js文件引用网络地址 一个Servlet 项目发布到服务器上,打成war包放到webapps目录下,tomcat自动解压后 当时可以访问,效果正确。 可是每次第二天再访问,就会发现六金城市读取不到。因为在服务器上也 不懂如何调试,不知道问题出在哪里。 求大神解决。

如果tomcat中 一直抛这样的异常 过一段时间会死掉吗??

<p>目前碰到个问题 就是 tomcat 跑一段时间后就会死掉 进程没有死但是网页打不开</p> <p> </p> <p> </p> <p>应用 apache2.2 + tomcat5.0 </p> <p> </p> <p>跑的是纯静态的页面  只有页面的底部的计数(ajax 请求)是用的jsp 访问数据库 目前由于</p> <p>数据服务器停掉了所以一直报这样的错误 但是这样一段时间后tomcat 会死掉网站页面打不开了</p> <p>不知道这是导致tomcat死掉的元凶吗????</p> <p>2008-11-21 07:39:56 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception<br />org.apache.commons.dbcp.DbcpException: java.sql.SQLException: ORA-01033: ORACLE initialization or shutdown in progress</p> <p> at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:85)<br /> at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:184)<br /> at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(Unknown Source)<br /> at org.apache.commons.dbcp.AbandonedObjectPool.borrowObject(AbandonedObjectPool.java:117)<br /> at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:110)<br /> at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:312)<br /> at org.apache.jsp.readcount_jsp._jspService(readcount_jsp.java:59)<br /> at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)<br /> at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)<br /> at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)<br /> at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)<br /> at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)<br /> at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)<br /> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)<br /> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)<br /> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)<br /> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)<br /> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)<br /> at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)<br /> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)<br /> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)<br /> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)<br /> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)<br /> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)<br /> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)<br /> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)<br /> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)<br /> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)<br /> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)<br /> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)<br /> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)<br /> at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:209)<br /> at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:670)<br /> at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:517)<br /> at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:575)<br /> at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)<br /> at java.lang.Thread.run(Unknown Source)<br />Caused by: java.sql.SQLException: ORA-01033: ORACLE initialization or shutdown in progress</p> <p> at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)<br /> at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)<br /> at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:283)<br /> at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:278)<br /> at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOsesskey(T4CTTIoauthenticate.java:294)<br /> at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:357)<br /> at oracle.jdbc.driver.PhysicalConnection.&lt;init&gt;(PhysicalConnection.java:439)<br /> at oracle.jdbc.driver.T4CConnection.&lt;init&gt;(T4CConnection.java:165)<br /> at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)<br /> at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)<br /> at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:83)<br /> ... 36 more</p><br /><strong>问题补充:</strong><br /><p>目前碰到个问题 就是 tomcat 跑一段时间后就会死掉 进程没有死但是网页打不开</p> <br /><p>?</p> <br /><p>?</p> <br /><p>应用 apache2.2 + tomcat5.0 </p> <br /><p>?</p> <br /><p>跑的是纯静态的页面? 只有页面的底部的计数(ajax 请求)是用的jsp 访问数据库 目前由于</p> <br /><p><span style="color: red;">数据服务器停掉了所以一直报这样的错误</span> 但是这样一段时间后tomcat 会死掉网站页面打不开了</p> <br /><p>不知道这是导致tomcat死掉的元凶吗????</p> <br /><p>2008-11-21 07:39:56 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception<br />org.apache.commons.dbcp.DbcpException: java.sql.SQLException: ORA-01033: ORACLE initialization or shutdown in progress</p> <br /><p>?at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:85)<br />?at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:184)<br />?at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(Unknown Source)<br />?at org.apache.commons.dbcp.AbandonedObjectPool.borrowObject(AbandonedObjectPool.java:117)<br />?at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:110)<br />?at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:312)<br />?at org.apache.jsp.readcount_jsp._jspService(readcount_jsp.java:59)<br />?at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)<br />?at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)<br />?at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)<br />?at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)<br />?at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)<br />?at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)<br />?at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)<br />?at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)<br />?at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)<br />?at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)<br />?at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)<br />?at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)<br />?at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)<br />?at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)<br />?at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)<br />?at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)<br />?at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)<br />?at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)<br />?at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)<br />?at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)<br />?at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)<br />?at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)<br />?at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)<br />?at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)<br />?at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:209)<br />?at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:670)<br />?at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:517)<br />?at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:575)<br />?at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)<br />?at java.lang.Thread.run(Unknown Source)<br />Caused by: java.sql.SQLException: ORA-01033: ORACLE initialization or shutdown in progress</p> <br /><p>?at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)<br />?at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)<br />?at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:283)<br />?at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:278)<br />?at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOsesskey(T4CTTIoauthenticate.java:294)<br />?at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:357)<br />?at oracle.jdbc.driver.PhysicalConnection.&lt;init&gt;(PhysicalConnection.java:439)<br />?at oracle.jdbc.driver.T4CConnection.&lt;init&gt;(T4CConnection.java:165)<br />?at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)<br />?at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)<br />?at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:83)<br />?... 36 more</p> <br /> <br /> <br /> <br />bohemia说 <br />有异常; 还是查查程序问题吧; <br /> <br />我知道异常的是怎么出的 关键是 <span style="color: red;">数据服务器停掉了</span>所以报错,可为什么这样tomcat就会死掉吗???? <br /> <br /> <br /><br /><strong>问题补充:</strong><br />在数据服务器停掉以前tomcat 是没有死掉过的 <br />还有这些异常是再tomcat 的日志里 copy 的<br /><strong>问题补充:</strong><br />汗~~~~~~ 关不了提问了

springmvc的全注解配置(完全不用xml)框架

最近在看spring实战的第五章springmvc,了解到了在使用springmvc时,我们原来的做法是需要将dispatcherservlet配置在xml中,而如今我们可以舍弃这种做法而选择配置在java类中(即完全不需要xml了)。但我在实现的时候按照书上的源码打,最后想在web页面中验证springmvc却开不开jsp动态网页,报404错误(是不是哪里地方需要启动这个java类而我却没有启动呢)。求高手指点,下面将po出我的源码 //这个类替代了原先的dispatcherservlet public class SpittrWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{ @Override protected Class<?>[] getRootConfigClasses() { // TODO Auto-generated method stub return new Class<?>[]{RootConfig.class}; } @Override protected Class<?>[] getServletConfigClasses() { // TODO Auto-generated method stub return new Class<?>[]{WebConfig.class}; } @Override protected String[] getServletMappings() { // TODO Auto-generated method stub return new String[]{"/"}; } } //这个类是由dispatcherservlet加载应用上下文 @Configuration @EnableWebMvc @ComponentScan("spittr.web") public class WebConfig extends WebMvcConfigurerAdapter{ @Bean public ViewResolver viewResolver(){ InternalResourceViewResolver resolver=new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/"); resolver.setSuffix(".jsp"); resolver.setExposeContextBeansAsAttributes(true); return resolver; } public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer){ configurer.enable(); } } //这个类是由ContextLoaderListener加载应用上下文 @Configuration @ComponentScan(basePackages={"spittr"},excludeFilters={@Filter(type=FilterType.ANNOTATION,value=EnableWebMvc.class)}) public class RootConfig { } 配置完这三个类之后我就在项目目录WEB-INF下面创建了index页面,然而却打不开这个页面,报404,去掉之前那三个类就可以正常运行这个页面。希望高手指出错误在哪里

做了一个小时的面试题(没有过 希望大家帮忙答下 虽然很幼稚 毕竟每个人都是这么过来的吗 感激了!)

XX软件工程师笔试试题 注:1、请参考人员将答案写在答题纸上,勿将答案写在此卷上。 2、请参考人员将编号与姓名填写在答题纸上。 1、 以下数据结构中不属于线性数据结构的是()。 A、队列 B、线性表 C、二叉树 D、栈 我的答案:C 2、 在结构化方法中,用数据流程图(DFD)作为描述工具的软件开发阶段是()。 A、 可行性分析 B、需求分析 C、详细设计 D、程序编码 我的答案:B 3、 结构化程序设计主要强调的是()。 A、 程序的规模 B、程序的易读性 C、程序的执行效率 D、程序的可移植性 我的答案:C 4、 在软件生命周期中,能准确地确定软件系统必须做什么和必须具备哪些功能的阶段()。 A、 概要设计 B、详细设计 C、可行性分析 D、需求分析 我的答案:B 5、 下列关于栈的叙述中正确的是()。 A、 在栈中只能插入数据 B、在栈中只能删除数据 B、 栈是先进先出的线性表 D、栈是先进后出的线性表 我的答案:D 6、 下面不属于软件设计原则的是()。 A、 抽象 B、模块化 C、自底向上 D、信息隐蔽 我的答案:C 7、 对长度为N的线性表进行顺序查找,在最坏情况下所需要的比较次数为()。 A、 N+1 B、N C、(N+1)/2 D、N/2 我的答案:C 8、 视图设计一般有3种设计次序,下列不属于视图设计的是()。 A、 自顶向下 B、由外向内 C、由内向外 D、自底向上 我的答案:C 9、下列有关数据库的描述,正确的是()。 A、数据库是一个DBF文件 B、数据库是一个关系 C、数据库是一个结构化的数据集合 D、数据库是一组文件 我的答案:C 10、下列说法中,不属于数据模型所描述的内容的是()。 A、数据结构 B、数据操作 C、数据查询 D、数据约束 我的答案:A 11、若按功能划分,软件测试的方法通常分为白盒测试方法和(黑盒测试方法)。 12、数据库系统的三级模式分别为(级联)模式、内部级模式与外部级模式。 13、在最坏情况下,冒泡排序的时间复杂度为(N+1/2)。 14、在面向对象方法中,信息隐蔽是通过对象的(封装)性来实现的。 15、关系模型的数据操纵既是建立在关系上的数据操纵,一般有(插入)、增加、删除、和修改四种操作。 16、TIME()的返回值的数据类型是(String)类型。 17、编写SQL语句 1)、创建一张学生表,包含以下信息,学号,姓名,年龄,性别,家庭住址,联系电话 我的答案: create table student( studentCardNo number(2) primary key, name char(10), age number(2), sex char(2) check(sex in (‘男’,’女’)), address varchar2(100), tel number(2) ) 2)、修改学生表的结构,添加一列信息,学历 我的答案: alter table student add(xueli varchar2(20)); 3)、修改学生表的结构,删除一列信息,家庭住址 我的答案: alter table student drop column address; 4)、向学生表添加如下信息: 学号 姓名 年龄 性别 联系电话 学历 1 A 22 男 123456 小学 2 B 21 男 119 中学 3 C 23 男 110 高中 4 D 18 女 114 大学 我的答案: insert into student values(‘&1’,’&2’,’&3’); 一次一次添加 5)修改学生表的数据,将电话号码以11开头的学员的学历改为“大专” 我的答案: update student set xueli=”大专” where tel like 11%; 6)删除学生表的数据,姓名以C开头,性别为‘男’的记录删除 我的答案: delete student where name like C% or sex=”男”; 7)查询学生表的数据,将所有年龄小于22岁的,学历为“大专”的,学生的姓名和学号显示出来 我的答案: select name,studentCardNo from student where age<22 and xueli=”大专”; 8)查询学生表的数据,查询所有信息,列出前25%的记录 我的答案: select top*0.25 from student; 9)查询出所有学生的姓名,性别,年龄降序排列 我的答案: select name,sex,age from student where age desc; 10)按照性别分组查询所有的平均年龄 我的答案: select avg(age) from student group by sex; 18、什么是存储过程?为什么存储过程要比单纯的SQL语句执行起来要快? 我的答案: 存储过程算是一种优化查询需要比单存SQL语句执行的要快 19、两张关联表,删除主表中已经在副表中没有的信息 我的答案 delete from fubiao a where a.fid not in(select id from zhubiao) 20、程序题: 用1、2、2、3、4、5这六个数字,用java或你熟悉的语言,打印出所有不同的排列,如:512234、412345等,要求:“4”不能再第三位,“3”与“5”不能相连。并将这些数据按从小到大输出。 我的答案 我的写的不好 没贴下 笔试的时候没写全 21、String 和 StringBuffer的区别 我的答案 String定长 StringBuffer 变长 22、&和&&的区别 我的答案 &短路与 &&逻辑与 网上答案: & 是位运算符,表示按位与运算, && 是逻辑运算符,表示逻辑与(and)。 23、final,finally,finalize的区别 我的答案 Final静变量关键字,finally异常关键字,finalize 网上答案 final 用于声明属性,方法和类,分别表示属性不可变,方法不可覆盖,类不可继承。 finally是异常处理语句结构的一部分,表示总是执行。 finalize是Object类的一个方法,在垃圾收集器执行的时候会调用被回收对象的此方法, 可以覆盖此方法提供垃圾收集时的其他资源回收,例如关闭文件等。 24、数组有没有length()这个方法?String有没有length()这个方法? 我的答案: 数组没有length()这个方法,有length的属性。 String有length()这个方法。 25、是否可以继承String类? 我的答案: 不可以 解释的很乱 26、说出数据连接池的工作机制是什么? 我的答案: 反正解释的很乱我感觉 27、垃圾回收的优点和原理。并考虑2种回收机制。 我的答案: 动态回收 解释的很乱 网上答案: Java语言中一个显著的特点就是引入了垃圾回收机制,使c++程序员最头疼的内存管理的问题迎刃而解, 它使得Java程序员在编写程序的时候不再需要考虑内存管理。由于有个垃圾回收机制,Java中的对象不再有"作用域"的概念, 只有对象的引用才有"作用域"。垃圾回收可以有效的防止内存泄露,有效的使用可以使用的内存。 垃圾回收器通常是作为一个单独的低级别的线程运行,不可预知的情况下对内存堆中已经死亡的或者长时间没有 使用的对象进行清除和回收,程序员不能实时的调用垃圾回收器对某个对象或所有对象进行垃圾回收。 回收机制有分代复制垃圾回收和标记垃圾回收,增量垃圾回收。 28、你所知道的集合类都有哪些?区别?主要方法? 我的答案: Arraylist 非线性的、Vertor线性的 29、JSP的内置对象及方法。 我的答案: Page,exception,out,page content,application,request,reponse,session,config 30、页面间对象传递的方法。 我的答案: 那几个方法都写错了 31、你知道Request对象的主要方法有哪些? 32、J2EE是技术还是平台还是框架? 我的答案: J2EE是技术也是平台 网上答案: J2EE本身是一个标准,一个为企业分布式应用的开发提供的标准平台。 J2EE也是一个框架,包括JDBC、JNDI、RMI、JMS、EJB、JTA等技术。 33、我们在web应用开发过程中经常遇到输出某种编码的字符,如iso8859-1等,如何输出一个某种(例如GBK编码类型)编码的字符串? Request encording(“GBK”) 34、j2ee常用的设计模式?说明工厂模式。 Gof23种设计模式 工厂模式:Factory 网上答案: Java中的23种设计模式: Factory(工厂模式), Builder(建造模式), Factory Method(工厂方法模式), Prototype(原始模型模式),Singleton(单例模式), Facade(门面模式), Adapter(适配器模式), Bridge(桥梁模式), Composite(合成模式), Decorator(装饰模式), Flyweight(享元模式), Proxy(代理模式), Command(命令模式), Interpreter(解释器模式), Visitor(访问者模式), Iterator(迭代子模式), Mediator(调停者模式), Memento(备忘录模式), Observer(观察者模式), State(状态模式), Strategy(策略模式), Template Method(模板方法模式), Chain Of Responsibleity(责任链模式) 工厂模式:工厂模式是一种经常被使用到的模式,根据工厂模式实现的类可以根据提供的数据生成一组类中某一个类的实例, 通常这一组类有一个公共的抽象父类并且实现了相同的方法,但是这些方法针对不同的数据进行了不同的操作。 首先需要定义一个基类,该类的子类通过不同的方法实现了基类中的方法。 然后需要定义一个工厂类,工厂类可以根据条件生成不同的子类实例。 当得到子类的实例后,开发人员可以调用基类中的方法而不必考虑到底返回的是哪一个子类的实例。 35、JSP四种会话跟踪技术 我的答案: Application cookie session 36、排序都有哪几种方法?请举例 冒泡 选择 快序 二分查找 网上答案: 排序的方法有:插入排序(直接插入排序、希尔排序), 交换排序(冒泡排序、快速排序), 选择排序(直接选择排序、堆排序), 归并排序,分配排序(箱排序、基数排序) 快速排序的伪代码。 //使用快速排序方法对a[ 0 :n- 1 ]排序 从a[ 0 :n- 1 ]中选择一个元素作为m i d d l e,该元素为支点 把余下的元素分割为两段left 和r i g h t,使得l e f t中的元素都小于等于支点,而right 中的元素都大于等于支点 递归地使用快速排序方法对left 进行排序 递归地使用快速排序方法对right 进行排序 所得结果为l e f t + m i d d l e + r i g h t 37、关于模块间的设计原则? 规范要一样 38、项目过程一般是怎样的?你参加过几个项目开发?参加过的项目流程是怎样的?自己负责与人合作工作内容及自我评价? 从需求调研——设计开发——实施 参加过网站的实施 模板的制作 39、tomcat自动关闭常见原因? 我的答案: 现在没遇到过 40、如何设置TOMCAT内存和连接数? 我的答案: Tomcat群集 41、你如何理解Tomcat是什么? 我的答案: Tomcat是JSP Servlet 容器恰当的说 42、静态变量和实例变量的区别? 我的答案: 静态变量域用final修饰,每次都被调用 实例变量则不会 43、IE、FF下面CSS的解释区别 我的答案: 自己编的 44、web前端技术你了解哪些技术? 我的答案: JAVAScript,CSS,DIV,Ajax,Ajax框架,DWR,dojo,jguery 45、什么是报表?什么是报表控件,作用是什么?你了解哪些报表工具? 我的答案: 解释的很乱 46、你了解的那些统计图表类型? 我的答案: 自己编的 47、Flex与数据库连接的三种方式? 我的答案: 自己编的 ------------------------------------------------------- 我答错的、 错在哪里? 没答上的帮忙解答下? 感激了 !

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> 取出来的值都是空的,为什么,是哪里错了?

存储过程执行SQL与Print SQL语句单独执行结果不同

代码如下: DECLARE @SQLEX1 nVARCHAR(MAX) DECLARE @TempEX1 VARCHAR(MAX) SELECT @SQLEX1 = '' SELECT @TempEX1 = '' SET @SQLEX1 = 'SELECT @Temp3 = A.T FROM (SELECT T = REPLACE((SELECT DISTINCT ''20'' AS ''machine/@id1'',1 AS ''machine/@actionId'' FROM TEKIOUKISYU_適応機種 AS TK WHERE IUINDEX = ''' + @IUID +''' AND MDPACKKATAMEI = '''+@MDPACKKATAMEI+''' AND ID3 = ''' + @Tekiouos + ''' FOR XML PATH(''machineSupport'')),''/>'',''/>''+ISNULL((SELECT DISTINCT ID AS ''@id'' FROM TEXTINFO INNER JOIN (SELECT DISTINCT IUINDEX,MDPACKKATAMEI,BPQ20001000 AS BK FROM TEKIOUKISYU_適応機種 WHERE BPQ20001000 <> '''' AND ID3 = '''+@Tekiouos+''' AND MDPACKKATAMEI = '''+@MDPACKKATAMEI+''' AND IUINDEX = '''+@IUID+''' ) AS IPT ON IPT.IUINDEX = TEXTINFO.IUINDEX AND IPT.MDPACKKATAMEI = TEXTINFO.MDPACKKATAMEI WHERE TEXTINFO.NAME LIKE ''[0-9]%'' AND RDBv6.dbo.findRegex(VALUE,CASE WHEN IPT.BK = '''' THEN ''#'' ELSE IPT.BK END,0) = 1 FOR XML PATH(''noteRef''), ROOT(''noteRefs'')),''<noteRefs/>''))) A WHERE A.T LIKE ''%actionId%''' print @SQLEX1 EXEC sp_executesql @SQLEX1,N'@Temp3 varchar(max) output',@TempEX1 output 该段代码嵌套在一个游标中,@SQLEX1返回值@Temp3在执行的sp_executesql时返回“<machineSupport><machine id1="100" actionId="1"/><noteRefs/></machineSupport>”而使用Print出来的语句单独执行时返回“<machineSupport><machine id1="100" actionId="1"/><noteRefs><noteRef id="21EB1E0B-F74D-4131-B512-D9CF19F7B207"/></noteRefs></machineSupport>” 求大神帮忙啊,是在不懂为什么会出现这种情况

想把shiro进行封装打jar包,方便以后其他项目重复使用,我该怎么办。。。?

想把shiro进行封装打jar包,方便以后其他项目重复使用,但是shiro方法参数都是封装好的,我该怎么办。。。? ``` package com.zns.shiro.config; import at.pollux.thymeleaf.shiro.dialect.ShiroDialect; import com.zns.shiro.domain.User; import com.zns.shiro.service.UserService; import org.apache.catalina.security.SecurityUtil; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.credential.HashedCredentialsMatcher; import org.apache.shiro.codec.Base64; import org.apache.shiro.spring.LifecycleBeanPostProcessor; import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; import org.apache.shiro.spring.web.ShiroFilterFactoryBean; import org.apache.shiro.subject.Subject; import org.apache.shiro.web.mgt.CookieRememberMeManager; import org.apache.shiro.web.mgt.DefaultWebSecurityManager; import org.apache.shiro.web.servlet.SimpleCookie; import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.util.LinkedHashMap; import java.util.Map; /** * @功能描述:Shiro配置类 * @创建日期: 2019/5/6 18:46 */ @Configuration public class ShiroConfig { @Autowired private UserService userService; /** * 密码校验规则HashedCredentialsMatcher * 这个类是为了对密码进行编码的 , * 防止密码在数据库里明码保存 , 当然在登陆认证的时候 , * 这个类也负责对form里输入的密码进行编码 * 处理认证匹配处理器:如果自定义需要实现继承HashedCredentialsMatcher */ @Bean("hashedCredentialsMatcher") public HashedCredentialsMatcher hashedCredentialsMatcher() { HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher(); //指定加密方式为MD5 credentialsMatcher.setHashAlgorithmName("MD5"); //加密次数 credentialsMatcher.setHashIterations(1024); credentialsMatcher.setStoredCredentialsHexEncoded(true); return credentialsMatcher; } /** * 创建ShiroFilterFactoryBean * shiro过滤bean */ @Bean public ShiroFilterFactoryBean getShiroFilterFactoryBean(@Qualifier("securityManager") DefaultWebSecurityManager securityManager){ ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); // 设置安全管理器 shiroFilterFactoryBean.setSecurityManager(securityManager); // 添加Shiro内置过滤器 /** * Shiro内置过滤器,可以实现权限相关的拦截器 * 常用的过滤器: * anon: 无需认证(登录)可以访问 * authc: 必须认证才可以访问 * user: 如果使用rememberMe功能可以直接访问 * perms: 该资源必须得到资源权限才可以访问 * role: 该资源必须得到角色权限才可以访问 */ Map<String, String> filerMap = new LinkedHashMap<>(); //顺序的map //配置记住我或认证通过可以访问的地址 filerMap.put("/testThymeleaf", "user"); //如果没有拦截,默认会跳转到login.jsp,可以通过setLoginUrl设置登录页面 //filerMap.put("/add","authc"); //filerMap.put("/update","authc"); filerMap.put("/testThymeleaf","anon"); filerMap.put("/login","anon"); //授权过滤器 filerMap.put("/add","perms[user:add]"); filerMap.put("/update","perms[user:update]"); filerMap.put("/*","authc"); //设置登录的页面,发送toLogin请求 shiroFilterFactoryBean.setLoginUrl("/toLogin"); //设置未授权的页面 shiroFilterFactoryBean.setUnauthorizedUrl("/noAuth"); //设置过滤器 shiroFilterFactoryBean.setFilterChainDefinitionMap(filerMap); return shiroFilterFactoryBean; } /** * 创建DefaultWebSecurityManager */ @Bean(name = "securityManager") public DefaultWebSecurityManager getDefaultWebSecurityManager(@Qualifier("userRealm") UserRealm userRealm){ DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); // 关联realm securityManager.setRealm(userRealm); securityManager.setRememberMeManager(rememberMeManager()); return securityManager; } /** * 创建Realm */ @Bean(name = "userRealm") public UserRealm getRealm(){ return new UserRealm(); } /** * 配置ShiroDialect,用于thymeleaf和shiro标签配合使用 */ @Bean public ShiroDialect getShiroDialect(){ return new ShiroDialect(); } /** * Spring的一个bean , 由Advisor决定对哪些类的方法进行AOP代理 . * @return */ @Bean public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { DefaultAdvisorAutoProxyCreator creator = new DefaultAdvisorAutoProxyCreator(); creator.setProxyTargetClass(true); return creator; } /** * lifecycleBeanPostProcessor是负责生命周期的 , 初始化和销毁的类 * (可选) */ @Bean("lifecycleBeanPostProcessor") public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() { return new LifecycleBeanPostProcessor(); } /** 2 * cookie对象; 3 * rememberMeCookie()方法是设置Cookie的生成模版,比如cookie的name,cookie的有效时间等等。 4 * @return 5 */ @Bean public SimpleCookie rememberMeCookie(){ //System.out.println("ShiroConfiguration.rememberMeCookie()"); //这个参数是cookie的名称,对应前端的checkbox的name = rememberMe SimpleCookie simpleCookie = new SimpleCookie("rememberMe"); //<!-- 记住我cookie生效时间30天 ,单位秒;--> simpleCookie.setMaxAge(259200); return simpleCookie; } /** * cookie管理对象; * rememberMeManager()方法是生成rememberMe管理器,而且要将这个rememberMe管理器设置到securityManager中 * @return */ @Bean public CookieRememberMeManager rememberMeManager(){ //System.out.println("ShiroConfiguration.rememberMeManager()"); CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager(); cookieRememberMeManager.setCookie(rememberMeCookie()); //rememberMe cookie加密的密钥 建议每个项目都不一样 默认AES算法 密钥长度(128 256 512 位) cookieRememberMeManager.setCipherKey(Base64.decode("2AvVhdsgUs0FSA3SDFAdag==")); return cookieRememberMeManager; } } ```package com.zns.shiro.config; import com.zns.shiro.domain.User; import com.zns.shiro.service.UserService; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.*; import org.apache.shiro.authz.AuthorizationInfo; import org.apache.shiro.authz.SimpleAuthorizationInfo; import org.apache.shiro.realm.AuthorizingRealm; import org.apache.shiro.subject.PrincipalCollection; import org.apache.shiro.subject.Subject; import org.apache.shiro.util.ByteSource; import org.springframework.beans.factory.annotation.Autowired; /** * @功能描述:TODO * @创建日期: 2019/5/6 18:56 */ public class UserRealm extends AuthorizingRealm { @Autowired private UserService userService; /** * 执行授权逻辑 */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { System.out.println("执行授权逻辑"); //给资源进行授权 SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); //获取当前登录用户 Subject subject = SecurityUtils.getSubject(); User user = (User)subject.getPrincipal(); //System.out.println(subject.getPrincipal()); User dbUser = userService.findById(user.getId()); // info.addStringPermission("user:add"); info.addStringPermission(dbUser.getPerms()); return info; } /** * 执行认证逻辑 */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { System.out.println("执行认证逻辑"); //编写shiro判断逻辑,判断用户名和密码 UsernamePasswordToken token = (UsernamePasswordToken)authenticationToken; // //根据用户名查询数据库中对应的记录 User user = userService.findByName(token.getUsername()); //1、判断用户名 if(user == null){ //用户名不存在 return null; //shiro底层会抛出UnKnowAccountException } //2、判断密码, 这里的user是principal //return new SimpleAuthenticationInfo(user,user.getPassword(),getName()); //盐值 ByteSource credentialsSalt = ByteSource.Util.bytes(token.getUsername()); //封装用户信息,构建AuthenticationInfo对象并返回 AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(user, user.getPassword(), credentialsSalt, getName()); return authcInfo; } } ``` ```

spring2.5.6 hibernate3.3.2 annotation无法持久化entity

请教一下各位: <br /> <br />试了一下spring2.5.6 MVC + hibernate3.3.2的annotation组合,在持久化实体时,没有报错,日志也显示调用到了相应的操作,但是数据库中却没有数据...,不知道是哪里有问题<img src="/images/smiles/icon_sad.gif"/> ,代码如下: <br /> <br /><strong>applicationContext.xml</strong> <br /><pre name="code" class="java"> &lt;context:property-placeholder location="classpath:jdbc.properties"/&gt; &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&gt; &lt;property name="driverClass" value="${jdbc.driverClassName}"/&gt; &lt;property name="jdbcUrl" value="${jdbc.url}"/&gt; &lt;property name="user" value="${jdbc.username}"/&gt; &lt;property name="password" value="${jdbc.password}"/&gt; &lt;property name="minPoolSize"&gt;&lt;value&gt;10&lt;/value&gt;&lt;/property&gt; &lt;property name="maxPoolSize"&gt;&lt;value&gt;100&lt;/value&gt;&lt;/property&gt; &lt;property name="maxIdleTime"&gt;&lt;value&gt;1800&lt;/value&gt;&lt;/property&gt; &lt;property name="acquireIncrement"&gt;&lt;value&gt;2&lt;/value&gt;&lt;/property&gt; &lt;property name="maxStatements"&gt;&lt;value&gt;100&lt;/value&gt;&lt;/property&gt; &lt;property name="initialPoolSize"&gt;&lt;value&gt;10&lt;/value&gt;&lt;/property&gt; &lt;property name="idleConnectionTestPeriod"&gt;&lt;value&gt;1800&lt;/value&gt;&lt;/property&gt; &lt;property name="acquireRetryAttempts"&gt;&lt;value&gt;30&lt;/value&gt;&lt;/property&gt; &lt;property name="breakAfterAcquireFailure"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt; &lt;property name="testConnectionOnCheckout"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt; &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt; &lt;property name="annotatedClasses"&gt; &lt;list&gt; &lt;value&gt;com.zy.sa.test.entity.Userinfo&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;!-- &lt;property name="packagesToScan" value="com.zy.sa.test.entity.*" /&gt; --&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.connection.provider_class"&gt;com.mchange.v2.c3p0.ComboPooledDataSource&lt;/prop&gt; &lt;prop key="hibernate.dialect"&gt;${hibernate_dialect}&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;${hibernate_show_sql}&lt;/prop&gt; &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.transcation.flush_before_completion"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.generate_statistics"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.connection.release_mode"&gt;auto&lt;/prop&gt; &lt;prop key="hibernate.autoReconnect"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.bytecode.use_reflection_optimizer"&gt;true&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory"/&gt; &lt;!-- 支持 @Transactional --&gt; &lt;tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /&gt; </pre> <br /> <br /><strong>annomvc-servlet.xml</strong> <br /><pre name="code" class="java"> &lt;!-- 对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 --&gt; &lt;context:component-scan base-package="com.zy.sa.test" /&gt; &lt;context:annotation-config/&gt; &lt;!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 --&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /&gt; &lt;!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 --&gt; &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /&gt;</pre> <br /> <br /><strong>web.xml</strong> <br /> <br /><pre name="code" class="java">&lt;!-- Spring 服务层的配置文件 --&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;!-- 日志配置 --&gt; &lt;context-param&gt; &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEF-INF/classes/log4j.properties&lt;/param-value&gt; &lt;/context-param&gt; &lt;!-- Spring 容器启动监听器 --&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;!-- 要负责处理由JavaBeans Introspector的使用而引起的缓冲泄露 --&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.util.IntrospectorCleanupListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;!-- 编码 --&gt; &lt;filter&gt; &lt;filter-name&gt;encodingFilter&lt;/filter-name&gt; &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;/filter-class&gt; &lt;init-param&gt; &lt;param-name&gt;encoding&lt;/param-name&gt; &lt;param-value&gt;UTF-8&lt;/param-value&gt; &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;forceEncoding&lt;/param-name&gt; &lt;param-value&gt;true&lt;/param-value&gt; &lt;/init-param&gt; &lt;/filter&gt; &lt;!-- Hibernate Open Session In View --&gt; &lt;filter&gt; &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt; &lt;filter-class&gt;org.springframework.orm.hibernate3.support.OpenSessionInViewFilter&lt;/filter-class&gt; &lt;/filter&gt; &lt;!-- Hibernate Open Session In View --&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;!-- 编码 --&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;encodingFilter&lt;/filter-name&gt; &lt;url-pattern&gt;*.jsp&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;!-- Spring MVC 的Servlet,它将加载WEB-INF/annomvc-servlet.xml 的配置文件,以启动Spring MVC模块--&gt; &lt;servlet&gt; &lt;servlet-name&gt;annomvc&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;2&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;annomvc&lt;/servlet-name&gt; &lt;url-pattern&gt;*.do&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.html&lt;/welcome-file&gt; &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt; &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt; &lt;welcome-file&gt;default.html&lt;/welcome-file&gt; &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt; &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;error-page&gt; &lt;exception-type&gt;java.lang.Exception&lt;/exception-type&gt; &lt;location&gt;/WEB-INF/common/uncaughtException.jsp&lt;/location&gt; &lt;/error-page&gt; &lt;error-page&gt; &lt;error-code&gt;403&lt;/error-code&gt; &lt;location&gt;/WEB-INF/common/403.jsp&lt;/location&gt; &lt;/error-page&gt; &lt;error-page&gt; &lt;error-code&gt;404&lt;/error-code&gt; &lt;location&gt;/WEB-INF/common/404.jsp&lt;/location&gt; &lt;/error-page&gt; &lt;error-page&gt; &lt;error-code&gt;500&lt;/error-code&gt; &lt;location&gt;/WEB-INF/common/500.jsp&lt;/location&gt; &lt;/error-page&gt;</pre> <br /> <br /><strong>MyController.java</strong> <br /> <br /><pre name="code" class="java">@Controller @RequestMapping("/my.do") public class MyController { @Autowired private UserinfoService userinfoService; @RequestMapping public String my(Userinfo user) { System.out.println("my.do"); System.out.println("userinfoService: " + userinfoService); System.out.println(user); userinfoService.createUserInfo(user); return "userinfo_create"; } }</pre> <br /> <br /> <br /><strong>UserinfoServiceImpl.java</strong> <br /> <br /><pre name="code" class="java">@Service @Transactional public class UserinfoServiceImpl implements UserinfoService { @Autowired private UserinfoDao userinfoDao; @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public void createUserInfo(Userinfo user) { Userinfo userinfo = new Userinfo(); userinfo.setId("ww"); userinfo.setUserName("wangwu"); userinfo.setPassword("111"); userinfo.setEmail("ww@aaa.com"); userinfoDao.save(userinfo); userinfoDao.getSession().save(userinfo); } @Override @Transactional(readOnly=true) public List&lt;Userinfo&gt; getAllUser() { return userinfoDao.getAll(); }</pre> <br /> <br /><strong>UserinfoDao.java</strong> <br /><pre name="code" class="java">@Repository public class UserinfoDao extends HibernateDao&lt;Userinfo, String&gt; { @Override @Autowired public void setSessionFactory(SessionFactory sessionFactory) { logger.info("sessionFactory: " + sessionFactory); super.setSessionFactory(sessionFactory); } }</pre> <br /> <br /><strong>HibernateDao.java</strong> <br /> <br /><pre name="code" class="java"> public Session getSession() { return sessionFactory.getCurrentSession(); } public void save(final T entity) { Assert.notNull(entity, "entity不能为空"); getSession().saveOrUpdate(entity); logger.debug("save entity: {}", entity); } </pre> <br /> <br />通过:http://localhost:8080/springannotation/my.do?id=lisi&amp;userName=ls&amp;password=111&amp;email=ls@aaa.com访问,控制台打印出了实体信息,但数据库无数据,不知道问题出在哪里?<img src="/images/smiles/icon_razz.gif"/> <br/><strong>问题补充</strong><br/>没人帮忙看一下啊 <br />

spring security cas单点登录拒绝访问

[b]cas服务端和cas客户端都已经配合,访问cas服务端可以登录,访问客户端应用资源的时候出现拒绝访问问题,但是[color=red]能成功跳转到cas服务端的login页面,输入账号密码后控制台打印显示出服务端登录成功,但是关于客户端的打印出现拒绝访问异常,而且httpSession不为null但是里面没值[/color][/b]。 初次使用spring security和cas望多多指教. 异常信息: [color=red][b]首次登录直接出现拒绝访问,但是却能跳转到cas 登录页面,[/b][/color] [quote] 信息: Server startup in 21955 ms 2012-6-6 11:51:31 org.apache.catalina.core.ApplicationContext log 信息: HTMLManager: init: Associated with Deployer 'Catalina:type=Deployer,host=localhost' 2012-6-6 11:51:31 org.apache.catalina.core.ApplicationContext log 信息: HTMLManager: init: Global resources are available 2012-6-6 11:51:31 org.apache.catalina.core.ApplicationContext log 信息: HTMLManager: list: Listing contexts for virtual host 'localhost' 2012-06-06 11:51:32,593 INFO [org.jasig.cas.ticket.registry.support.DefaultTicketRegistryCleaner] - <Beginning ticket cleanup.> 2012-06-06 11:51:32,593 INFO [org.jasig.cas.ticket.registry.support.DefaultTicketRegistryCleaner] - <0 tickets found to be removed.> 2012-06-06 11:51:32,593 INFO [org.jasig.cas.ticket.registry.support.DefaultTicketRegistryCleaner] - <Finished ticket cleanup.> 11:51:33,906 DEBUG org.springframework.security.web.FilterChainProxy:318 - /index.jsp at position 1 of 12 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter' 11:51:33,921 DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository:127 - No HttpSession currently exists 11:51:33,921 DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository:85 - No SecurityContext was available from the HttpSession: null. A new one will be created. 11:51:33,921 DEBUG org.springframework.security.web.FilterChainProxy:318 - /index.jsp at position 2 of 12 in additional filter chain; firing Filter: 'LogoutFilter' 11:51:33,921 DEBUG org.springframework.security.web.FilterChainProxy:318 - /index.jsp at position 3 of 12 in additional filter chain; firing Filter: 'CasAuthenticationFilter' 11:51:33,937 DEBUG org.springframework.security.cas.web.CasAuthenticationFilter:311 - serviceTicketRequest = false 11:51:33,937 DEBUG org.springframework.security.cas.web.CasAuthenticationFilter:362 - proxyReceptorConfigured = false 11:51:33,937 DEBUG org.springframework.security.cas.web.CasAuthenticationFilter:349 - proxyReceptorRequest = false 11:51:33,937 DEBUG org.springframework.security.cas.web.CasAuthenticationFilter:327 - proxyTicketRequest = false 11:51:33,937 DEBUG org.springframework.security.cas.web.CasAuthenticationFilter:262 - requiresAuthentication = false 11:51:33,937 DEBUG org.springframework.security.web.FilterChainProxy:318 - /index.jsp at position 4 of 12 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter' 11:51:33,937 DEBUG org.springframework.security.web.FilterChainProxy:318 - /index.jsp at position 5 of 12 in additional filter chain; firing Filter: 'DefaultLoginPageGeneratingFilter' 11:51:33,937 DEBUG org.springframework.security.web.FilterChainProxy:318 - /index.jsp at position 6 of 12 in additional filter chain; firing Filter: 'BasicAuthenticationFilter' 11:51:33,937 DEBUG org.springframework.security.web.FilterChainProxy:318 - /index.jsp at position 7 of 12 in additional filter chain; firing Filter: 'RequestCacheAwareFilter' 11:51:33,937 DEBUG org.springframework.security.web.FilterChainProxy:318 - /index.jsp at position 8 of 12 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter' 11:51:33,937 DEBUG org.springframework.security.web.FilterChainProxy:318 - /index.jsp at position 9 of 12 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter' 11:51:33,937 DEBUG org.springframework.security.web.authentication.AnonymousAuthenticationFilter:102 - Populated SecurityContextHolder with anonymous token: 'org.springframework.security.authentication.AnonymousAuthenticationToken@9055e4a6: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS' 11:51:33,937 DEBUG org.springframework.security.web.FilterChainProxy:318 - /index.jsp at position 10 of 12 in additional filter chain; firing Filter: 'SessionManagementFilter' 11:51:33,937 DEBUG org.springframework.security.web.session.SessionManagementFilter:91 - Requested session IDFED78FFF2BDBC0647461CBFA29AB9B23 is invalid. 11:51:33,937 DEBUG org.springframework.security.web.FilterChainProxy:318 - /index.jsp at position 11 of 12 in additional filter chain; firing Filter: 'ExceptionTranslationFilter' 11:51:33,937 DEBUG org.springframework.security.web.FilterChainProxy:318 - /index.jsp at position 12 of 12 in additional filter chain; firing Filter: 'FilterSecurityInterceptor' 11:51:33,937 DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor:193 - Secure object: FilterInvocation: URL: /index.jsp; Attributes: [ROLE_USER] 11:51:33,937 DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor:298 - Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken@9055e4a6: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS 11:51:33,937 DEBUG org.springframework.security.access.vote.AffirmativeBased:65 - Voter: org.springframework.security.access.vote.RoleVoter@13e02ed, returned: -1 11:51:33,953 DEBUG org.springframework.security.access.vote.AffirmativeBased:65 - Voter: org.springframework.security.access.vote.AuthenticatedVoter@322394, returned: 0 11:51:33,968 DEBUG org.springframework.security.web.access.ExceptionTranslationFilter:165 - Access is denied (user is anonymous); redirecting to authentication entry point org.springframework.security.access.AccessDeniedException: Access is denied at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:83) at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:205) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:114) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:91) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594) at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675) at java.lang.Thread.run(Thread.java:662) 11:51:33,984 DEBUG org.springframework.security.web.savedrequest.HttpSessionRequestCache:41 - DefaultSavedRequest added to Session: DefaultSavedRequest[http://localhost:8080/Cas_Client/] 11:51:33,984 DEBUG org.springframework.security.web.access.ExceptionTranslationFilter:185 - Calling Authentication entry point. 11:51:33,984 DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository:269 - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession. 11:51:34,015 DEBUG org.springframework.security.web.context.SecurityContextPersistenceFilter:97 - SecurityContextHolder now cleared, as request processing completed 2012-06-06 11:51:34,921 INFO [org.jasig.cas.web.flow.InitialFlowSetupAction] - <Setting path for cookies to: /casServer/> [/quote] [color=red][b]跳转到登录页面后输入账号密码出现cas服务端的信息正常,但是关于cas客户端的和上面的异常一样:[/b][/color] 打印信息: [quote] 2012-06-06 12:03:21,625 INFO [org.jasig.cas.services.DefaultServicesManagerImpl] - <Reloading registered services.> 2012-06-06 12:03:21,625 INFO [org.jasig.cas.services.DefaultServicesManagerImpl] - <Loaded 0 services.> start[1338955402531] time[603] tag[QueryDatabaseAuthenticationHandler] 2012-06-06 12:03:23,125 INFO [org.jasig.cas.authentication.AuthenticationManagerImpl] - <AuthenticationHandler: org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler successfully authenticated the user which provided the following credentials: [username: wucht]> 2012-06-06 12:03:23,234 INFO [org.jasig.cas.authentication.AuthenticationManagerImpl] - <Resolved principal wucht> 2012-06-06 12:03:23,234 INFO [org.jasig.cas.authentication.AuthenticationManagerImpl] - <Principal found: wucht> 2012-06-06 12:03:23,250 INFO [com.github.inspektr.audit.support.Slf4jLoggingAuditTrailManager] - <Audit trail record BEGIN ============================================================= WHO: [username: wucht] WHAT: supplied credentials: [username: wucht] ACTION: AUTHENTICATION_SUCCESS APPLICATION: CAS WHEN: Wed Jun 06 12:03:23 CST 2012 CLIENT IP ADDRESS: 127.0.0.1 SERVER IP ADDRESS: 127.0.0.1 ============================================================= > 2012-06-06 12:03:23,250 INFO [com.github.inspektr.audit.support.Slf4jLoggingAuditTrailManager] - <Audit trail record BEGIN ============================================================= WHO: [username: wucht] WHAT: TGT-1-0WNh4MDLT57myMG77eF54B9ix5oQP0OItPnVBGDZBYac9Bj42E-casServer ACTION: TICKET_GRANTING_TICKET_CREATED APPLICATION: CAS WHEN: Wed Jun 06 12:03:23 CST 2012 CLIENT IP ADDRESS: 127.0.0.1 SERVER IP ADDRESS: 127.0.0.1 ============================================================= > 2012-06-06 12:03:23,265 INFO [org.jasig.cas.CentralAuthenticationServiceImpl] - <Granted service ticket [ST-1-eOK4CG7zd7cApkahlva9-casServer] for service [http://localhost:8080/Cas_Client/j_acegi_cas_security_check] for user [wucht]> 2012-06-06 12:03:23,265 INFO [com.github.inspektr.audit.support.Slf4jLoggingAuditTrailManager] - <Audit trail record BEGIN ============================================================= WHO: wucht WHAT: ST-1-eOK4CG7zd7cApkahlva9-casServer for http://localhost:8080/Cas_Client/j_acegi_cas_security_check ACTION: SERVICE_TICKET_CREATED APPLICATION: CAS WHEN: Wed Jun 06 12:03:23 CST 2012 CLIENT IP ADDRESS: 127.0.0.1 SERVER IP ADDRESS: 127.0.0.1 ============================================================= > 12:03:23,296 DEBUG org.springframework.security.web.FilterChainProxy:318 - /j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer at position 1 of 12 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter' 12:03:23,296 DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository:139 - HttpSession returned null object for SPRING_SECURITY_CONTEXT 12:03:23,296 DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository:85 - No SecurityContext was available from the HttpSession: org.apache.catalina.session.StandardSessionFacade@1ef3d12. A new one will be created. 12:03:23,296 DEBUG org.springframework.security.web.FilterChainProxy:318 - /j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer at position 2 of 12 in additional filter chain; firing Filter: 'LogoutFilter' 12:03:23,296 DEBUG org.springframework.security.web.FilterChainProxy:318 - /j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer at position 3 of 12 in additional filter chain; firing Filter: 'CasAuthenticationFilter' 12:03:23,296 DEBUG org.springframework.security.cas.web.CasAuthenticationFilter:311 - serviceTicketRequest = false 12:03:23,296 DEBUG org.springframework.security.cas.web.CasAuthenticationFilter:362 - proxyReceptorConfigured = false 12:03:23,296 DEBUG org.springframework.security.cas.web.CasAuthenticationFilter:349 - proxyReceptorRequest = false 12:03:23,296 DEBUG org.springframework.security.cas.web.CasAuthenticationFilter:327 - proxyTicketRequest = false 12:03:23,296 DEBUG org.springframework.security.cas.web.CasAuthenticationFilter:262 - requiresAuthentication = false 12:03:23,296 DEBUG org.springframework.security.web.FilterChainProxy:318 - /j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer at position 4 of 12 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter' 12:03:23,296 DEBUG org.springframework.security.web.FilterChainProxy:318 - /j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer at position 5 of 12 in additional filter chain; firing Filter: 'DefaultLoginPageGeneratingFilter' 12:03:23,296 DEBUG org.springframework.security.web.FilterChainProxy:318 - /j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer at position 6 of 12 in additional filter chain; firing Filter: 'BasicAuthenticationFilter' 12:03:23,296 DEBUG org.springframework.security.web.FilterChainProxy:318 - /j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer at position 7 of 12 in additional filter chain; firing Filter: 'RequestCacheAwareFilter' 12:03:23,296 DEBUG org.springframework.security.web.savedrequest.DefaultSavedRequest:309 - pathInfo: both null (property equals) 12:03:23,296 DEBUG org.springframework.security.web.savedrequest.DefaultSavedRequest:317 - queryString: arg1=null; arg2=ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer (property not equals) 12:03:23,296 DEBUG org.springframework.security.web.savedrequest.HttpSessionRequestCache:75 - saved request doesn't match 12:03:23,296 DEBUG org.springframework.security.web.FilterChainProxy:318 - /j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer at position 8 of 12 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter' 12:03:23,296 DEBUG org.springframework.security.web.FilterChainProxy:318 - /j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer at position 9 of 12 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter' 12:03:23,296 DEBUG org.springframework.security.web.authentication.AnonymousAuthenticationFilter:102 - Populated SecurityContextHolder with anonymous token: 'org.springframework.security.authentication.AnonymousAuthenticationToken@6fa86552: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffd148a: RemoteIpAddress: 127.0.0.1; SessionId: 659060E504E41E2F28CF873803A07F81; Granted Authorities: ROLE_ANONYMOUS' 12:03:23,312 DEBUG org.springframework.security.web.FilterChainProxy:318 - /j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer at position 10 of 12 in additional filter chain; firing Filter: 'SessionManagementFilter' 12:03:23,312 DEBUG org.springframework.security.web.FilterChainProxy:318 - /j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer at position 11 of 12 in additional filter chain; firing Filter: 'ExceptionTranslationFilter' 12:03:23,312 DEBUG org.springframework.security.web.FilterChainProxy:318 - /j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer at position 12 of 12 in additional filter chain; firing Filter: 'FilterSecurityInterceptor' 12:03:23,312 DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor:193 - Secure object: FilterInvocation: URL: /j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer; Attributes: [ROLE_USER] 12:03:23,312 DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor:298 - Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken@6fa86552: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffd148a: RemoteIpAddress: 127.0.0.1; SessionId: 659060E504E41E2F28CF873803A07F81; Granted Authorities: ROLE_ANONYMOUS 12:03:23,312 DEBUG org.springframework.security.access.vote.AffirmativeBased:65 - Voter: org.springframework.security.access.vote.RoleVoter@13e02ed, returned: -1 12:03:23,312 DEBUG org.springframework.security.access.vote.AffirmativeBased:65 - Voter: org.springframework.security.access.vote.AuthenticatedVoter@322394, returned: 0 12:03:23,312 DEBUG org.springframework.security.web.access.ExceptionTranslationFilter:165 - Access is denied (user is anonymous); redirecting to authentication entry point org.springframework.security.access.AccessDeniedException: Access is denied at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:83) at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:205) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:114) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:91) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594) at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675) at java.lang.Thread.run(Thread.java:662) 12:03:23,312 DEBUG org.springframework.security.web.savedrequest.HttpSessionRequestCache:41 - DefaultSavedRequest added to Session: DefaultSavedRequest[http://localhost:8080/Cas_Client/j_acegi_cas_security_check?ticket=ST-1-eOK4CG7zd7cApkahlva9-casServer] 12:03:23,312 DEBUG org.springframework.security.web.access.ExceptionTranslationFilter:185 - Calling Authentication entry point. 12:03:23,312 DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository:269 - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession. 12:03:23,343 DEBUG org.springframework.security.web.context.SecurityContextPersistenceFilter:97 - SecurityContextHolder now cleared, as request processing completed [/quote] [b]cas服务端配置:[/b] cas.properties [quote] #server.prefix=http://localhost:8080/cas #server.prefix=http://cas.wucht.com:8080/casServer server.prefix=http://localhost:8080/casServer cas.securityContext.serviceProperties.service=${server.prefix}/j_acegi_cas_security_check # Names of roles allowed to access the CAS service manager cas.securityContext.serviceProperties.adminRoles=ROLE_ADMIN cas.securityContext.casProcessingFilterEntryPoint.loginUrl=${server.prefix}/login cas.securityContext.ticketValidator.casServerUrlPrefix=${server.prefix} cas.themeResolver.defaultThemeName=cas-theme-default #cas.themeResolver.defaultThemeName=default cas.viewResolver.basename=default_views #host.name=cas host.name=casServer #database.hibernate.dialect=org.hibernate.dialect.OracleDialect database.hibernate.dialect=org.hibernate.dialect.MySQLDialect #database.hibernate.dialect=org.hibernate.dialect.HSQLDialect [/quote] deployerConfigContext.xml [quote] <?xml version="1.0" encoding="UTF-8"?> <!-- | deployerConfigContext.xml centralizes into one file some of the declarative configuration that | all CAS deployers will need to modify. | | This file declares some of the Spring-managed JavaBeans that make up a CAS deployment. | The beans declared in this file are instantiated at context initialization time by the Spring | ContextLoaderListener declared in web.xml. It finds this file because this | file is among those declared in the context parameter "contextConfigLocation". | | By far the most common change you will need to make in this file is to change the last bean | declaration to replace the default SimpleTestUsernamePasswordAuthenticationHandler with | one implementing your approach for authenticating usernames and passwords. +--> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:sec="http://www.springframework.org/schema/security" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> <!-- | This bean declares our AuthenticationManager. The CentralAuthenticationService service bean | declared in applicationContext.xml picks up this AuthenticationManager by reference to its id, | "authenticationManager". Most deployers will be able to use the default AuthenticationManager | implementation and so do not need to change the class of this bean. We include the whole | AuthenticationManager here in the userConfigContext.xml so that you can see the things you will | need to change in context. +--> <bean id="authenticationManager" class="org.jasig.cas.authentication.AuthenticationManagerImpl"> <!-- | This is the List of CredentialToPrincipalResolvers that identify what Principal is trying to authenticate. | The AuthenticationManagerImpl considers them in order, finding a CredentialToPrincipalResolver which | supports the presented credentials. | | AuthenticationManagerImpl uses these resolvers for two purposes. First, it uses them to identify the Principal | attempting to authenticate to CAS /login . In the default configuration, it is the DefaultCredentialsToPrincipalResolver | that fills this role. If you are using some other kind of credentials than UsernamePasswordCredentials, you will need to replace | DefaultCredentialsToPrincipalResolver with a CredentialsToPrincipalResolver that supports the credentials you are | using. | | Second, AuthenticationManagerImpl uses these resolvers to identify a service requesting a proxy granting ticket. | In the default configuration, it is the HttpBasedServiceCredentialsToPrincipalResolver that serves this purpose. | You will need to change this list if you are identifying services by something more or other than their callback URL. +--> <property name="credentialsToPrincipalResolvers"> <list> <!-- | UsernamePasswordCredentialsToPrincipalResolver supports the UsernamePasswordCredentials that we use for /login | by default and produces SimplePrincipal instances conveying the username from the credentials. | | If you've changed your LoginFormAction to use credentials other than UsernamePasswordCredentials then you will also | need to change this bean declaration (or add additional declarations) to declare a CredentialsToPrincipalResolver that supports the | Credentials you are using. +--> <bean class="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver"> <!--增加此属性,为认证过的用户的Principal添加属性--> <property name="attributeRepository" ref="attributeRepository"></property> </bean> <!-- | HttpBasedServiceCredentialsToPrincipalResolver supports HttpBasedCredentials. It supports the CAS 2.0 approach of | authenticating services by SSL callback, extracting the callback URL from the Credentials and representing it as a | SimpleService identified by that callback URL. | | If you are representing services by something more or other than an HTTPS URL whereat they are able to | receive a proxy callback, you will need to change this bean declaration (or add additional declarations). +--> <bean class="org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver" /> </list> </property> <!-- | Whereas CredentialsToPrincipalResolvers identify who it is some Credentials might authenticate, | AuthenticationHandlers actually authenticate credentials. Here we declare the AuthenticationHandlers that | authenticate the Principals that the CredentialsToPrincipalResolvers identified. CAS will try these handlers in turn | until it finds one that both supports the Credentials presented and succeeds in authenticating. +--> <property name="authenticationHandlers"> <list> <!-- | This is the authentication handler that authenticates services by means of callback via SSL, thereby validating | a server side SSL certificate. +--> <bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" p:httpClient-ref="httpClient" /> <!-- | This is the authentication handler declaration that every CAS deployer will need to change before deploying CAS | into production. The default SimpleTestUsernamePasswordAuthenticationHandler authenticates UsernamePasswordCredentials | where the username equals the password. You will need to replace this with an AuthenticationHandler that implements your | local authentication strategy. You might accomplish this by coding a new such handler and declaring | edu.someschool.its.cas.MySpecialHandler here, or you might use one of the handlers provided in the adaptors modules. +--> <!-- <bean class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" /> --> <!-- 数据库认证.wucht--> <bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler"> <property name="dataSource" ref="dataSource" /> <property name="sql" value="select password from users where name=?" /> </bean> </list> </property> </bean> <!-- DATABASE 增加数据源配置 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property> <property name="url"><value>jdbc:mysql://localhost:3306/mysql?useUnicode=true&amp;characterEncoding=utf-8</value></property> <property name="username"><value>root</value></property> <property name="password"><value>root</value></property> </bean> <!-- This bean defines the security roles for the Services Management application. Simple deployments can use the in-memory version. More robust deployments will want to use another option, such as the Jdbc version. The name of this should remain "userDetailsService" in order for Spring Security to find it. --> <!-- <sec:user name="@@THIS SHOULD BE REPLACED@@" password="notused" authorities="ROLE_ADMIN" />--> <sec:user-service id="userDetailsService"> <sec:user name="@@THIS SHOULD BE REPLACED@@" password="notused" authorities="ROLE_ADMIN" /> </sec:user-service> <!-- Bean that defines the attributes that a service may return. This example uses the Stub/Mock version. A real implementation may go against a database or LDAP server. The id should remain "attributeRepository" though. --> <!-- <bean id="attributeRepository" class="org.jasig.services.persondir.support.StubPersonAttributeDao"> <property name="backingMap"> <map> <entry key="uid" value="uid" /> <entry key="eduPersonAffiliation" value="eduPersonAffiliation" /> <entry key="groupMembership" value="groupMembership" /> </map> </property> </bean> --> <!-- 使用SingleRowJdbcPersonAttributeDao 获取更多用户的信息 --> <bean id="attributeRepository" class="org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao"> <constructor-arg index="0" ref="dataSource"/> <constructor-arg index="1" value="select role_name from role where login_name = ?"/> <!--这里的key需写username,value对应数据库用户名字段 --> <property name="queryAttributeMapping"> <map> <entry key="username" value="login_name"/> </map> </property> <!--key对应数据库字段,value对应客户端获取参数 --> <!-- 返回数据认证后的数据 --> <property name="resultAttributeMapping"> <map> <!--这个从数据库中获取的角色,用于在应用中security的权限验证--> <entry key="role_name" value="authorities"/> </map> </property> </bean> <!-- Sample, in-memory data store for the ServiceRegistry. A real implementation would probably want to replace this with the JPA-backed ServiceRegistry DAO The name of this bean should remain "serviceRegistryDao". --> <bean id="serviceRegistryDao" class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl"> <!-- <property name="registeredServices"> <list> <bean class="org.jasig.cas.services.RegisteredServiceImpl"> <property name="id" value="0" /> <property name="name" value="HTTP" /> <property name="description" value="Only Allows HTTP Urls" /> <property name="serviceId" value="http://**" /> <property name="evaluationOrder" value="10000001" /> </bean> <bean class="org.jasig.cas.services.RegisteredServiceImpl"> <property name="id" value="1" /> <property name="name" value="HTTPS" /> <property name="description" value="Only Allows HTTPS Urls" /> <property name="serviceId" value="https://**" /> <property name="evaluationOrder" value="10000002" /> </bean> <bean class="org.jasig.cas.services.RegisteredServiceImpl"> <property name="id" value="2" /> <property name="name" value="IMAPS" /> <property name="description" value="Only Allows HTTPS Urls" /> <property name="serviceId" value="imaps://**" /> <property name="evaluationOrder" value="10000003" /> </bean> <bean class="org.jasig.cas.services.RegisteredServiceImpl"> <property name="id" value="3" /> <property name="name" value="IMAP" /> <property name="description" value="Only Allows IMAP Urls" /> <property name="serviceId" value="imap://**" /> <property name="evaluationOrder" value="10000004" /> </bean> </list> </property> --> </bean> <bean id="auditTrailManager" class="com.github.inspektr.audit.support.Slf4jLoggingAuditTrailManager" /> </beans> [/quote] [b]spring的配置代码如下:[/b][code="ruby"] <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:beans="http://www.springframework.org/schema/beans" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd" default-lazy-init="true"> <!-- entry-point-ref="casEntryPoint"作用是认证的入口,是一个实现AuthenticationEntryPoint接口的类 ,为ExceptionTranslationFilter类提供认证依据, <custom-filter position="FORM_LOGIN_FILTER" ref="casFilter"/> 使用自定义的Filter,放置在过滤器链的FORM_LOGIN_FILTER的位置 casEntryPoint只是提供认证入口的作用,当没有权限,将跳转到该地址。 casFilter是处理CAS service ticket的,当无权访问时,会使用casEntryPoint提供认证入口 --> <http auto-config="true" entry-point-ref="casEntryPoint" access-denied-page="/403.jsp"> <intercept-url pattern="/**" access="ROLE_USER" /> <!-- ROLE_ADMIN--> <!-- logout-success-url="/login.html" --> <!-- 注销时需要先注销应用程序,再注销cas中心认证服务 --> <logout logout-url="/logout.html" success-handler-ref="casLogoutSuccessHandler" /> <custom-filter position="CAS_FILTER" ref="casFilter" /> </http> <authentication-manager alias="authenticationManager"> <authentication-provider ref="casAuthenticationProvider" /> </authentication-manager> <!-- cas中心认证服务入口 --> <beans:bean id="casEntryPoint" class="org.springframework.security.cas.web.CasAuthenticationEntryPoint"> <beans:property name="loginUrl" value="http://localhost:8080/casServer/login" /> <beans:property name="serviceProperties" ref="serviceProperties" /> </beans:bean> <!-- cas中心认证服务配置 --> <beans:bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties"> <beans:property name="service" value="http://localhost:8080/Cas_Client/j_acegi_cas_security_check" /> <beans:property name="sendRenew" value="false" /> </beans:bean> <!-- CAS service ticket(中心认证服务凭据)验证 --> <beans:bean id="casFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter"> <beans:property name="authenticationManager" ref="authenticationManager" /> <!-- <beans:property name="authenticationFailureHandler">--> <!-- <beans:bean--> <!-- class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">--> <!-- <beans:property name="defaultFailureUrl"--> <!-- value="/logout.html" />--> <!-- </beans:bean>--> <!-- </beans:property>--> <!-- 登录成功后的页面,如果是固定的。否则 ref="authenticationSuccessHandler" --> <!-- <beans:property name="authenticationSuccessHandler">--> <!-- <beans:bean--> <!-- class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler">--> <!-- <beans:property name="defaultTargetUrl"--> <!-- value="/index.jsp" />--> <!-- </beans:bean>--> <!-- </beans:property>--> </beans:bean> <!-- 从Cas Server得到用户信息 --> <beans:bean id="authenticationUserDetailsService" class="org.springframework.security.cas.userdetails.GrantedAuthorityFromAssertionAttributesUserDetailsService"> <beans:constructor-arg> <beans:array> <beans:value>authorities</beans:value> </beans:array> </beans:constructor-arg> </beans:bean> <beans:bean id="userDetailsService" class="com.reportstart.security.service.impl.BocUserDetaislServiceImpl"> <!-- <beans:property name="userDao">--> <!-- <beans:ref bean="userDao" />--> <!-- </beans:property>--> </beans:bean> <!-- <beans:bean id="authenticationUserDetailsService"--> <!-- class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">--> <!-- <beans:property name="userDetailsService">--> <!-- <beans:ref local="userDetailsService" />--> <!-- </beans:property>--> <!-- </beans:bean>--> <beans:bean id="casAuthenticationProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider"> <!-- 使用自定义service获取用户信息 --> <!-- <beans:property name="authenticationUserDetailsService"--> <!-- ref="casAuthenticationUserDetailsService" />--> <!-- 通过Cas Server获取用户信息 --> <beans:property name="authenticationUserDetailsService" ref="authenticationUserDetailsService" /> <beans:property name="serviceProperties" ref="serviceProperties" /> <beans:property name="ticketValidator"> <beans:bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator"> <beans:constructor-arg index="0" value="http://localhost:8080/casServer" /> </beans:bean> </beans:property> <!-- 自定义cas客户端应用标示.wucht.2012-6-4(每个cas客户端都需要一个key标示用于区分不同cas客户端) --> <beans:property name="key" value="Cas_Client" /> </beans:bean> <!-- 注销 --> <beans:bean id="casLogoutSuccessHandler" class="com.wucht.test.CasLogoutSuccessHandler"> </beans:bean> </beans:beans>[/code]

程序员的兼职技能课

程序员的兼职技能课

为linux系统设计一个简单的二级文件系统

实验目的: 通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现。 实验要求: 为linux系统设计一个简单的二级文件系统。要求做到以下几点: (1)可以实现下列几条命令(至少4条)

CCNA+HCNA+wireshark抓包综合网工技能提升套餐

本套餐包含思科路由交换CCNA,部分CCNP核心,华为HCNA以及wireshark抓包等类容,旨在培养具有综合能力的网络工程师。

董付国老师Python全栈学习优惠套餐

购买套餐的朋友可以关注微信公众号“Python小屋”,上传付款截图,然后领取董老师任意图书1本。

成年人用得到的6款资源网站!各个都是宝藏,绝对让你大饱眼福!

不管是学习还是工作,我们都需要一些资源帮助我们有效地解决实际问题。 很多人找资源只知道上百度,但是你们知道吗,有的资源是百度也搜索不出来的,那么今天小编就给大家介绍几款好用的资源网站,大家赶紧收入囊中吧! 1.网盘007 https://wangpan007.com/ 一款全能的资源搜索网站!只需要输入关键字,就能获得你想要的视频、音乐、压缩包等各种资源,网上...

矿车轴载荷计算方法的比较及选用

针对矿车轴的弯曲损坏,分析了固定式矿车车轴的受力,并对力叠加法以及当量负荷法2种计算方法进行了分析和比较,认为应采用当量负荷法进行车轴的设计计算。

Python数据清洗实战入门

Python数据清洗实战入门

C/C++跨平台研发从基础到高阶实战系列套餐

一 专题从基础的C语言核心到c++ 和stl完成基础强化; 二 再到数据结构,设计模式完成专业计算机技能强化; 三 通过跨平台网络编程,linux编程,qt界面编程,mfc编程,windows编程,c++与lua联合编程来完成应用强化 四 最后通过基于ffmpeg的音视频播放器,直播推流,屏幕录像,

Polar编码matlab程序

matlab实现的Polar codes源程序

2019全国大学生数学建模竞赛C题原版优秀论文

2019全国大学生数学建模竞赛C题原版优秀论文,PDF原版论文,不是图片合成的,是可编辑的文字版。共三篇。 C044.pdf C137.pdf C308.pdf

Linux常用命令大全(非常全!!!)

Linux常用命令大全(非常全!!!) 最近都在和Linux打交道,感觉还不错。我觉得Linux相比windows比较麻烦的就是很多东西都要用命令来控制,当然,这也是很多人喜欢linux的原因,比较短小但却功能强大。我将我了解到的命令列举一下,仅供大家参考: 系统信息 arch 显示机器的处理器架构 uname -m 显示机器的处理器架构 uname -r 显示正在使用的内核版本 d...

Linux下聊天室实现(基于C)

在linux下的基于TCP/IP,采用socket通信的聊天室,实现进入聊天室,进行多人群聊,指定人进行私聊,群主管理员功能,颗进行禁言,提出群聊等操作。个人账号可修改昵称或者修改密码,还可进行找回密

一个较完整的Qt用户登录界面设计

一个较完整的Qt用户登录界面,稍微移植可用,用sqlite数据库存储用户名和密码,具有增加和删除用户的功能,开发环境为ubuntu16.04+Qt5.6.1,win7下程序也编译可用。贡献出来,共同学

机器学习初学者必会的案例精讲

机器学习初学者必会的案例精讲

【C语言】贪吃蛇游戏代码(Visual C++6.0实现)

本游戏代码参考《C语言项目开发全程实录(第二版)》第六章。代码已在Visual C++6.0环境下编译测试通过,可在VC++6.0编译器中导入工程编译运行查看效果,或者也可以直接运行Release或D

Android小项目——新闻APP(源码)

Android小项目——新闻APP(源码),一个很简单的可以练手的Android Demo Ps:下载之前可以先看一下这篇文章——https://blog.csdn.net/qq_34149526/a

网络工程师小白入门--【思科CCNA、华为HCNA等网络工程师认证】

网络工程师小白入门--【思科CCNA、华为HCNA等网络工程师认证】

Android音视频开发全套

Android平台音视频开发全套,涉及:FFmpeg软解码解码、Mediacodec硬解码编码、Openssl音频播放、OpenGL ES视频渲染、RTMP推流等核心重要知识点。

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

2019 Python开发者日-培训

2019 Python开发者日-培训

2019 AI开发者大会

2019 AI开发者大会

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

4小时玩转微信小程序——基础入门与微信支付实战

4小时玩转微信小程序——基础入门与微信支付实战

因为看了这些书,我大二就拿了华为Offer

四年了,四年,你知道大学这四年我怎么过的么?

Python可以这样学(第四季:数据分析与科学计算可视化)

Python可以这样学(第四季:数据分析与科学计算可视化)

我说我不会算法,阿里把我挂了。

不说了,字节跳动也反手把我挂了。

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

YOLOv3目标检测实战系列课程

《YOLOv3目标检测实战系列课程》旨在帮助大家掌握YOLOv3目标检测的训练、原理、源码与网络模型改进方法。 本课程的YOLOv3使用原作darknet(c语言编写),在Ubuntu系统上做项目演示。 本系列课程包括三门课: (1)《YOLOv3目标检测实战:训练自己的数据集》 包括:安装darknet、给自己的数据集打标签、整理自己的数据集、修改配置文件、训练自己的数据集、测试训练出的网络模型、性能统计(mAP计算和画出PR曲线)和先验框聚类。 (2)《YOLOv3目标检测:原理与源码解析》讲解YOLOv1、YOLOv2、YOLOv3的原理、程序流程并解析各层的源码。 (3)《YOLOv3目标检测:网络模型改进方法》讲解YOLOv3的改进方法,包括改进1:不显示指定类别目标的方法 (增加功能) ;改进2:合并BN层到卷积层 (加快推理速度) ; 改进3:使用GIoU指标和损失函数 (提高检测精度) ;改进4:tiny YOLOv3 (简化网络模型)并介绍 AlexeyAB/darknet项目。

DirectX修复工具V4.0增强版

DirectX修复工具(DirectX Repair)是一款系统级工具软件,简便易用。本程序为绿色版,无需安装,可直接运行。 本程序的主要功能是检测当前系统的DirectX状态,如果发现异常则进行修复

C++语言基础视频教程

C++语言基础视频教程

相关热词 c#跨线程停止timer c#批量写入sql数据库 c# 自动安装浏览器 c#语言基础考试题 c# 偏移量打印是什么 c# 绘制曲线图 c#框体中的退出函数 c# 按钮透明背景 c# idl 混编出错 c#在位置0处没有任何行
立即提问