我用Struts2做了一个登录程序,index.jsp是这样的
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Login</title>
</head>
<body>
<s:form action="Login" method="POST">
<s:textfield name="user.username" label="User name"/>
<s:password name="user.password" label="Password"/>
<s:submit value="Submit"/>
</s:form>
</body>
</html>
struts.xml是这样的
<!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" />
<package name="package1" extends="struts-default">
<action name="Login" class="org.fcb.login.action.LoginAction">
<result name="SUCCESS">HelloWorld.jsp</result>
<result name="ERROR">error.jsp</result>
</action>
</package>
</struts>
web.xml是这样的
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Struts 2.0 Hello World</display-name>
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
此外还有个user bean类
private String name ;
private String passWord ;
还有个action
package org.fcb.login.action;
import org.fcb.login.vo.User;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class LoginAction extends ActionSupport {
private User user = new User() ;
private String message ;
public String getMessage()
{
return message;
}
@Override
public String execute() throws Exception
{
if("max".equals(user.getName())&&"123456".equals(user.getPassWord()))
{
message = "欢迎光临!!! " ;
return ActionSupport.SUCCESS ;
}else
{
message = "用户名或密码错误" ;
return ActionSupport.ERROR ;
}
}
}
结果报错
警告: Internal Error: File /WEB-INF/web.xml not found
2007-9-10 21:47:29 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: File "/struts-tags" not found
.......
我把struts2所有的包都导进去了