login.jsp <form action="login.action" method="post">
username:<input type = "text" name = "username" > <br>
password:<input type = "password" name = "password"> <br>
<input type = "submit" value = "submit">result.jsp
username:${requestScope.username} <br>
password:${requestScope.password} LoginAction:
package com.test.Action;public class LoginAction { private String username;
private String password;
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public String execute() throws Exception
{
return "success";
}
}
structs.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>
<package name="struts2" extends="struts-default">
<action name="login" class = "com.test.Action.LoginAction">
<result>/result.jsp</result>
</action>
</package>
</struts>web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>strcuts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>strcuts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>报的错:
description The requested resource (There is no Action mapped for namespace / and action name login.) is not available.
username:<input type = "text" name = "username" > <br>
password:<input type = "password" name = "password"> <br>
<input type = "submit" value = "submit">result.jsp
username:${requestScope.username} <br>
password:${requestScope.password} LoginAction:
package com.test.Action;public class LoginAction { private String username;
private String password;
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public String execute() throws Exception
{
return "success";
}
}
structs.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>
<package name="struts2" extends="struts-default">
<action name="login" class = "com.test.Action.LoginAction">
<result>/result.jsp</result>
</action>
</package>
</struts>web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>strcuts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>strcuts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>报的错:
description The requested resource (There is no Action mapped for namespace / and action name login.) is not available.
解决方案 »
- simpledateformat
- 求高手指点!
- 求懂连接池和Spring原理的朋友来帮帮我
- spring+hibernate的一个有趣的问题!!跪求高手解答!!!!
- 求救,。。。。。
- 关于spring,hibernate整合中的事务提交问题
- 用JAVA做一个C/S模式的程序
- java 异常:Caused by: java.lang.NoSuchMethodError: 有偿解决
- 哪位高手帮我看下这个问题,谢谢!
- 做了一个Hibernate和Struts的例子出错!!!请教高人指点!!!
- 在jsp页面上,如何从spring容器中拿到一个bean?
- 为什么我开启了TOMCAT服务器。。其他机子还是访问不到我的TOMCAT呢?
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>struts.i18n.encoding</param-name>
<param-value>UTF-8</param-value>
</init-param> </filter>
我看的这个教程里面没有namespace
也没有1楼的那个写法
换成<form action="login" method="post">也不行
........你的代码!
</s:from>
这个教程没用struts2标签也运行了
password:${requestScope.password} 这两行删除了也不行
我按你代码测试过没问题。。
只是发现使用
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
会乱码
使用1L的
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
这比较好。。
username: <input type = "text" name = "username" > <br>
password: <input type = "password" name = "password"> <br>
<input type = "submit" value = "submit">
</form> //这东西忘掉了吧
<action name="/login" class = "com.test.Action.LoginAction">
没找你你的action。看你上面的代码和namespace 没关系。
struts也没写错。。
应该就是你位置问题了
???