解决方案 »

  1.   

    Java 技术交流群!入群先看公约!本群公约:互助、互勉、共同进步!惑则问、知则答、不知则表示关注。帮助新手、细心回答。 
    同意上述公约者·申请加入!  
    QQ群号:25922618(一群)-----人员快满
    QQ群号:17615698(二群)-----最近新群
      

  2.   

    在页面截取字符串
    <%
    String   s   =   RS.getString("title");    
      if   (s.length()>12)    
      {    
      s   =   s.subString(0,12)+"...";    
      } %>
    然后在你想输出的地方输出s不就可以了吗?比如在一个td中输出:<td><%=s%></td>不知道楼主问的是这个意思不
      

  3.   

    1.RS.getString("title");  其中的“title”是字符串吗?
    2.String  s中的“s”是在页面截取的字符串吗?
      

  4.   

    对title是你ResultSet数据库的字段名.s就是你需要的东西了
                                  -------助人为快乐之本
      

  5.   

    ...不是吧楼主 你连这么基本的代码都看不懂? 那我换个方式给你写 在不懂 我也无语了
    <% 
    String str="这是原有的字符传";String s="";
      if   (str.length()>4)     
      {     
      s   =   str.subString(0,4)+"...";   //s是截取后的字符串  
      }  %> 
    <td> <%=s%> </td> //输出S 显示的结果应该是“这是原有”这几个字。
      

  6.   

    补充下<td>  <%=s%>  </td> //输出S 显示的结果应该是“这是原有...”这几个字。
      

  7.   


    /**
     * 截取子串加"..."
     * @param str   原字符串
     * @param size  截取大小
     * @return      截取后的字串
     */
    public static String getSub(String str,int size){
       if(str == null || str.equals("")) return " ";
       if(str.length()>size) str = str.substring(0,size) + "...";
       return str;
    }
      

  8.   

    真是惭愧!我没有jsp基础,我平时只负责页面设计的,平时数据库方面都交给程序员的。现在想自学下,难度好大啊!
    我现在把代码发给你们,我是用CSS做的可能对浏览器支持方面会有问题。现在请你们看看用JSP如何控制,我现在只想控制“title”字段。我是不会编程,是用DREAMWEAVER做的,大家帮帮我吧。
      

  9.   

    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <% request.setCharacterEncoding("gb2312"); %>
    <%@ include file="Connections/newtest.jsp" %>
    <%
    Driver Drivernewlist = (Driver)Class.forName(MM_newtest_DRIVER).newInstance();
    Connection Connnewlist = DriverManager.getConnection(MM_newtest_STRING,MM_newtest_USERNAME,MM_newtest_PASSWORD);
    PreparedStatement Statementnewlist = Connnewlist.prepareStatement("SELECT * FROM newtest.newlist ORDER BY id DESC");
    ResultSet newlist = Statementnewlist.executeQuery();
    boolean newlist_isEmpty = !newlist.next();
    boolean newlist_hasData = !newlist_isEmpty;
    Object newlist_data;
    int newlist_numRows = 0;
    %>
    <%
    // *** Recordset Stats, Move To Record, and Go To Record: declare stats variablesint newlist_first = 1;
    int newlist_last  = 1;
    int newlist_total = -1;if (newlist_isEmpty) {
      newlist_total = newlist_first = newlist_last = 0;
    }//set the number of rows displayed on this page
    if (newlist_numRows == 0) {
      newlist_numRows = 1;
    }
    %>
    <%
    // *** Recordset Stats: if we don't know the record count, manually count themif (newlist_total == -1) {  // count the total records by iterating through the recordset
        for (newlist_total = 1; newlist.next(); newlist_total++);  // reset the cursor to the beginning
      newlist.close();
      newlist = Statementnewlist.executeQuery();
      newlist_hasData = newlist.next();  // set the number of rows displayed on this page
      if (newlist_numRows < 0 || newlist_numRows > newlist_total) {
        newlist_numRows = newlist_total;
      }  // set the first and last displayed record
      newlist_first = Math.min(newlist_first, newlist_total);
      newlist_last  = Math.min(newlist_first + newlist_numRows - 1, newlist_total);
    }
    %>
    <%
    // *** Move To Record and Go To Record: declare variablesResultSet MM_rs = newlist;
    int       MM_rsCount = newlist_total;
    int       MM_size = newlist_numRows;
    String    MM_uniqueCol = "";
              MM_paramName = "";
    int       MM_offset = 0;
    boolean   MM_atTotal = false;
    boolean   MM_paramIsDefined = (MM_paramName.length() != 0 && request.getParameter(MM_paramName) != null);
    %>
    <%
    // *** Move To Record: handle 'index' or 'offset' parameterif (!MM_paramIsDefined && MM_rsCount != 0) {  //use index parameter if defined, otherwise use offset parameter
      String r = request.getParameter("index");
      if (r==null) r = request.getParameter("offset");
      if (r!=null) MM_offset = Integer.parseInt(r);  // if we have a record count, check if we are past the end of the recordset
      if (MM_rsCount != -1) {
        if (MM_offset >= MM_rsCount || MM_offset == -1) {  // past end or move last
          if (MM_rsCount % MM_size != 0)    // last page not a full repeat region
            MM_offset = MM_rsCount - MM_rsCount % MM_size;
          else
            MM_offset = MM_rsCount - MM_size;
        }
      }  //move the cursor to the selected record
      int i;
      for (i=0; newlist_hasData && (i < MM_offset || MM_offset == -1); i++) {
        newlist_hasData = MM_rs.next();
      }
      if (!newlist_hasData) MM_offset = i;  // set MM_offset to the last possible record
    }
    %>
    <%
    // *** Move To Record: if we dont know the record count, check the display rangeif (MM_rsCount == -1) {  // walk to the end of the display range for this page
      int i;
      for (i=MM_offset; newlist_hasData && (MM_size < 0 || i < MM_offset + MM_size); i++) {
        newlist_hasData = MM_rs.next();
      }  // if we walked off the end of the recordset, set MM_rsCount and MM_size
      if (!newlist_hasData) {
        MM_rsCount = i;
        if (MM_size < 0 || MM_size > MM_rsCount) MM_size = MM_rsCount;
      }  // if we walked off the end, set the offset based on page size
      if (!newlist_hasData && !MM_paramIsDefined) {
        if (MM_offset > MM_rsCount - MM_size || MM_offset == -1) { //check if past end or last
          if (MM_rsCount % MM_size != 0)  //last page has less records than MM_size
            MM_offset = MM_rsCount - MM_rsCount % MM_size;
          else
            MM_offset = MM_rsCount - MM_size;
        }
      }  // reset the cursor to the beginning
      newlist.close();
      newlist = Statementnewlist.executeQuery();
      newlist_hasData = newlist.next();
      MM_rs = newlist;  // move the cursor to the selected record
      for (i=0; newlist_hasData && i < MM_offset; i++) {
        newlist_hasData = MM_rs.next();
      }
    }
    %>
    <%
    // *** Move To Record: update recordset stats// set the first and last displayed record
    newlist_first = MM_offset + 1;
    newlist_last  = MM_offset + MM_size;
    if (MM_rsCount != -1) {
      newlist_first = Math.min(newlist_first, MM_rsCount);
      newlist_last  = Math.min(newlist_last, MM_rsCount);
    }// set the boolean used by hide region to check if we are on the last record
    MM_atTotal  = (MM_rsCount != -1 && MM_offset + MM_size >= MM_rsCount);
    %>
    <%
    // *** Move To Record: set the strings for the first, last, next, and previous linksString MM_moveFirst,MM_moveLast,MM_moveNext,MM_movePrev;
    {
      String MM_keepMove = MM_keepBoth;  // keep both Form and URL parameters for moves
      String MM_moveParam = "index=";  // if the page has a repeated region, remove 'offset' from the maintained parameters
      if (MM_size > 1) {
        MM_moveParam = "offset=";
        int start = MM_keepMove.indexOf(MM_moveParam);
        if (start != -1 && (start == 0 || MM_keepMove.charAt(start-1) == '&')) {
          int stop = MM_keepMove.indexOf('&', start);
          if (start == 0 && stop != -1) stop++;
          if (stop == -1) stop = MM_keepMove.length();
          if (start > 0) start--;
          MM_keepMove = MM_keepMove.substring(0,start) + MM_keepMove.substring(stop);
        }
      }  // set the strings for the move to links
      StringBuffer urlStr = new StringBuffer(request.getRequestURI()).append('?').append(MM_keepMove);
      if (MM_keepMove.length() > 0) urlStr.append('&');
      urlStr.append(MM_moveParam);
      MM_moveFirst = urlStr + "0";
      MM_moveLast  = urlStr + "-1";
      MM_moveNext  = urlStr + Integer.toString(MM_offset+MM_size);
      MM_movePrev  = urlStr + Integer.toString(Math.max(MM_offset-MM_size,0));
    }
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>列表</title>
    <link href="css.css" rel="stylesheet" type="text/css" />
    </head><body> <table width="222" border="0" cellpadding="2" cellspacing="1" bgcolor="#666666" class="ctl">
       <tr>
         <td width="216" height="20" align="center" bgcolor="#E8E8E8">标题</td>
       </tr>
       <tr>
         <td align="left" bgcolor="#FFFFFF">·<%=(((newlist_data = newlist.getObject("title"))==null || newlist.wasNull())?"":newlist_data)%></td>
       </tr>
     </table>
    </body>
    </html>
    <%
    newlist.close();
    Statementnewlist.close();
    Connnewlist.close();
    %>
      

  10.   

    重新发,上一个太繁琐。
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <% request.setCharacterEncoding("gb2312"); %>
    <%@ include file="Connections/newtest.jsp" %>
    <%
    Driver DriverRecordset1 = (Driver)Class.forName(MM_newtest_DRIVER).newInstance();
    Connection ConnRecordset1 = DriverManager.getConnection(MM_newtest_STRING,MM_newtest_USERNAME,MM_newtest_PASSWORD);
    PreparedStatement StatementRecordset1 = ConnRecordset1.prepareStatement("SELECT * FROM newtest.newlist ORDER BY id DESC");
    ResultSet Recordset1 = StatementRecordset1.executeQuery();
    boolean Recordset1_isEmpty = !Recordset1.next();
    boolean Recordset1_hasData = !Recordset1_isEmpty;
    Object Recordset1_data;
    int Recordset1_numRows = 0;
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>列表</title>
    <link href="css.css" rel="stylesheet" type="text/css" />
    </head><body> <table width="222" border="0" cellpadding="2" cellspacing="1" bgcolor="#666666" class="ctl">
       <tr>
         <td width="216" height="20" align="center" bgcolor="#E8E8E8">标题</td>
       </tr>
       <tr>
         <td align="left" bgcolor="#FFFFFF">·<%=(((Recordset1_data = Recordset1.getObject("title"))==null || Recordset1.wasNull())?"":Recordset1_data)%></td>
       </tr>
     </table>
    </body>
    </html>
    <%
    Recordset1.close();
    StatementRecordset1.close();
    ConnRecordset1.close();
    %>
      

  11.   

    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <% request.setCharacterEncoding("gb2312"); %>
    <%@ include file="Connections/newtest.jsp" %>
    <%
    Driver DriverRecordset1 = (Driver)Class.forName(MM_newtest_DRIVER).newInstance();
    Connection ConnRecordset1 = DriverManager.getConnection(MM_newtest_STRING,MM_newtest_USERNAME,MM_newtest_PASSWORD);
    PreparedStatement StatementRecordset1 = ConnRecordset1.prepareStatement("SELECT * FROM newtest.newlist ORDER BY id DESC");
    ResultSet Recordset1 = StatementRecordset1.executeQuery();
    boolean Recordset1_isEmpty = !Recordset1.next();
    boolean Recordset1_hasData = !Recordset1_isEmpty;
    Object Recordset1_data;
    int Recordset1_numRows = 0;
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>列表</title>
    <link href="css.css" rel="stylesheet" type="text/css" />
    </head><body> <table width="222" border="0" cellpadding="2" cellspacing="1" bgcolor="#666666" class="ctl">
       <tr>
         <td width="216" height="20" align="center" bgcolor="#E8E8E8">标题</td>
       </tr>
       <tr>
         <td align="left" bgcolor="#FFFFFF">·<%=(((Recordset1_data = Recordset1.getObject("title"))==null || Recordset1.wasNull())?"":Recordset1_data)%></td>
       </tr>
     </table>
    </body>
    </html>
    <%
    Recordset1.close();
    StatementRecordset1.close();
    ConnRecordset1.close();
    %>
      

  12.   

    <%=(((Recordset1_data = Recordset1.getObject("title"))==null || Recordset1.wasNull())?"":Recordset1_data)%>不知道怎么限制它的字数。
      

  13.   

    用VB语言,怎样在GridView1中绑定数据后,让字数过长的字用省略号代替?
      

  14.   

    写个自定义的JSP标签不就成了,在JSP页面上写java代码,可读性差
      

  15.   

    其实超级简单 用jstl标签  引入
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
    ${fn:substring(list.content, 0, 10)}...   比如 2012-06-15 01:01:01 这样显示的就是
    2012-06-15...  list.content是我的变量 随便改个字符串 - -