Java <;h:输出文本>;如何显示固定长度的内容?
我有这样一个字符串:Java <;h:输出文本>;如何显示固定长度的内容?,java,html,jsf-2,Java,Html,Jsf 2,我有这样一个字符串: <p><strong>Make sure you’re paying the right price for your household and trade services with pricing calculators from Australia’s largest online services marketplace, ServiceSeeking.com.au </strong></p>. 使用澳大利亚最大
<p><strong>Make sure you’re paying the right price for your household and trade services with pricing calculators from Australia’s largest online services marketplace, ServiceSeeking.com.au </strong></p>.
使用澳大利亚最大的在线服务市场ServiceSeeking.com.au的定价计算器,确保您为家庭和交易服务支付了正确的价格。
我想用
显示这个字符串的一部分(只显示内容,没有HTML标记)。我尝试了substring()
,但我不知道html标记在哪里完成,所以我的表单被破坏了。我只想得到大约100个字符。如何执行此操作?您可以使用以下JSF HTML标记输出文本:
<h:outputText escape="false" value="Your content here" />
您可以使用以下JSF HTML标记输出文本:
<h:outputText escape="false" value="Your content here" />
我不确定是否100%正确理解了您的问题,但如果您要显示的所有字符串的格式与示例中的格式大致相同,则您可以不使用html显示它们,并通过以下方式将其缩短为100个字符:
<h:outputText value="#{textExtractorBean.extractedText}"/>
这就是豆子:
class TextExtractorBean{
...
getExtractedText(){
Pattern pattern = Pattern.compile("<([a-z])+>");
Matcher matcher = pattern.matcher(text);
int firstIdxAfterOpeningTags = 0;
while(matcher.find()){
firstIdxAfterOpeningTags = matcher.end();
}
pattern = Pattern.compile("</([a-z])+>");
matcher = pattern.matcher(text);
int firstIdxBeforeClosingTags = text.length();
if(matcher.find()){
firstIdxBeforeClosingTags = matcher.start();
}
String extractedText = text.substring(firstIdxAfterOpeningTags,
firstIdxBeforeClosingTags);
String shortenedText = extractedText.length() > 0 ? extractedText
.substring(0,100) : extractedText;
return shortenedText;
}
...
}
类TextExtractorBean{
...
getExtractedText(){
Pattern=Pattern.compile(“”);
Matcher Matcher=pattern.Matcher(文本);
int firstIdxAfterOpeningTags=0;
while(matcher.find()){
firstIdxAfterOpeningTags=matcher.end();
}
pattern=pattern.compile(“”);
matcher=pattern.matcher(文本);
int firstIDXbeforoClosingTags=text.length();
if(matcher.find()){
firstIDXbeforoClosingTags=matcher.start();
}
String extractedText=text.substring(第一个IDX在OpeningTags之后,
第一个IDXbeforeconsingtags);
字符串shortenedText=extractedText.length()>0?extractedText
.子字符串(0100):提取的文本;
返回shortenedText;
}
...
}
其中文本变量包含字符串,如示例中所示。我不确定是否100%正确理解了您的问题,但如果您要显示的所有字符串的格式与示例中的格式大致相同,则您可以不使用html显示它们,并以这种方式缩短为100个字符:
<h:outputText value="#{textExtractorBean.extractedText}"/>
这就是豆子:
class TextExtractorBean{
...
getExtractedText(){
Pattern pattern = Pattern.compile("<([a-z])+>");
Matcher matcher = pattern.matcher(text);
int firstIdxAfterOpeningTags = 0;
while(matcher.find()){
firstIdxAfterOpeningTags = matcher.end();
}
pattern = Pattern.compile("</([a-z])+>");
matcher = pattern.matcher(text);
int firstIdxBeforeClosingTags = text.length();
if(matcher.find()){
firstIdxBeforeClosingTags = matcher.start();
}
String extractedText = text.substring(firstIdxAfterOpeningTags,
firstIdxBeforeClosingTags);
String shortenedText = extractedText.length() > 0 ? extractedText
.substring(0,100) : extractedText;
return shortenedText;
}
...
}
类TextExtractorBean{
...
getExtractedText(){
Pattern=Pattern.compile(“”);
Matcher Matcher=pattern.Matcher(文本);
int firstIdxAfterOpeningTags=0;
while(matcher.find()){
firstIdxAfterOpeningTags=matcher.end();
}
pattern=pattern.compile(“”);
matcher=pattern.matcher(文本);
int firstIDXbeforoClosingTags=text.length();
if(matcher.find()){
firstIDXbeforoClosingTags=matcher.start();
}
String extractedText=text.substring(第一个IDX在OpeningTags之后,
第一个IDXbeforeconsingtags);
字符串shortenedText=extractedText.length()>0?extractedText
.子字符串(0100):提取的文本;
返回shortenedText;
}
...
}
其中文本变量包含类似于示例中的字符串