环境:MyEclipse 14 发布时间: 2017-04-20 21:04:55
1 struts1 框架搭建
在MyEclipse新建web project 取名为struts1_login,此时是一个空文档就不截图了然后在project上右键->选择myeclipse->add struts capabilities
单击上面Install Apache Struts(1.x)Facet
点击next
选择*.do ,改下包名改成与你项目相关的。如我的包名为com.lichang.struts1
点击next
点击完成,在我们的WEB-INF下就会多出struts-config.xml文件
以上就是让myeclipse帮我们加入框架的大概过程。项目的整体结构如下:
至此我们的struts1 框架搭建完成
2 接着我们就开始编程来实现了。
web.xml 如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>struts1_login</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
- 然后在struts.xml配置LoginAction 代码如下:
-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="loginForm" type="com.lichang.struts1.LoginActionForm"/>
</form-beans>
<action-mappings>
<!-- path:指定访问时的路径 type:指定Action所在的类(一般是:包名.类名) name:指定和哪个表单(和jsp中Javabean
差不多的东西)对应,该例中name就和com.lichang.struts1.LoginActionForm类对应-->
<action path="/login"
type="com