1.主页
<body>
<form action="NoteServlet" method="post">
Note:<textarea rows="10" cols="20"name="notes"></textarea>
<input type="submit">
</form>
</body>
2.Servlet
public class NoteServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException {
String notes= request.getParameter("notes");
System.err.println("向数据库保存了数据。。。"+notes);//模拟保存到数据库
//response.getWriter().print(notes);
request.setAttribute("notes",notes);
request.getRequestDispatcher("/jsps/c.jsp").forward(request,response);
}
}
3.自定义标签类
publicclassOutTag extendsSimpleTagSupport {
private String value;
List<String>list= newArrayList<String>();
publicvoid setValue(String value){
this.value = value;
list.add("SB");
list.add("沙比");
}
@Override
publicvoid doTag() throws JspException,IOException {
for(String s:list){
value = value.replaceAll(s, "***");
}
getJspContext().getOut().print(value);
}
}
4.标签的配置c.tld
<uri>/aa</uri>
<tag>
<name>out</name>
<tag-class>czb.tag.OutTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
5.显示
<%@ taglib uri="/aa"prefix="o"%>
<body>
留言原内容:${notes}<br/>
留言被和谐后的内容:<o:out value="${notes}"/>
</body>