我想在struct+spring+hibernate中使用jsp自定义标签
标签类
public class TitleTag extends TagSupport{
@Override
public int doStartTag() throws JspException {
Title title = null ;
TitleServices titleServices = (TitleServices)TagTool.getObject("titleServices");
title = titleServices.getTheTitle();
String Webtitle = title.getT_name();
System.out.println(Webtitle);
try {
pageContext.getOut().write(Webtitle);
} catch (IOException e) {
e.printStackTrace();
}
return super.doStartTag();
}
}
工具类
public class TagTool {
public static Object getObject(String str){
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
return ac.getBean(str);
}
}
配置
<tag><!-- 标题 -->
<name>title</name>
<tag-class>com.school.tag.TitleTag</tag-class>
<body-content>empty</body-content>
</tag>
页面
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ taglib uri="/taglib" prefix="cms" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<title>
<cms:title />
</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<a href="manager/index.jsp">uThis is my JSP page. </a><br>
</body>
</html>页面显示标签错误
大家帮帮忙,我第一次使用自定义标签
错误信息如下
org.apache.jasper.JasperException: Exception in JSP: /index.jsp:107: <html>
8: <head>
9: <title>
10: <cms:title />
11: </title>
12: <meta http-equiv="pragma" content="no-cache">
13: <meta http-equiv="cache-control" content="no-cache">
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
标签类
public class TitleTag extends TagSupport{
@Override
public int doStartTag() throws JspException {
Title title = null ;
TitleServices titleServices = (TitleServices)TagTool.getObject("titleServices");
title = titleServices.getTheTitle();
String Webtitle = title.getT_name();
System.out.println(Webtitle);
try {
pageContext.getOut().write(Webtitle);
} catch (IOException e) {
e.printStackTrace();
}
return super.doStartTag();
}
}
工具类
public class TagTool {
public static Object getObject(String str){
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
return ac.getBean(str);
}
}
配置
<tag><!-- 标题 -->
<name>title</name>
<tag-class>com.school.tag.TitleTag</tag-class>
<body-content>empty</body-content>
</tag>
页面
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ taglib uri="/taglib" prefix="cms" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<title>
<cms:title />
</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<a href="manager/index.jsp">uThis is my JSP page. </a><br>
</body>
</html>页面显示标签错误
大家帮帮忙,我第一次使用自定义标签
错误信息如下
org.apache.jasper.JasperException: Exception in JSP: /index.jsp:107: <html>
8: <head>
9: <title>
10: <cms:title />
11: </title>
12: <meta http-equiv="pragma" content="no-cache">
13: <meta http-equiv="cache-control" content="no-cache">
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
楼主【myair2006】截止到2008-07-09 14:33:27的历史汇总数据(不包括此帖):
发帖的总数量:19 发帖的总分数:360 每贴平均分数:18
回帖的总数量:21 得分贴总数量:3 回帖的得分率:14%
结贴的总数量:15 结贴的总分数:280
无满意结贴数:4 无满意结贴分:80
未结的帖子数:4 未结的总分数:80
结贴的百分比:78.95 % 结分的百分比:77.78 %
无满意结贴率:26.67 % 无满意结分率:28.57 %
楼主加油