struts2 验证框架的问题。

zhangfengsummer 2010-04-23 02:01:02
配置struts2的验证框架的时候,出现找不到action的问题,将代码贴出来,请大家帮忙。

action的代码


package example.login;

import com.opensymphony.xwork2.ActionSupport;


public class Login2 extends ActionSupport {

public String login() {
System.out.println("----------");
return "hah";
}
}



login.jsp的代码


<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Sign On</title>
</head>

<body>
<form action="login.action" method="post">
用户名<input type="text" name="username"/><br>
密码<input type="password" name="pwd"/>
<input type="submit" value="提交">
</form>
</body>
</html>

Login2-validation.xml的代码


<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<validators>
<field name="username">
<field-validator type="requiredstring">
<message >没有用户名</message>
</field-validator>
</field>
<field name="pwd">
<field-validator type="requiredstring">
<message >密码为空</message>
</field-validator>
</field>
</validators>


struts的配置:

<?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="example" namespace="/example" extends="struts-default">

<action name="login" class="example.login.Login2" method="login">
<result name="hah">/example/success.jsp</result>
</action>




</struts>


求高手解答。
...全文
48 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangfengsummer 2010-05-02
  • 打赏
  • 举报
回复
不管用哦,不过谢谢。
redlotus_lyn 2010-04-23
  • 打赏
  • 举报
回复
1.jsp:

<form action="login.action" method="post" namespace="/example">

2.struts.xml

<action name="login" class="example.login.Login2" method="login">
<result name="input">/example/error.jsp</result> <result name="hah">/example/success.jsp</result>
</action>

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧