读书人

初学者struts2入门

发布时间: 2012-02-13 17:20:26 作者: rapoo

菜鸟struts2入门求助
登录login.jsp
<%@ page language="java" contentType="text/html; charset=GBK"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>


<title>登录页面</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<form action="Login.action" method="post">
<table align="center">
<caption>user login</caption>
<tr>
<td>Username:<input type="text" name="Username"/></td>
</tr>
<tr>
<td>Password:<input type="text" name="Password"/></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" value="login"/>
<input type="reset" value="reset2"/></td>
</tr>
</table>
</form>
</body>
</html>

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>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />

<package name="1" extends="struts-default">
<action name="Login.action" class="rtcrud.LoginAction">
<result name="success">welcome.jsp</result>
<result name="error">error.jsp</result>
</action>
</package>

<!-- Add packages here -->

</struts>

Loginaction.java

package rtcrud;

public class LoginAction {
private String Username;
private String Password;
private final String Success="success";
private final String Error="error";
public String getUsername() {
return Username;
}
public void setUsername(String username) {
this.Username = username;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
this.Password = password;
}
public String execute() throws Exception{
if(getUsername().equals("scott")&& getPassword().equals("tiger")){
return Success;
}
else{
return Error;
}
}
}



页面报错 The requested resource (/new/Login.action) is not available.


求帮助!!!先行谢过!!


[解决办法]
LoginAction这个类放在哪了
------解决方案--------------------


action 中没写method
[解决办法]
new是什么,工程名字吗? web.xml贴出来。
[解决办法]
具体是在执行什么时候出的错,你不说要大家去猜么
[解决办法]
路过,没分了。555。。
[解决办法]
action即使是不继承actionsupport也是可以的,不过其中的方法必须是execute,应该不是这个问题
[解决办法]
页面上form里的action 要加上项目名称吧

读书人网 >J2EE开发

热点推荐