1.开启“开发模式”:
<?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>
<span style="color:#ff0000;"> <!-- 启用开发模式,这样当代码发生变化时,能在浏览器页面立即响应,而不用重新启动服务器 -->
<constant name="struts.devMode" value="true"></constant>
</span>
<package name="helloWorld" extends="struts-default">
<action name="test" class="com.atguigu.struts2.helloworld.Product" method="test">
<result>/index.jsp</result>
</action>
</package>
</struts>
2.Struts2的类文件加载目录:D:/云盘同步文件夹/JAVA开发/JAR包/struts-2.3.15.3/src/core/src/main/java
3.Struts2的doc的加载目录:file:/D:/云盘同步文件夹/JAVA开发/JAR包/struts-2.3.30/docs/struts2-core/apidocs/
4.Struts2的DTD文件:http://struts.apache.org/dtds/struts-2.3.dtd
5.要用就用ActionSupport,即
public class Product extends ActionSupport {
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return super.execute();
}
}
6.文件路径问题
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<span style="color:#ff0000;"><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
</span>
<!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=UTF-8">
<span style="color:#ff0000;"><base href="<%=basePath%>"/>
</span><title>Insert title here</title>
</head>
<body>
<a href="product-input.action">Product Input</a>
<br><br>
<a href="test.action">Test</a>
</body>
</html>
7.动态方法调用(DMI)
8.用通配符匹配action标签
<action name="*_*" class="com.javaweb.struts2.action.{1}Action" method="{2}">
<result>/{1}_{2}.jsp</result>
</action>
9.Action接收参数的3种方式:
①.用setName()方法来赋值。
②用实体类来赋值。
③ModelDriver模型驱动接口来实现赋值。
10.中文乱码问题,在struts.xml文件中加入:
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
11.值栈的访问和使用。