struts2.0中应注意的问题

注意下面的几个问题做个简单的CRUD应该不是什么问题
http://localhost:8080/struts_2/login.jsp 或http://localhost:8080/struts_2/login.action
1   添加.jar   ^_^
commons-logging-1.0.4.jar,freemarks-2.3.8.jar,ognl-2.6.11.jar,xwork-2.0.4.jar
       简单记忆方法:4 7 8 12  -1
2 在src下添加struts.xml 和struts-2.
在struts-2.0.9\src\core\src\main\resources\struts-2.0.dtd找

3   struts.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "struts-2.0.dtd"> //删除掉http://........就可以找到dtd了
<struts>
<package name="struts_2"  extends="struts-default" >//必须继承struts-default
<action name="login" class="com.xaccp.action.UserAction" method="login">
//这个name是和jsp页面中action的值一样的      //**Action的方法名一样     
<result>ok.jsp</result>
</action>
</package>
</struts>
4  login.jsp :
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %> //在jsp页面的头部添加struts2的标签库
<body>
    <s:form action="login">
    <s:textfield name="vo.uname" label="uname"/> //name="对象名.属性"
     //name的值是**Action中vo对象的对象名
    <s:password name="vo.upass" label="upass" />
    <s:submit value="login"/>
    <s:reset value="reset"/>
    </s:form>
</body>

5 UserAction.java :
public class UserAction extends ActionSupport {
private UserVo vo ;
public UserVo getVo() {
return vo;
}
public void setVo(UserVo vo) {
this.vo = vo;
}
public String login() {
System.out.println("i love u " + vo.getUname() + ", your pass is " + vo.getUpass());
return SUCCESS;
}
}

6  web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<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">
<display-name>这地方写描述</display-name>
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
//注意这地方必须是FilterDispatcher
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>   
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>//欢迎页面
    </welcome-file-list>
</web-app>

你可能感兴趣的:(apache,jsp,Web,xml,struts)