首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

一个关于SSH2的有关问题~

2012-08-09 
一个关于SSH2的问题~!急!由于项目需求我需要使用SSH2框架。其中struts2我尝试了一下使用注解的方式,但是配

一个关于SSH2的问题~!急!
由于项目需求我需要使用SSH2框架。其中struts2我尝试了一下使用注解的方式,但是配置完之后总是访问不到,请各位大侠帮忙给看看:

我的struts.xml:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<!-- devMode模式是开发模式,默认开启了一些提示功能,方便开发排错 -->
<constant name="struts.devMode" value="true" />

<!-- 交给spring管理 -->
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.objectFactory.spring.autoWire" value="type" />

<!-- 映射JSP目录 -->
<constant name="struts.convention.result.path" value="/WEB-INF/pages/" />

<!-- 包路径包含test的将被视为Action存在的路径来进行搜索 -->
<constant name="struts.convention.package.locators" value="web,action" />

<!-- URL分割规则:去掉类名的Action部分。然后将将每个分部的首字母转为小写,用’-’分割 -->
<constant name="struts.convention.action.name.separator" value="-" />

<!-- 配置默认的Action -->
  <package name="default" namespace="/" extends="struts-default"/>
</struts>


我的Action:

package com.z.test.web;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;


import com.opensymphony.xwork2.ActionSupport;

@Namespace("/")
@ParentPackage("default")
@Action
public class HelloAction extends ActionSupport{

private static final long serialVersionUID = 1L;

public String method1(){
String a = "method1";
System.out.println(a);
return SUCCESS;
}

public String method2(){
String b = "method2";
System.out.println(b);
return SUCCESS;
}
}


然后我通过URL访问:http://localhost/SSH2andJPA/hello!method1.action
可是报错:
HTTP Status 404 - There is no Action mapped for namespace / and action name hello.
There is no Action mapped for namespace / and action name hello. - [unknown location]

说是没有映射"/"这个命名空间和Action"hello"。。。不知道哪里出了问题。

[解决办法]
这些配置是没错了,难道是少包了?
[解决办法]
若楼主换成xml配置action的话 能否访问到 ?若能 那肯定是注解配置有问题 或者哪里配置
不正确
[解决办法]
你的@Action沒給名字,
默認好想是类名,应该http://localhost/SSH2andJPA/HelloAction!method1.action
要不h小写试试,
要这样的话
http://localhost/SSH2andJPA/hello!method1.action
@Action(vlaue="hello")

[解决办法]
先试试把XML中的中文注释去掉。有些版本的容器不支持中文注释。
[解决办法]
你直接使用struts零配置多好啊!struts.xml代码:
<struts>
<!-- 默认包 --> <constant name="struts.convention.default.parent.package" value="auth-default"/>

<!-- 如果不用注解默认包就这样 --> <constant name="struts.convention.default.parent.package" value="convention-default"/>
<!-- 基于什么包 --> <constant name="struts.convention.package.locators.basePackage"value="这里写你自己acion路径比如:com.action"/>
<!--确定搜索包的路径。只要是结尾为action的包都要搜索。basePackage按照默认不用配置,如果配置,只会找以此配置开头的包。locators及locators.basePackage都是一组以逗号分割的字符串。 --> <constant name="struts.convention.package.locators" value="action"/>


<!--定于跳转后缀名--> <constant name="struts.action.extension" value="action,ajax,," /> <!--定于注解可要可不要 主要用来方便登陆判断-->
package name="auth-default" extends="convention-default"> <interceptors> <interceptor name="auth"class="com.me.code.modules.interceptor.AuthInterceptor"/> <interceptor-stack name="authStack"> <interceptor-ref name="auth" /> <interceptor-ref name="paramsPrepareParamsStack" /> </interceptor-stack> </interceptors> <default-interceptor-ref name="authStack"/></package> </struts>


wem.xml要注意这些:<filter-mapping>
<filter-name>struts2Filter</filter-name>
<url-pattern>*.action</url-pattern>
<url-pattern>*.ajax</url-pattern>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.html</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
action配上这些就ok了:
@Results({@Result(name = "success", location = "/ok.jsp") })
另外要加载一个jar:struts2-convention-plugin-2.1.8.1.jar

[解决办法]
http://localhost/SSH2andJPA/hello!method1.action
你的id为hello这个action是在哪里定义的,没有看到你定义的位置,是在spring容器中吗?没定义的话,麻烦定义一下
[解决办法]
1、你把开发模式关闭掉试试 devMode 我记得这个有可能出BUG

2、注解我没用过,先绑定,有空研究下= = 呵呵~~

热点排行