整容说文库 > 程序代码 > 教育资讯

小弟刚学STRUTS,可是环境从昨天晚上到现在还没配好那为大虾帮帮小弟感恩不尽啊

来源:学生作业帮助网 编辑:整容说文库 时间:2021/01/18 20:36:09 程序代码
小弟刚学STRUTS,可是环境从昨天晚上到现在还没配好那为大虾帮帮小弟感恩不尽啊程序代码
我用的是tomcat,在webapp下新建了一应用程序目录,以下是目录结构:
/HelloStruts 
  index.jsp 
    /pages 
      Welcome.jsp 
    /WEB-INF 
      web.xml 
        /conf 
            struts-config.xml 
        /lib 
            *.jar 
        /tld 
            *.tld 
        /classes 
            /resources 
              application.properties

这是我的web.xml的配置:
<?xml version="1.0" encoding="ISO-8859-1"?> 

<!DOCTYPE web-app 
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" 
  "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> 
                                                                                
<web-app> 
                                                                                
  <display-name>Struts Blank Application</display-name> 
                                                                                
  <!-- Standard Action Servlet Configuration (with debugging) --> 
  <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/conf/struts-config.xml</param-value> 
    </init-param> 
    <load-on-startup>2</load-on-startup> 
  </servlet> 
                                                                                
  <!-- Standard Action Servlet Mapping --> 
  <servlet-mapping> 
    <servlet-name>action</servlet-name> 
    <url-pattern>*.do</url-pattern> 
  </servlet-mapping> 

  <!-- The Usual Welcome File List --> 
  <welcome-file-list> 
    <welcome-file>index.jsp</welcome-file> 
  </welcome-file-list> 
 
  <!-- Struts Tag Library Descriptors --> 
  <taglib> 
    <taglib-uri>/tags/struts-bean</taglib-uri> 
    <taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location> 
  </taglib> 
                                                                                
  <taglib> 
    <taglib-uri>/tags/struts-html</taglib-uri> 
    <taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location> 
  </taglib> 
                                                                                
  <taglib> 
    <taglib-uri>/tags/struts-logic</taglib-uri> 
    <taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location> 
  </taglib> 
</web-app>
这是我struts-config.xml的配置:
<?xml version="1.0" encoding="ISO-8859-1" ?> 
                                                                                
<!DOCTYPE struts-config PUBLIC 
          "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" 
          "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> 
                                                                                
<struts-config> 
    <global-forwards> 
        <forward 
            name="welcome" 
            path="/Welcome.do"/> 
    </global-forwards> 
                                                                                
    <action-mappings> 
        <action 
            path="/Welcome" 
            type="org.apache.struts.actions.ForwardAction" 
            parameter="/pages/Welcome.jsp"/> 
    </action-mappings> 
                                                                                
    <message-resources parameter="resources.application"/> 
</struts-config>
这是我index.jsp的内容:
<%@ taglib uri="/tags/struts-logic" prefix="logic" %> 
<logic:redirect forward="welcome"/>
这是我Welcome.jsp的内容:
<%@ taglib uri="/tags/struts-bean" prefix="bean" %> 
<%@ taglib uri="/tags/struts-html" prefix="html" %> 
<%@page contentType="text/html; charset=Big5"%> 
<html:html locale="true"> 
<head> 
<title><bean:message key="welcome.title"/></title> 
<html:base/> 
</head> 
<body bgcolor="white"> 
                                                                                
<H1><bean:message key="welcome.message"/></H1> 
                                                                                
</body> 
</html:html>

这是我application.properties的内容:
# -- welcome -- 
welcome.title=Hello!Struts! 
welcome.message=Welcome to Your First Struts!
可总是找不到Welcome.jsp
大家帮忙看看。谢谢了
把struts包中带的 struts-blank.war 运行一下。。

理解一下,再写一个。 :)
你的struts-config.xml中没有actionform的配置
建议用 JBuilder2005 可以自动配置struts,适合初学者学习。
我也是刚学,共同努力
程序代码