Java SSH项目出异常肿么办

喜之郎 发布于 2012/08/08 16:42
阅读 423
收藏 0

我用SSH做了一个项目,名称叫SSH,下面是web.xml中对Struts2的配置

	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>
			org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

然后是struts.xml配置

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<constant name="struts.enable.DynamicMethodInvocation" value="true" />
	<constant name="struts.devMode" value="true" />
	<constant name="struts.ui.theme" value="simple" />
	<constant name="struts.i18n.encoding" value="UTF-8" />
	<constant name="struts.custom.i18n.resources" value="globalMessages" />


	<!--
		定义上传文件临时存放路径 <constant name="struts.multipart.saveDir"
		value="D:\\temp"></constant>
	-->
	<!--定义上传文件最大大小100M ,超过此值会抛异常-->
	<constant name="struts.multipart.maxSize" value="104857600"></constant>

	<package name="ssh_default" extends="struts-default">
		<global-results>
			<result name="error">/error.jsp</result>
		</global-results>
		<global-exception-mappings>
			<exception-mapping result="error" exception="java.lang.Exception"></exception-mapping>
		</global-exception-mappings>
	</package>
	<include file="user.xml" />
	<include file="upload.xml" />

</struts> 

为什么输入以下路径访问

http://localhost:8080/SSH/

正常。而输入以下路径

http://localhost:8080/SSH
就出以下异常

There is no Action mapped for action name . - [unknown location]
	at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
	at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
	at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
	at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
	at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
	at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
	at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
	at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
	at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:187)
	at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:265)
	at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:273)
	at com.caucho.server.port.TcpConnection.run(TcpConnection.java:682)
	at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:743)
	at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:662)
	at java.lang.Thread.run(Thread.java:619)

加载中
0
喜之郎
喜之郎

我自己搞好了。我又写了个LoginAction.java:

package com.potegd.action;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;

@Component("loginAction")
@Scope("prototype")
public class LoginAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	@Override
	public String execute() throws Exception {
		return super.execute();
	}

}

然后配置到struts.xml中如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<constant name="struts.enable.DynamicMethodInvocation" value="true" />
	<constant name="struts.devMode" value="true" />
	<constant name="struts.ui.theme" value="simple" />
	<constant name="struts.i18n.encoding" value="UTF-8" />
	<constant name="struts.custom.i18n.resources" value="globalMessages" />


	<!--
		定义上传文件临时存放路径 <constant name="struts.multipart.saveDir"
		value="D:\\temp"></constant>
	-->
	<!--定义上传文件最大大小100M ,超过此值会抛异常-->
	<constant name="struts.multipart.maxSize" value="104857600"></constant>

	<package name="ssh_default" extends="struts-default">
		<global-results>
			<result name="error">/error.jsp</result>
		</global-results>
		<global-exception-mappings>
			<exception-mapping result="error" exception="java.lang.Exception"></exception-mapping>
		</global-exception-mappings>
		
		<action name="*" class="loginAction">
			<result name="success">/index.jsp</result>
		</action>
	</package>

	<include file="user.xml" />
	<include file="upload.xml" />

</struts> 

这样就可以直接输入:

http://localhost:8080/SSH
访问啦。高兴啊。。。 。。。

0
情天大圣
喜之郎
喜之郎
不行啊,老兄。把所有的namespace="/"都去掉还是这样。很郁闷。。。
0
喜之郎
喜之郎
按理说Struts2拦截的是/*路径,我输入SSH应该不会被它拦截啊???
0
情天大圣
情天大圣

将struts.xml中的:

<package name="ssh_default" extends="struts-default">

修改为:
<package name="ssh_default" extends="struts-default" namespace="/">

喜之郎
喜之郎
回复 @情天大圣 : http://zouxixi-project.googlecode.com/svn/trunk/%20zouxixi-project%20--username%20406427071qq.com@gmail.com/ 看能不能检出。
情天大圣
情天大圣
回复 @喜之郎 : 这是问题么?
喜之郎
喜之郎
这工程太大,三大框架的jar包一共有二十多M吧。
情天大圣
情天大圣
回复 @喜之郎 : 没道理的啊,把你的工程打包发到我邮箱,下班回家看看!
喜之郎
喜之郎
试过了,不行。。。
返回顶部
顶部