正在调试一个书上例子,出错信息如下:
org.apache.jasper.JasperException: Unable to compile class for JSPGenerated servlet error:
D:\Tomcat\work\Catalina\localhost\_\org\apache\jsp\WebRoot\showAttackSolution_jsp.java:6: 软件包 struts.sample.cap13.sample1.entity 不存在
import struts.sample.cap13.sample1.entity.AttackSolution;
                                          ^
An error occurred at line: 55 in the jsp file: /WebRoot/showAttackSolution.jsp
Generated servlet error:
D:\Tomcat\work\Catalina\localhost\_\org\apache\jsp\WebRoot\showAttackSolution_jsp.java:175: 软件包 struts.sample.cap13.sample1.entity 不存在
            struts.sample.cap13.sample1.entity.AttackSolution attackSolution = null;
                                              ^
An error occurred at line: 55 in the jsp file: /WebRoot/showAttackSolution.jsp
Generated servlet error:
D:\Tomcat\work\Catalina\localhost\_\org\apache\jsp\WebRoot\showAttackSolution_jsp.java:181: 软件包 struts.sample.cap13.sample1.entity 不存在
            attackSolution = (struts.sample.cap13.sample1.entity.AttackSolution) _jspx_page_context.findAttribute("attackSolution");
                                                                ^
Generated servlet error:
D:\Tomcat\work\Catalina\localhost\_\org\apache\jsp\WebRoot\showAttackSolution_jsp.java:212: 软件包 struts.sample.cap13.sample1.entity 不存在
              attackSolution = (struts.sample.cap13.sample1.entity.AttackSolution) _jspx_page_context.findAttribute("attackSolution");
                                                                  ^
注意:D:\Tomcat\work\Catalina\localhost\_\org\apache\jsp\WebRoot\showAttackSolution_jsp.java 使用了未经检查或不安全的操作。
注意:要了解详细信息,请使用 -Xlint:unchecked 重新编译。
4 错误 org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
例子的目录结构是:
D:\Tomcat\webapps\sshsampleD:\Tomcat\webapps\sshsample\src\struts\sample\cap13\sample1\entitypackage struts.sample.cap13.sample1.entity;public class AttackSolution D:\Tomcat\webapps\sshsample\WebRoot\showAttackSolution.jsp

解决方案 »

  1.   

    查看构建路径有没有错误
    看看problem窗口提示
    web.xml配置问题,如果你用自定义标签的话,就要在里面配置
      

  2.   

    我是直接把书带的光盘的源代码放到tomcat下的wepapp文件夹下的,没有什么构建路径啊
    web.xml文件:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"--><web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
      <filter>
        <filter-name>Set Character Encoding</filter-name>
        <filter-class>struts.sample.cap13.sample1.util.SetCharacterEncodingFilter</filter-class>
        <init-param>
          <param-name>encoding</param-name>
          <param-value>UTF-8</param-value>
        </init-param>
      </filter>
      <filter-mapping>
        <filter-name>Set Character Encoding</filter-name>
        <url-pattern>*.do</url-pattern>
      </filter-mapping>
      <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
          <param-name>config</param-name>
          <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <init-param>
          <param-name>debug</param-name>
          <param-value>2</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
        <welcome-file>setSolution.jsp</welcome-file>
      </welcome-file-list>
      <jsp-config>
      <taglib>
        <taglib-uri>WEB-INF/struts-template.tld</taglib-uri>
        <taglib-location>WEB-INF/struts-template.tld</taglib-location>
      </taglib>
      <taglib>
        <taglib-uri>WEB-INF/struts-bean.tld</taglib-uri>
        <taglib-location>WEB-INF/struts-bean.tld</taglib-location>
      </taglib>
      <taglib>
        <taglib-uri>WEB-INF/struts-html.tld</taglib-uri>
        <taglib-location>WEB-INF/struts-html.tld</taglib-location>
      </taglib>
      <taglib>
        <taglib-uri>WEB-INF/struts-logic.tld</taglib-uri>
        <taglib-location>WEB-INF/struts-logic.tld</taglib-location>
      </taglib>
      <taglib>
        <taglib-uri>WEB-INF/struts-titles.tld</taglib-uri>
        <taglib-location>WEB-INF/struts-titles.tld</taglib-location>
      </taglib>
      <taglib>
        <taglib-uri>WEB-INF/struts-nested.tld</taglib-uri>
        <taglib-location>WEB-INF/struts-nested.tld</taglib-location>
      </taglib>
      </jsp-config>
    </web-app>
    showattacksolution.jsp文件内容:
    <%@ page contentType="text/html; charset=utf-8"%>
    <%@ page import="struts.sample.cap13.sample1.entity.AttackSolution" %> 
    <%@ taglib uri="WEB-INF/struts-logic.tld" prefix="logic" %>
    <%@ taglib uri="WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="WEB-INF/struts-bean.tld" prefix="bean" %>
    <html>
      <head>
        <script language="JavaScript">
         function add() {
         document.attackSolutionActionForm.attack_event_code.value = attack_event_codeC.value;
         document.attackSolutionActionForm.attack_mean.value = attack_meanC.innerText;
         document.attackSolutionActionForm.attack_action.value = attack_actionC.innerText;
         document.attackSolutionActionForm.action = "AddAttackSolutionAction.do";
         document.attackSolutionActionForm.submit();
         }
         function search() {
         document.attackSolutionActionForm.attack_event_code.value = attack_event_codeC.value;
         document.attackSolutionActionForm.attack_mean.value = attack_meanC.innerText;
         document.attackSolutionActionForm.attack_action.value = attack_actionC.innerText;
         document.attackSolutionActionForm.action = "SearchAttackSolutionAction.do";
         document.attackSolutionActionForm.submit();
         }
         function del(argAttack_event_code) {
         document.attackSolutionActionForm.attack_event_code.value = argAttack_event_code;
         document.attackSolutionActionForm.action = "DeleteAttackSolutionAction.do";
         document.attackSolutionActionForm.submit();
         }
        </script>
      </head>
      <body>
        <em><bean:message key="message.attacksolutionDB"/></em><p>
        <table>
       <html:errors/>
       </table>
    <bean:message key="message.attackcode"/>:<input name="attack_event_codeC" value="" type="text">&nbsp;
    <bean:message key="message.attackdesc"/>:<TEXTAREA style="height:100" name=attack_meanC></TEXTAREA>&nbsp;

    <bean:message key="message.attacksolution"/>:<TEXTAREA style="height:100" name=attack_actionC></TEXTAREA>&nbsp;
    <p/>
        <html:form action="AddAttackSolutionAction.do">
         <html:hidden property="attack_event_code"/>
         <html:hidden property="attack_mean"/>
         <html:hidden property="attack_action"/>
         <input type="button" onclick="add();" value="<bean:message key="message.add"/>">
         <input type="button"  onclick="search();" value="<bean:message key="message.search"/>">
        </html:form>
        <table border=1 cellspacing=1 cellpadding=2>
         <tr>
         <td style="background-color: #808080;font-size: 12pt;color: #ffffff;font-weight: bold;line-height: 15pt;border: 1px solid #808080;"><bean:message key="message.attackcode"/></td>
         <td style="background-color: #808080;font-size: 12pt;color: #ffffff;font-weight: bold;line-height: 15pt;border: 1px solid #808080;"><bean:message key="message.attackdesc"/></td>
         <td style="background-color: #808080;font-size: 12pt;color: #ffffff;font-weight: bold;line-height: 15pt;border: 1px solid #808080;"><bean:message key="message.attacksolution"/></td>
         <td style="background-color: #808080;font-size: 12pt;color: #ffffff;font-weight: bold;line-height: 15pt;border: 1px solid #808080;"><bean:message key="message.delete"/></td>
         </tr>
    <logic:notEmpty name="allAttackSolution">
         <logic:iterate name="allAttackSolution" id="attackSolution" type="struts.sample.cap13.sample1.entity.AttackSolution">
    <tr>
             <td style="word-break: break-all;" >
              <bean:write property="attack_event_code" name="attackSolution"/>
             </td>
             <td style="word-break: break-all;" >
              <bean:write property="attack_mean" name="attackSolution"/>
             </td>
             <td style="word-break: break-all;" >
              <bean:write property="attack_action" name="attackSolution"/>
             </td>
             <td style="word-break: break-all;" ><input type="button" onclick="del('<%=attackSolution.getAttack_event_code()%>');" value="<bean:message key="message.delete"/>"></td>
    </tr>
    </logic:iterate>
    </logic:notEmpty>
        </table>
      </body>
    </html>
      

  3.   

    用的是不是eclispe?
    如果是,查查所有的与路经有关的定义文件。
    我现在不好说是那个错了。web.xml的可能性比较大,*.properties也看看(虽然可能没用)。
      

  4.   

    有没有把struts的jar文件加到工程里?