jdk1.6.0_24+apache-tomcat-7.0.12+Eclipse目前最新版
我下载了最新的:struts2.2.3
jar文件放在:WebContent\WEB-INF\lib,常用的都包括了
struts.xml放在:WebContent\WEB-INF\classes下,配置如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!--
/*
* $Id: struts-plugin.xml 722219 2008-12-01 20:41:26Z musachy $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
-->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.action.extension" value="action,do" />
<!-- 声明包 -->
<package name="myPackage" extends="struts-default">
<!-- 定义action -->
<action name="userAction" class="com.action.UserAction">
<!-- 添加成功的映射页面 -->
<result name="add">user_add.jsp</result>
<!-- 更新成功的映射页面 -->
<result name="update">user_update.jsp</result>
</action>
</package>
<!-- 声明包 -->
<package name="myPackage2" extends="struts-default">
<!-- 定义action -->
<action name="TestAction" class="com.action.TestAction">
<!-- 处理成功的映射页面 -->
<result>success.jsp</result>
</action>
</package>
</struts>
web.xml放在:\WebContent\WEB-INF下,配置如下:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- END SNIPPET: filter -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
index.jsp文件:
<a href="TestAction.action">struts2</a>
<a href="userAction!add">添加用户</a>
<br>
<a href="userAction!update">更新用户</a>
TestAction文件:
package com.action;
import com.opensymphony.xwork2.ActionSupport;
/**
* Map类型的request、session、application
*/
public class TestAction extends ActionSupport {
private static final long serialVersionUID = 1L;
public TestAction(){
}
/**
* 请求处理方法
* @return String
*/
public String execute() throws Exception{
return SUCCESS;
}
}
问题描述如下:
按照目前的配置,index.jsp中三个链接都访问不了,错误类似:
HTTP Status 404 - /myNewProject/userAction!add
The requested resource (/myNewProject/userAction!add) is not available.
如果我把struts.xml文件中这段配置:
<constant name="struts.action.extension" value="action,do" />
注释掉的话
添加,更新用户可以访问,但:struts2这个链接还是用不了,错误如下一样:
The requested resource (/myNewProject/TestAction.action) is not available.
所有jsp文件都在一个目录下,请各位大侠们指教!