Struts2第一个Demo求指导

Struts2第一个Demo求指点
本人初学Struts2,按照书上的示例自己写了一个Demo。配置文件及路径如下:
Struts2第一个Demo求指导
login.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
</head>
<body>
<form action= "<%=request.getContextPath() %>/login.action" method= "get">
User Name: <input type= "text" name= "username" />
Password: <input type= "password" name= "password" />
<input type= "submit" value= "Login" />
</form>
</body>
</html>

LoginAction.java:
package Struts2Test;

import com.opensymphony.xwork2.Action;

public class LoginAction implements Action{
private String username;
private String password;

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{
System.out.println( "here" );
if( username.equals( "Struts2" ) ){
return "LoginSuccess";
}else{
return "LoginFailure";
}
}
}

web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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">

    <display-name>Struts Blank</display-name>

    <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>

</web-app>

struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <package name="default" namespace="/" extends="struts-default">

        <action name="login" class= "Struts2Test.LoginAction">
            <result name= "LoginSuccess">/success.jsp</result>
            <result name= "LoginFailure" >/failure.jsp</result>
        </action>
    </package>

</struts>

Struts2第一个Demo求指导

求巨师指点。
话说Java开发跟C、C++开发在调试方面还是很不一样。用Struts2时我根本不知道如何动手调试啊。
------解决方案--------------------
引用:
Quote: 引用:

好像看错了,路径对着呢,你改改以下几个地方,试试:
1. <form action= "<%=request.getContextPath() %>/login.action" method= "post">
红色的去掉,改成post请求。

2. public String username;
    public String password;
换成public,get/set方法都去掉。

试一试。


谢谢!
按照你说的改了,但是故障仍旧啊!
另外能请教一下如何来调试用Java Web框架开发的程序呢?
还有,我用的Eclipse虽然每次在改过代码后都clean一下,但是貌似还是有缓存未清空的现象,请问这个是什么原因?
非常感谢!

和VisualStudio差不多啊,你可以在代码里打断点,然后run debug server  就行了~ clean没有必要~ 服务器端代码每次运行都会重新编译~ 你留个邮箱我给你发个标准的struts2的demo。你照着看一下。 你有很多写的不规范的地方。
------解决方案--------------------
Eclipse项目要手动发布的,愚见。。
------解决方案--------------------
有可能是struts.xml位置有问题吧,看一下发布后的目录。。struts.xml是不是在WEB-INF\classes下面
------解决方案--------------------
web.xml 位置不对,应该放在web-inf 下