我正在学习struts2,运行第一例子时出现了问题,请高手帮忙看看,实在感谢。
我的开发环境是:MyEclipse 6.0.1,jdk1.6.0_05,tomcat6.0
web.xml代码如下:
<?xml version="1.0" encoding="GBK"?>
<web-app 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>struts2 </filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher </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="GBK"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml"> </include>
<package name="struts2" extends="struts-default">
<action name="Login" class="com.test.action.LoginAction">
<result name="error">/error.jsp </result>
<result name="success">/welcome.jsp </result>
</action>
</package>
</struts> LoginAction.java代码如下:
package com.test.action; public class LoginAction { 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
{
if(getUsername().equals("scott") && getPassword().equals("tiger"))
{
return "success";
}
else
{
return "error";
}
}
} login.jsp代码如下:
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<title>My JSP 'login.jsp' starting page </title>
</head>
<body>
<form action="Login.action" method="post">
<table align="center">
<tr>
<td>用户名: <input type="text" name="username"/> </td>
</tr>
<tr>
<td>密 码: <input type="text" name="password"/> </td>
</tr>
<tr align="center">
<td colspan="2"> <input type="submit" value="登录"/>
<input type="reset" value="重新输入"/> </td>
</tr>
</table>
</form>
</body>
</html> <%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<title>My JSP 'login.jsp' starting page </title>
</head>
<body>
<form action="Login.action" method="post">
<table align="center">
<tr>
<td>用户名: <input type="text" name="username"/> </td>
</tr>
<tr>
<td>密 码: <input type="text" name="password"/> </td>
</tr>
<tr align="center">
<td colspan="2"> <input type="submit" value="登录"/>
<input type="reset" value="重新输入"/> </td>
</tr>
</table>
</form>
</body>
</html> 我也编写了error.jsp和welcome.jsp代码 我启动服务器运行第一个页面成功,可在输入用户名和密码,点击登录按钮后,出现让我下载Login.action的对话框,请问这是什么原因,如何去解决,谢谢。
我的开发环境是:MyEclipse 6.0.1,jdk1.6.0_05,tomcat6.0
web.xml代码如下:
<?xml version="1.0" encoding="GBK"?>
<web-app 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>struts2 </filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher </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="GBK"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml"> </include>
<package name="struts2" extends="struts-default">
<action name="Login" class="com.test.action.LoginAction">
<result name="error">/error.jsp </result>
<result name="success">/welcome.jsp </result>
</action>
</package>
</struts> LoginAction.java代码如下:
package com.test.action; public class LoginAction { 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
{
if(getUsername().equals("scott") && getPassword().equals("tiger"))
{
return "success";
}
else
{
return "error";
}
}
} login.jsp代码如下:
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<title>My JSP 'login.jsp' starting page </title>
</head>
<body>
<form action="Login.action" method="post">
<table align="center">
<tr>
<td>用户名: <input type="text" name="username"/> </td>
</tr>
<tr>
<td>密 码: <input type="text" name="password"/> </td>
</tr>
<tr align="center">
<td colspan="2"> <input type="submit" value="登录"/>
<input type="reset" value="重新输入"/> </td>
</tr>
</table>
</form>
</body>
</html> <%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<title>My JSP 'login.jsp' starting page </title>
</head>
<body>
<form action="Login.action" method="post">
<table align="center">
<tr>
<td>用户名: <input type="text" name="username"/> </td>
</tr>
<tr>
<td>密 码: <input type="text" name="password"/> </td>
</tr>
<tr align="center">
<td colspan="2"> <input type="submit" value="登录"/>
<input type="reset" value="重新输入"/> </td>
</tr>
</table>
</form>
</body>
</html> 我也编写了error.jsp和welcome.jsp代码 我启动服务器运行第一个页面成功,可在输入用户名和密码,点击登录按钮后,出现让我下载Login.action的对话框,请问这是什么原因,如何去解决,谢谢。
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%> 写的对不对
<form action="Login.action" method="post">
中的action="Login.action" 匹配模式对么,后缀是.action吗