首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

jsp textarea的换行字符怎么转换

2012-05-15 
jsp textarea的换行字符如何转换form namemyform methodpost actionreply.jsptable width10

jsp textarea的换行字符如何转换
<form name="myform" method="post" action="reply.jsp">

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
  <tr height="20" valign="middle">
  <td>&nbsp;快速回复主题
  </td>
  <td>
<input type="text" name="username" maxlength="500" height="100" size="100"/>
</td>
  </tr>
  <tr>
  <td width="20%" align="center" valign="middle">
  </td>
  <td width="80%">
  <textarea name="rtext" style="width:98%" rows="3"></textarea>
  </td>
  </tr>
  <tr>
  <td>&nbsp;</td>
  <td><input name="Submit" type="submit" value="回复主题 &gt;&gt;&gt;">  
  &nbsp;&nbsp;
  <input name="Submit2" type="reset" value="重 置"></td></tr>
</table>

</form>

<%



if(session.getAttribute("user name")!=null)
{
String userid=session.getAttribute("user name").toString();
String reply_content=request.getParameter("rtext");

String recont=re.toHTMLString(reply_content);
//String reply_content=workFC.UnitoGB(request.getParameter("rtext"));


String replycontent=workFC.UnitoGB(recont);


re.setUserID(userid);
re.setTopicid(topicid);


re.setReplycontent(replycontent);


re.doReply();

}




%>
<%=re.getReplycontent()%>


</body>
</html>


java代码如下

package com.ice.test;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Date;

public class Reply {

/**
* @param args
*/
private String topicid,replycontent,userID;
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
public Reply(){

}

public static String toHTMLString(String in) {  
  StringBuffer out = new StringBuffer();  
  for (int i = 0; in != null && i < in.length(); i++) {  
  char c = in.charAt(i);  
  if (c == '\'')  
  out.append("&#039;");  
  else if (c == '\"')  
  out.append("&#034;");  
  else if (c == '<')  
  out.append("&lt;");  
  else if (c == '>')  
  out.append("&gt;");  
  else if (c == '&')  
  out.append("&amp;");  
  else if (c == ' ')  
  out.append("&nbsp;");  
  else if (c == '\n')  
  out.append("<br/>");  
  else  
  out.append(c);  
  }  
  return out.toString();  
}  

public boolean doReply(){


java.util.Date dt=new java.util.Date();
 
int year=dt.getYear();
year+=1900;

int month=dt.getMonth();
month+=1;

int date=dt.getDate();
int hour=dt.getHours();
int minute=dt.getMinutes();
int second=dt.getSeconds(); 
String str_begin="It is";
String str_end="now!";
 
String str_year=String.valueOf(year);
String str_month=String.valueOf(month);
 
String str_date=String.valueOf(date);
String str_hour=String.valueOf(hour);
String str_minute=String.valueOf(minute);
String str_second=String.valueOf(second);
 
 
String chi_dt=str_year+"-"+str_month+"-"+str_date+" "+str_hour+":"+str_minute+":"+str_second;

try{
 



Class.forName("org.gjt.mm.mysql.Driver").newInstance();  
String url ="jdbc:mysql://localhost/hello?user=root&password=123456&useUnicode=true&characterEncoding=gb2312";
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
con=DriverManager.getConnection(url);
stmt=con.createStatement();
 
System.out.print("a");
String insert="insert into replyinfo(topicid,replyuserid,replycontent,replytime) values('"+topicid+"','"+userID+"','"+replycontent+"','"+chi_dt+"')";
System.out.print("b");
stmt.executeUpdate(insert);
 
return true;

 
 
 
 
}


catch (Exception e) {
// TODO Auto-generated catch block
System.err.println(e.getMessage());
System.err.println("fail");
return false;
}
finally{
try{
if(stmt!=null){
stmt.close();
}
if(con!=null){
con.close();
}
}catch(SQLException ex){
System.err.print(ex);
 
}
}

}
public static void main(String[] args) {
// TODO Auto-generated method stub

Reply re=new Reply();




 
 
 
//System.out.print(chi_dt);
 
 



}

public String getTopicid() {
return topicid;
}

public void setTopicid(String topicid) {
this.topicid = topicid;
}

public String getReplycontent() {
return replycontent;
}

public void setReplycontent(String replycontent) {
this.replycontent = replycontent;
}

public String getUserID() {
return userID;
}

public void setUserID(String userID) {
this.userID = userID;
}


}

请各位大虾看看,每次存入数据库的都是“”,我都不知道怎么办了


[解决办法]
有必要转吗,直接存进去不就得了

热点排行