login.jsp 部分代码:
<INPUT class="ipt" id="name" name="name" type="text" placeholder="请输入用户名或邮箱" value="">
<INPUT class="ipt" id="password" name="passwrod" type="password" placeholder="请输入密码" value="">
<input type="submit" value="登录" onclick="login()">
<SCRIPT>
function login(){
alert("begin");
$.post("LoginAction.action",{"name":$("#name").val(),"password":$("#password").val()},function(data){
alert('ok');},"json");
alert("end");
}
</SCRIPT>
web.xml配置主要代码
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>struts.i18n.encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
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>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
<package name="user" extends="struts-default, json-default">
<action name="LoginAction" class="com.xml.actions.LoginAction" method="execute">
<result>/bottom.jsp</result>
</action>
</package>
</struts>
LoginAction类代码
package com.xml.actions;
import com.opensymphony.xwork2.ActionSupport;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
public class LoginAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private String name;
private String password;
public String execute()
{
System.out.println("you have enterd the action");
System.out.println(name+" "+password);
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
导入的Struts包:
运行了之后,根本跳转不到bottom.jsp里面
求解!!!!!