Struts入门—基本配置
1、导入jar包
2、配置web.xml文件
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "dtd\web-app_2_3.dtd"> <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> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>2</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
3、配置struts-config.xml文件,放在WEB-INF目录下
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> <struts-config> <form-beans> <form-bean name="userinfo" type="test.UserInfoBean"/> </form-beans> <global-forwards> <forward name="success" path="/test/success.jsp" redirect="false" /> </global-forwards> <action-mappings> <action path="/login" type="test.TestAction" name="userinfo"/> </action-mappings> </struts-config>
4、登录页面
<form id="userinfo" name="userinfo" action="<%=request.getContextPath()%>/login.do" method="post"> 用户名:<input id="username" type="text" name="userName"/><br/> 密 码:<input id="password" type="password" name="password"/><br/> <input id="submit" type="submit" value="登 录"/> </form>
5、Action:继承org.apache.struts.action.Action,重写execute()方法
6、Bean需要继承org.apache.struts.action.ActionForm
相关推荐
lantingyue 2020-07-30
Kafka 2020-09-18
Wepe0 2020-10-30
杜倩 2020-10-29
windle 2020-10-29
minerd 2020-10-28
mengzuchao 2020-10-22
Junzizhiai 2020-10-10
bxqybxqy 2020-09-30
风之沙城 2020-09-24
kingszelda 2020-09-22
大唐帝国前营 2020-08-18
yixu0 2020-08-17
TangCuYu 2020-08-15
xiaoboliu00 2020-08-15
songshijiazuaa 2020-08-15
xclxcl 2020-08-03
zmzmmf 2020-08-03
newfarhui 2020-08-03