怎么读出数据库里面的空格和回车? 存进去就有回车和空格的读到text框中不需要转换读到页面需要转换..... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我给你个例子片断看看吧<%@ page contentType="text/html; charset=GBK" %><%@ page import="com.action.*,com.obj.*,com.tools.*"%><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <title>人才招聘</title><link rel="stylesheet" href="images/style1.css" type="text/css"> <SCRIPT LANGUAGE="JavaScript"> //<!-- function onlynumber(str)//判断是否只是数字 { var i,strlength,tempchar; strlength=str.length; for(i=0;i<strlength;i++) { tempchar=str.substring(i,i+1); if(!(tempchar==0||tempchar==1||tempchar==2||tempchar==3||tempchar==4 ||tempchar==5||tempchar==6||tempchar==7||tempchar==8||tempchar==9)) { alert('只能输入数字'); str="1"; break; } } return str; } //--></SCRIPT> </head> <body bgcolor="#eeeeee"> <div align="center"> <center> <table width="716" height="541" bgcolor="#FFFFFF"> <jsp:useBean id="table" scope="page" class="com.action.ListJob"/> <% Job[] job=table.getJobs(pageContext) ; int total=0;//当前页面有多少条记录 int currPage=table.getCurPage() ;//当前页码 int pageCount=table.getPageCount() ;//总页数 int rCount=table.getRowCount() ;//总行数 if(job!=null) { total=job.length ; } %> <td height="496"> <table> <tr> <td width="550"><font color="#cc6600" size="3"><b>人才招聘________________________</b> </font> </td> </tr> <tr> <td width="550"> </td> </tr> <tr> <td width="550"><b>本公司招聘以下人员</b>: <p> </td> </tr> </table> <% for(int i=0;i<total ;i++) { Job current=job[i]; %> <table border="0" width="73%" cellpadding="2" cellspacing="4"> <tr> <%//留言板换行处理 String text=current.getNeeds() ;//从数据库中提出来的数据 int index=text.indexOf("\r\n") ; while(index!=-1) { text=text.substring(0,index)+"<br>"+text.substring(index+2); index=text.indexOf("\r\n") ; } %> <td width="65%"><%=4*currPage-3+i%> </td> </tr> <td width="35%" align="center">招聘职位: </td> <td width="65%"><%=current.getJob()%> </td> </tr> <tr> <td width="35%" align="center">招聘人数: </td> <td width="65%"><%=current.getNumber()%>人 </td> </tr> <tr> <td width="35%" align="center">其体要求: </td> <td width="65%"><%=text%> </td> </tr> </table> <font color="#cc6600">---------------------------------------------------------------------------------------</font> <% } %> <% if(job!=null) { %> <form name="PageForm" action="rencai.jsp" onSubmit="return testform(this)"> <div align="center">共<%=rCount%>条 共<%=pageCount%>页 第<%=currPage%>页 <% if(currPage>1) { %> <a href="rencai.jsp?page=1">首页</a> <% } %> <% if(currPage>1) { %> <a href="rencai.jsp?page=<%=currPage-1%>">上一页</a> <% } %> <% if(currPage<pageCount) { %> <a href="rencai.jsp?page=<%=currPage+1%>">下一页</a> <% } %> <% if(currPage<pageCount) { %> <a href="rencai.jsp?page=<%=pageCount%>">尾页</a> <% } %> 跳到 <input type="text" name="page" size="4" style="font-size:9px" onBlur="this.value=onlynumber(this.value);" value=1> 页 <input type="submit" name="submit" size="4" value="GO" style="font-size:12px"> </div> </form> <% } %> <tr> <td height="37"> <jsp:include page="copyright.jsp"/> </tr> </table> </center> </div></body></html> 给你一个转换的JavaBean:package com.chenyue.html;public class HtmlEncode{ String re; //用指定的字符串替换字符串中某个字符的方法 public String replace(String con,String tag,String rep){ int j=0; int i=0; int k=0; String RETU=""; String temp=con; int tagc=tag.length(); while(i<con.length()){ if(con.substring(i).startsWith(tag)){ temp=con.substring(j,i)+rep; RETU+=temp; i+=tagc; j=i; } else i+=1; } RETU+=con.substring(j); return RETU; } //对字符串进行编码的方法 public String HtmlEncode(String s){ re=replace(s,"<","<"); re=replace(re,">",">"); re=replace(re,"\n","<br>"); re=replace(re," "," "); //re=replace(re,"'","'"); return re; }} 你直接在页面加入<pre>XXX-->要显示的内容</per>你可以这样试试,昨天也有人问这样的问题,好象他已经这样给解决了,希望能给你帮助,^_^! 关于远程访问oracle10g的问题 崩溃的strtuts开发jsp中插入图像!高分求解! MySQL批量更新问题求解 TEXTAREA中<BR>不能换行,只会打印出来。怎么办? JSP从sql数据库中读取的值是乱码 獲取同一頁面的表單參數 急,50分相送:BBS不同注册用户的权限问题,请高手指教啊! 构建jsp开发环境是什么 我是根据下面的步骤一步一步做的,怎么还是连不上服务器啊 请问有没有Crystal Report for Java版,在哪里下载? 一个<html:form>的问题??? 怎样判断会员是离线了,或下线了?
<%@ page import="com.action.*,com.obj.*,com.tools.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>人才招聘</title>
<link rel="stylesheet" href="images/style1.css" type="text/css">
<SCRIPT LANGUAGE="JavaScript">
//<!--
function onlynumber(str)//判断是否只是数字
{
var i,strlength,tempchar;
strlength=str.length;
for(i=0;i<strlength;i++)
{
tempchar=str.substring(i,i+1);
if(!(tempchar==0||tempchar==1||tempchar==2||tempchar==3||tempchar==4
||tempchar==5||tempchar==6||tempchar==7||tempchar==8||tempchar==9))
{
alert('只能输入数字');
str="1";
break;
}
}
return str;
}
//-->
</SCRIPT>
</head>
<body bgcolor="#eeeeee">
<div align="center">
<center>
<table width="716" height="541" bgcolor="#FFFFFF">
<jsp:useBean id="table" scope="page" class="com.action.ListJob"/>
<%
Job[] job=table.getJobs(pageContext) ;
int total=0;//当前页面有多少条记录
int currPage=table.getCurPage() ;//当前页码
int pageCount=table.getPageCount() ;//总页数
int rCount=table.getRowCount() ;//总行数
if(job!=null)
{
total=job.length ;
}
%>
<td height="496">
<table>
<tr>
<td width="550"><font color="#cc6600" size="3"><b>人才招聘________________________</b>
</font>
</td>
</tr>
<tr>
<td width="550">
</td>
</tr>
<tr>
<td width="550"><b>本公司招聘以下人员</b>: <p>
</td>
</tr>
</table>
<%
for(int i=0;i<total ;i++)
{
Job current=job[i];
%>
<table border="0" width="73%" cellpadding="2" cellspacing="4">
<tr>
<%//留言板换行处理
String text=current.getNeeds() ;//从数据库中提出来的数据
int index=text.indexOf("\r\n") ;
while(index!=-1)
{
text=text.substring(0,index)+"<br>"+text.substring(index+2);
index=text.indexOf("\r\n") ;
}
%>
<td width="65%"><%=4*currPage-3+i%>
</td>
</tr>
<td width="35%" align="center">招聘职位:
</td>
<td width="65%"><%=current.getJob()%>
</td>
</tr>
<tr>
<td width="35%" align="center">招聘人数:
</td>
<td width="65%"><%=current.getNumber()%>人
</td>
</tr>
<tr>
<td width="35%" align="center">其体要求:
</td>
<td width="65%"><%=text%>
</td>
</tr>
</table>
<font color="#cc6600">---------------------------------------------------------------------------------------</font>
<%
}
%>
<%
if(job!=null)
{
%>
<form name="PageForm" action="rencai.jsp" onSubmit="return testform(this)">
<div align="center">共<%=rCount%>条 共<%=pageCount%>页 第<%=currPage%>页
<%
if(currPage>1)
{
%>
<a href="rencai.jsp?page=1">首页</a>
<%
}
%>
<%
if(currPage>1)
{
%>
<a href="rencai.jsp?page=<%=currPage-1%>">上一页</a>
<%
}
%>
<%
if(currPage<pageCount)
{
%>
<a href="rencai.jsp?page=<%=currPage+1%>">下一页</a>
<%
}
%>
<%
if(currPage<pageCount)
{
%>
<a href="rencai.jsp?page=<%=pageCount%>">尾页</a>
<%
}
%> 跳到
<input type="text" name="page" size="4" style="font-size:9px" onBlur="this.value=onlynumber(this.value);" value=1>
页
<input type="submit" name="submit" size="4" value="GO" style="font-size:12px">
</div>
</form>
<%
}
%>
<tr>
<td height="37">
<jsp:include page="copyright.jsp"/>
</tr>
</table>
</center>
</div>
</body>
</html>
package com.chenyue.html;
public class HtmlEncode{
String re;
//用指定的字符串替换字符串中某个字符的方法
public String replace(String con,String tag,String rep){
int j=0;
int i=0;
int k=0;
String RETU="";
String temp=con;
int tagc=tag.length();
while(i<con.length()){
if(con.substring(i).startsWith(tag)){
temp=con.substring(j,i)+rep;
RETU+=temp;
i+=tagc;
j=i;
}
else
i+=1;
}
RETU+=con.substring(j);
return RETU;
}
//对字符串进行编码的方法
public String HtmlEncode(String s){
re=replace(s,"<","<");
re=replace(re,">",">");
re=replace(re,"\n","<br>");
re=replace(re," "," ");
//re=replace(re,"'","'");
return re;
}
}
<pre>
XXX-->要显示的内容
</per>
你可以这样试试,昨天也有人问这样的问题,好象他已经这样给解决了,希望能给你帮助,^_^!