weixin_42299332 2009-04-24 08:57
浏览 151
已采纳

Struts2 入门问题

我在jsp文件中写了这样一行
<%@ taglib prefix="s" uri = "/struts-tags" %>

用eclipse可以找到struts-tags这个文件
导入的jar文件有以下几个
commons-logging-1.0.4.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
struts2-core-2.0.14.jar
xwork-2.0.7.jar

HelloWorld.jsp文件为
[code="java"] <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri = "/struts-tags" %>


Hello World!


< s:property value ="message"/>



[/code]

访问 HelloWorld.jsp文件时,产生错误信息如下,红色是我认为的关键颜色。向大家请教,我哪里错了

org.apache.jasper.JasperException: Exception in JSP: /HelloWorld.jsp:10

7: < title > Hello World! </ title >
8: </ head >
9: < body >
10: < h2 >< s:property value ="message" /></ h2 >
11: </ body >
12: </ html >

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

[color=red]The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location][/color]
org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:52)
org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:49)
org.apache.jsp.HelloWorld_jsp._jspx_meth_s_005fproperty_005f0(HelloWorld_jsp.java:87)
org.apache.jsp.HelloWorld_jsp._jspService(HelloWorld_jsp.java:61)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

展开全部

  • 写回答

3条回答 默认 最新

  • zhoujuan520 2009-04-24 09:31
    关注

    [code="html"]
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="s" uri = "/struts-tags" %><!-- ltd包的引用必须放到上面,这个是正规的写法 -->
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



    Hello World!


    <!-- 这里空格是个很明显的问题-->


    [/code]
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?