工大后院

 找回密码
 加入后院

扫一扫,访问微社区

QQ登录

只需一步,快速开始

搜索
查看: 1133|回复: 3

关于struts

[复制链接]
发表于 2006-3-6 23:32 | 显示全部楼层 |阅读模式
struts-config.xml文件如下:#####################################################################

<?xml version="1.0"?>
<!DOCTYPE struts-config
PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
  "http://jakrta.apache.org/struts/dtds/struts-config_1_1.dtd">
<!--This is the Struts configuration file for the "Hello!" sample application-->
<struts-config>
        <!-- Form Bean Definition -->
        <form-beans>
                <form-bean name="TestForm" type="sys.test.TestForm" />
        </form-beans>
        <!-- Action Mapping Definition -->
        <action-mappings>
                <action type="sys.action.TestAction" scope="request" path="/testAction">
                        <forward name="wellcome" path="/test.jsp" />
                </action>
        </action-mappings>
        <message-resources parameter="WebsystermMessageResource_ZH" />
</struts-config>

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>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<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-template.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-template.tld</taglib-location>
</taglib>
</web-app>

index.jsp文件如下:#####################################################################

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="struts/bean" prefix="bean"%>
<%@ taglib uri="struts/html" prefix="html"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>index.jsp</title>
</head>
<body>
<h1>hello</h1>
<br>
<a href="testAction.do">Test</a>
</body>
</html>

test.jsp文件如下:#####################################################################
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="struts/bean" prefix="bean"%>
<%@ taglib uri="struts/html" prefix="html"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>test</title>
</head>
<body>wellcome!
</body>
</html>

TestAction.java 文件如下:#####################################################################
/**
*
*/
package sys.test;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
* @author bobows
*
*/
public class TestAction extends Action {
        /* (非 Javadoc)
         * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
         */
        public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
                return (mapping.findForward("wellcome"));
        }

}

现在遇到的问题是:在index.jsp页面里边点击Test链接时,根本转不到test.jsp
说是:
type Status report

message /websysterm/testAction.do

description The requested resource (/websysterm/testAction.do) is not available.

我不知道什么原因想请教后院能人.谢谢
发表于 2006-3-7 11:39 | 显示全部楼层
你用的是STtust几啊。
我也是最近才用STRUST的。给点建议:
public ActionForward unspecified
这个似乎才是STRUTS的ActionForward默认执行的方法吧?

要不你试一下。<a href="testAction.do?method=execute">Test</a>
回复

使用道具 举报

 楼主| 发表于 2006-3-7 13:56 | 显示全部楼层
原帖由 大鱼 于 2006-3-7 11:39 AM 发表
你用的是STtust几啊。
我也是最近才用STRUST的。给点建议:
public ActionForward unspecified
这个似乎才是STRUTS的ActionForward默认执行的方法吧?

要不你试一下。<a href="testAction.do?metho ...

我用的是struts1.1呵呵,,我估计是配置文件出了问题
我用了struts自带的struts-blank的配置文件修改一下再运行我的程序就可以了..

谢谢
回复

使用道具 举报

发表于 2006-3-7 19:04 | 显示全部楼层
楼主程序没错的.

欢迎楼主到本版交流java框架方面的问题.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入后院

本版积分规则

QQ|Archiver|手机版|小黑屋|广告业务Q|工大后院 ( 粤ICP备10013660号 )

GMT+8, 2025-5-14 17:05

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表