1 创建day27的web应用
2 加入strust1.3相关的jar包到WEB-INF/lib/目录下(至少10个)
3 修改WEB-INF/web.xml和struts-config.xml文件
web.xml文件内容如下:
<web-app>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>[Struts1核心控制器默认接收的请求为*.do]
</servlet-mapping>
</web-app>
struts-config.xml文件内容如下:
<struts-config>
<action-mappings>
<action
path="/register"(用户请求的路径,/表示当前web应用,无需写.do)
type="cn.itcast.web.struts1.action.RegisterAction"/>(该请求由哪个分控制器处理)
</action-mappings>
</struts-config>
4 写一个register.jsp页面
<form action="/day27/register.do" method="post">
5 写一个分控制器RegisterAction.java,该分控制器一定要扩展Action类,覆写execute()方法
//分控制器
public class RegisterAction extends Action{
//覆写execute()方法
@Override
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
request.setCharacterEncoding("UTF-8");
String username = request.getParameter("username");
System.out.println("用户名:" + username);
return null;
}
}
6 部置该Web应用,访问register.jsp页面