解析后的
该怎么处理

shore1111 2009-09-22 11:38:48
现在对方服务器返回的内容中含有<br/>,在我的页面中直接显示为<br/>。action中我这样处理Result3.replaceAll("<br/>", "");但是没起作用,这是什么原因啊?

...全文
442 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
andyan_2008 2009-09-22
  • 打赏
  • 举报
回复
还是用replace方法,先对“<”、“>”和“/”进行转义,
“\<”代替“<”
“\>”代替“>”
“\/”代替“/”
试试看
shore1111 2009-09-22
  • 打赏
  • 举报
回复
Result3[j].replaceAll("<br/>", "");这个我替换了,其它也得替换吗?
晴天v1 2009-09-22
  • 打赏
  • 举报
回复
如果可以用el表达式的话,可以试下el表达式,我不记得el表达式会不会过滤了。

另外如果是用struts的话,bean:write 标签有个filter属性,可以设置是否过滤。jstl估计也有类似的标签的。
鲜为人知 2009-09-22
  • 打赏
  • 举报
回复
replaceAll这个方法,我只成功替换过“,”,其他的字符和字符串都没替换成功。

shore1111 2009-09-22
  • 打赏
  • 举报
回复
public String process() {
client.getHostConfiguration().setHost( "wap.l.cn" , 80, "http" );
HttpMethod method;
try {
method = Mobile.getGetMethod(tel);
try {
client.executeMethod(method);
String Result2=new String(method.getResponseBodyAsString());
String[] Result3 = Result2.split("\n");
Result = new String[Result3.length];
int i = "<br/>".length();
for(int j=0;j<Result3.length;j++){
for(int t=0;t<Result3[j].length()-i;t++)
{ if(Result3[j].regionMatches(0,"<br/>",0,i)==true)
Result3[j].replaceAll("<br/>", "");}
Result[j] = Result3[j];
}
method.releaseConnection();
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}


return SUCCESS;
}
猿敲月下码 2009-09-22
  • 打赏
  • 举报
回复
Result3.replaceAll("<br/>", "");
把关于这个地方的的代码贴下
shore1111 2009-09-22
  • 打赏
  • 举报
回复
返回的内容呢是这个样子的。
手机号:1590058****<br/>
归属地:上海<br/>
卡类型:移动全球通卡<br/>
Result3.replaceAll("<br/>", "");这种方法是行不通的啊
Johnson_Hong 2009-09-22
  • 打赏
  • 举报
回复
Result3里面有<br/>吗?
如果有的话,可能是你前面加了空格的原因,大小写也要注意
乌云飘 2009-09-22
  • 打赏
  • 举报
回复
Result3.replaceAll("<br/>", "\r\n");
试试
BearKin 2009-09-22
  • 打赏
  • 举报
回复
先把这些数据在后台输出下 判断下究竟是什么

< > 你获得的时候那个< 或者 > 是这两个 所以你替换的时候得给他换成

Result3.replaceAll("<br>", "");

如果还不好使的话 另外你replace <br/>的时候前面带了个空格 把他去掉

猿敲月下码 2009-09-22
  • 打赏
  • 举报
回复
其实页面显示的是<br/>

Result3.replaceAll("<br/>", "");
shore1111 2009-09-22
  • 打赏
  • 举报
回复
问题OK啦,解析的时候出了点问题,+_+!
shore1111 2009-09-22
  • 打赏
  • 举报
回复
谁会解析啊,比如说我只想获取其中的手机号和归属地。
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card title="乐活-[北京]">
<p>
<a href="/tel/tel_index.php?city_id=010&sid=&tuid=22128034">归属地</a>->查询结果
<br/>
手机号码归属地查询<br/>
<input name="tel" maxlength="50" value="" size="19"/><br/>
><anchor>查询
<go method="get" href="/tel/tel_search.php">
<postfield name="city_id" value="010"></postfield>
<postfield name="tuid" value="22128034"></postfield>
<postfield name="sid" value=""></postfield>
<postfield name="tel" value="$tel"></postfield>
</go>
</anchor>
<br/>

手机号:1590058****<br/>
归属地:上海<br/>
卡类型:移动全球通卡<br/>

<a href="wtai://wp/mc;1590058****">直接拨打</a><br/>
<a href="wtai://wp/mc;179511590058****">加17951拨打</a><br/>
<a href="/opinion/list.php?city_id=010&tuid=22128034">查询结果不满意?</a><br/>
<br/>
<anchor>返回上页<prev/></anchor><br/>
<a href="/search/category.php?city_id=010&tuid=22128034&cate_name=%E7%BE%8E%E9%A3%9F&sid=">美食</a>
<a href="/search/category.php?city_id=010&tuid=22128034&cate_name=%E5%A8%B1%E4%B9%90&sid=">娱乐</a>
<a href="/search/category.php?city_id=010&tuid=22128034&cate_name=%E6%9C%8D%E5%8A%A1&sid=">服务</a>
<br/>
<a href="/index.php?city_id=010&tuid=22128034&sid=">乐活首页</a><br/>
乐活<br/>
09-22 14:52 </p>
</card>

</wml>
shore1111 2009-09-22
  • 打赏
  • 举报
回复
想想,问题可能出在解析的过程中

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧