刚接触struts2不久,在写测试的时候遇到一个问题,请求大家帮忙解决。问题如下:我写了一个登录页面,启动服务,访问路径http://155.20.25.249:7001/TestStruts2,TestStruts2是我的工程名称,页面访问正常,
页面用的struts2标签
代码为:
<s:form action="loginAction">
<s:textfield label="用户名" name="username"></s:textfield>
<s:password label="密码" name="password"></s:password>
<s:submit value="登录">
<input type="button" value="注册" onclick="window.location.href='/buss_regist.jsp'"></s:submit>
</s:form>
<s:actionerror/>
<s:actionmessage/>
查看源文件如下:
<form id="loginAction" name="loginAction" action="/TestStruts2/loginAction.action" method="post">
<table class="wwFormTable">
<tr>
<td class="tdLabel"><label for="loginAction_username" class="label">用户名:</label></td>
<td><input type="text" name="username" value="" id="loginAction_username"/></td>
</tr>
<tr>
<td class="tdLabel"><label for="loginAction_password" class="label">密码:</label></td>
<td><input type="password" name="password" id="loginAction_password"/></td>
</tr>
<tr>
<td colspan="2"><div align="right"><input type="submit" id="loginAction_0" value="登录"/>
<input type="button" value="注册" onclick="window.location.href='http://155.20.25.249:7001/EasyCool/regist/buss_regist.jsp'"></div></td>
</tr>
</table>
</form>
开始做登录测试,输入错误的用户名和密码,返回正常并提示输入信息有误
查看页面源文件为:
<form id="loginAction" name="loginAction" action="/TestStruts2/loginAction.action" method="post">
<table class="wwFormTable">
<tr>
<td class="tdLabel"><label for="loginAction_username" class="label">用户名:</label></td>
<td
><input type="text" name="username" value="yylaob" id="loginAction_username"/></td>
</tr>
<tr>
<td class="tdLabel"><label for="loginAction_password" class="label">密码:</label></td>
<td
><input type="password" name="password" id="loginAction_password"/></td>
</tr>
<tr>
<td colspan="2"><div align="right"><input type="submit" id="loginAction_0" value="登录"/>
<input type="button" value="注册" onclick="window.location.href=/buss_regist.jsp'"></div></td>
</tr>
</table></form>
<ul class="errorMessage">
<li><span>用户名或密码错误,请重新输入!</span></li> </ul>
此时再输入正确的用户名和密码
浏览器报HTTP 404 错误
控制台错误信息如下:
WARN org.apache.struts2.dispatcher.Dispatcher - Could not find action or result
No result defined for action easycool.common.userAction.EC_UserLoginAction and result input
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:364)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
...
...
页面用的struts2标签
代码为:
<s:form action="loginAction">
<s:textfield label="用户名" name="username"></s:textfield>
<s:password label="密码" name="password"></s:password>
<s:submit value="登录">
<input type="button" value="注册" onclick="window.location.href='/buss_regist.jsp'"></s:submit>
</s:form>
<s:actionerror/>
<s:actionmessage/>
查看源文件如下:
<form id="loginAction" name="loginAction" action="/TestStruts2/loginAction.action" method="post">
<table class="wwFormTable">
<tr>
<td class="tdLabel"><label for="loginAction_username" class="label">用户名:</label></td>
<td><input type="text" name="username" value="" id="loginAction_username"/></td>
</tr>
<tr>
<td class="tdLabel"><label for="loginAction_password" class="label">密码:</label></td>
<td><input type="password" name="password" id="loginAction_password"/></td>
</tr>
<tr>
<td colspan="2"><div align="right"><input type="submit" id="loginAction_0" value="登录"/>
<input type="button" value="注册" onclick="window.location.href='http://155.20.25.249:7001/EasyCool/regist/buss_regist.jsp'"></div></td>
</tr>
</table>
</form>
开始做登录测试,输入错误的用户名和密码,返回正常并提示输入信息有误
查看页面源文件为:
<form id="loginAction" name="loginAction" action="/TestStruts2/loginAction.action" method="post">
<table class="wwFormTable">
<tr>
<td class="tdLabel"><label for="loginAction_username" class="label">用户名:</label></td>
<td
><input type="text" name="username" value="yylaob" id="loginAction_username"/></td>
</tr>
<tr>
<td class="tdLabel"><label for="loginAction_password" class="label">密码:</label></td>
<td
><input type="password" name="password" id="loginAction_password"/></td>
</tr>
<tr>
<td colspan="2"><div align="right"><input type="submit" id="loginAction_0" value="登录"/>
<input type="button" value="注册" onclick="window.location.href=/buss_regist.jsp'"></div></td>
</tr>
</table></form>
<ul class="errorMessage">
<li><span>用户名或密码错误,请重新输入!</span></li> </ul>
此时再输入正确的用户名和密码
浏览器报HTTP 404 错误
控制台错误信息如下:
WARN org.apache.struts2.dispatcher.Dispatcher - Could not find action or result
No result defined for action easycool.common.userAction.EC_UserLoginAction and result input
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:364)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
...
...
<package name="default" extends="struts-default">
<action name="loginAction" class="LoginAction">
<result name="fail" type="dispatcher">/login.jsp</result>
<result name="success">/success.jsp</result>
</action>
</package>因为我的JSP文件都在根目录下,所以没有用namespace ,
无奈下,我也加了namespace测试了一下,没有任何变化。感觉就像是服务器完全接不到第二次请求,两次请求路径不是完全一样吗?求解答。
应。。<改为:<s:form action="loginAction.acttion">还要看配置文件是否出错。。这也很重要。
重启服务器,还是第一访问,一切正常,第二次到N次,都是404错误
用Firefox调试显示:
No result defined for action TestStruts2.common.userAction.EC_UserLoginAction and result input
输入数据类型是不是错了,或者是长度限制了
你添加个
<result name="input">/跳转页面</result>
你看看是不是跳转到那个页面了、。
里的type="dispatcher" 去掉~~~~~~~
我后面的访问连处理action类都没有进去,应该和返回字符串没关系吧我返回字符串分别是“fail”和“success”~
加了个<result name="input">/login.jsp</result>的配置
现在是第二次到第N次不管输入是否正确都跳到登录界面上我没有加域名空间
每次控制台提示
WARN org.apache.struts2.components.ServletUrlRenderer - No configuration found for the specified action: 'loginAction.action' in namespace: '/'. Form action defaulting to 'action' attribute's literal value.
WARN org.apache.struts2.components.ServletUrlRenderer - No configuration found for the specified action: 'loginAction.action' in namespace: '/'. Form action defaulting to 'action' attribute's literal value.既然每次连提示都是一样的,那么访问请求的处理类应该都可以映射到啊为什么只有第一次真正映射到了呢?还有怎么会有一个“input”返回,我在处理action类里打了断点,只有第一次访问进去了,后面的压根都没进去,怎么会有个“input”的返回?是还有一个默认的处理类接收了我后面所有的请求吗?大哥大姐们,解释一下?或者这个是不是我的struts、spring、WebLogic版本的兼容问题?或者那个引用的jar包冲突造成的?
<?xml version="1.0" encoding="GBK"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true </param-value>
</init-param>
</filter>
<servlet>
<servlet-name>ValidatePicServlet</servlet-name>
<servlet-class>easycool.common.ValidatePicServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ValidatePicServlet</servlet-name>
<url-pattern>/servlet/getValidatePic.do</url-pattern>
</servlet-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
我的sping里面是这样配置的
<bean id="userManage" class="test.common.userBean.EC_UserManage">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- 配置LoginAction -->
<bean id="LoginAction" class="test.common.userAction.EC_UserLoginAction">
<property name="userManage">
<ref bean="userManage"/>
</property>
</bean>这个配置的LoginAction默认是单例的吗?
默认是单例。
谢谢,就是这个问题,配成prototype就没问题了~~默认是singleton ,完全没有想到 SHIT!!!