`

Struts1基本配置

阅读更多

以下记录Struts1基本配置。

一、下载Struts1.3

链接如下:http://struts.apache.org/download.cgi#struts1310

二、拷贝lib下面的所有包到项目WEB-INF\LIB下。

三、修改web.xml内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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>TestStruts</display-name>
	<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>
	</servlet>
	<servlet-mapping>
		<servlet-name>action</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
	
	<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>
</web-app>

 

四、在WEB-INF下新建struts-config.xml文件内容如下。

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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="logonForm" type="com.lwf.struts.form.UserForm"></form-bean>
    </form-beans>

    <global-exceptions>
        <!-- sample exception handler
        <exception
            key="expired.password"
            type="app.ExpiredPasswordException"
            path="/changePassword.jsp"/>
        end sample -->
    </global-exceptions>

    <global-forwards>
        <!-- Default forward to "Welcome" action -->
        <!-- Demonstrates using index.jsp to forward -->
        <forward
            name="welcome"
            path="/Welcome.do"/>
    </global-forwards>

    <action-mappings>
         <action 
         	path="/logon"
         	type="com.lwf.struts.action.LogonAction"
         	name="logonForm"
         	input="/input.jsp"
         	scope="session"
         	validate="false"
         >
         <forward name="resultForward" path="/result.jsp"></forward>
         </action>
    </action-mappings>


<!-- ======================================== Message Resources Definitions -->

    <message-resources parameter="MessageResources" />


<!-- =============================================== Plug Ins Configuration -->

  <!-- ======================================================= Tiles plugin -->
  <!--
     This plugin initialize Tiles definition factory. This later can takes some
	 parameters explained here after. The plugin first read parameters from
	 web.xml, thenoverload them with parameters defined here. All parameters
	 are optional.
     The plugin should be declared in each struts-config file.
       - definitions-config: (optional)
            Specify configuration file names. There can be several comma
		    separated file names (default: ?? )
       - moduleAware: (optional - struts1.1)
            Specify if the Tiles definition factory is module aware. If true
            (default), there will be one factory for each Struts module.
			If false, there will be one common factory for all module. In this
            later case, it is still needed to declare one plugin per module.
            The factory will be initialized with parameters found in the first
            initialized plugin (generally the one associated with the default
            module).
			  true : One factory per module. (default)
			  false : one single shared factory for all modules
	   - definitions-parser-validate: (optional)
	        Specify if xml parser should validate the Tiles configuration file.
			  true : validate. DTD should be specified in file header (default)
			  false : no validation

	  Paths found in Tiles definitions are relative to the main context.

      To use this plugin, download and add the Tiles jar to your WEB-INF/lib
      directory then uncomment the plugin definition below.

    <plug-in className="org.apache.struts.tiles.TilesPlugin" >

      <set-property property="definitions-config"
                       value="/WEB-INF/tiles-defs.xml" />
      <set-property property="moduleAware" value="true" />
    </plug-in>
  -->  


  <!-- =================================================== Validator plugin 

  <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property
        property="pathnames"
        value="/org/apache/struts/validator/validator-rules.xml,
               /WEB-INF/validation.xml"/>
  </plug-in>
-->
</struts-config>

 

五、新建UserForm类文件

package com.lwf.struts.form;

import org.apache.struts.action.ActionForm;

public class UserForm extends ActionForm{

	private String userName;
	private String password;
	
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	
}

 

 

新建LogonAction文件

package com.lwf.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.lwf.struts.form.UserForm;

public class LogonAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		UserForm userForm = (UserForm)form;
		String name = userForm.getUserName();
		String pwd = userForm.getPassword();
		
		
		return mapping.findForward("resultForward");
	}

}

 

六、新建所需的index.jsp, result.jsp,logon.jsp三个文件

index.jsp如下

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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">
<title>Insert title here</title>
</head>
<body>
<%
	out.print(new java.util.Date());
%>
<table>
	<tr><td><a href="./Logon.jsp">Logon</a></td></tr>
</table>
</body>
</html>

 

logon.jsp如下。

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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">
<title>Insert title here</title>
</head>
<body>
<form action="logon.do">
	UserName:<input type="text" name="userName"></input>
	Password:<input type="text" name="password"></input>
	<input type="submit" name="submit"></input>
</form>
</body>
</html>

 

result.jsp如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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">
<title>Insert title here</title>
</head>
<body>
result
</body>
</html>

 

运行程序,最终结果返回到result.jsp,显示result.

 

 

附件为代码:

分享到:
评论

相关推荐

    struts2基本配置

    ### Struts2基本配置知识点详解 #### 一、Struts2概述 - **定义与作用**:Struts2是Apache组织开发的一个开源Web应用框架,主要用于简化Java Web应用程序的开发。Struts2作为MVC(Model-View-Controller)模式的一...

    java-struts2基本配置使用手册.doc

    Java Struts2 基本配置使用手册 Struts2 是一个基于 Java 语言的 Web 框架,作为 MVC 2 模型的 Web 框架,Struts2 自推出以来不断受到开发者的追捧,得到广泛的应用。Struts2 的主要优点包括:MVC 2 模型的使用、...

    语言程序设计资料:struts2基本配置使用手册.doc

    Struts 2.0 基本配置使用手册 Struts 2.0 作为一款功能强大且广泛应用的 Web 框架,其优点包括 MVC 2 模型的使用、功能齐全的标志库(Tag Library)和开放源代码。然而,Struts 也存在一些缺点,如需要编写的代码...

    struts2 Https 配置

    1. **配置服务器**:首先,你需要在服务器端(如Tomcat、Jetty等)启用HTTPS。这通常涉及到修改服务器的配置文件(如Tomcat的`server.xml`),添加一个监听443端口的SSL连接器。你需要提供一个有效的SSL证书,这可以...

    struts2 基本配置

    它的基本配置是理解和使用Struts2的关键步骤,对于初学者来说尤其重要。以下将详细介绍Struts2的基本配置及其相关知识点。 一、Struts2的核心组件 Struts2的核心组件包括Action、Result、Interceptor(拦截器)等。...

    struts1 mvc基本原理

    本文将深入探讨Struts1的基本原理,帮助理解其架构设计和工作流程。 **1. MVC架构** MVC模式是软件工程中一种用于分离业务逻辑、数据和用户界面的设计模式。在Struts1中,Model代表应用程序的数据和业务逻辑,View...

    struts基本配置

    在Struts的基本配置中,有以下几个关键组件和概念: 1. **struts-config.xml**:这是Struts的核心配置文件,它定义了Action和ActionForm,以及Action的映射路径。例如: ```xml ``` 这段配置表示当用户...

    struts2的配置信息

    理解了lib目录后,我们转向“struts2的基本配置”。Struts2的配置主要分为两部分:XML配置和注解配置。在典型的`struts-default.xml`和`struts.xml`配置文件中,你可以定义Action、结果类型、拦截器栈等。 1. **...

    ·Struts2配置文件介绍 超级详细

    - **struts-default.xml**:这是Struts2框架提供的默认配置文件,包含了一些基本的拦截器和结果类型的定义。当开发者未在自己的`struts.xml`中指定某些配置时,默认会采用这些预定义的配置。 #### 二、struts.xml...

    struts2基本运行环境配置方法

    Web应用程序部署描述符(web.xml)是Java Web应用的关键组成部分,它包含了应用程序的基本配置信息。为了使Struts2框架能够正常工作,需要在web.xml中配置Filter。 ```xml xmlns:xsi=...

    struts2.0基本配置包类

    在这个“struts2.0基本配置包类”中,我们很可能会发现一系列用于搭建基础Struts2环境的核心类和配置文件。下面将详细介绍这些知识点。 1. **Action类**:在Struts2中,业务逻辑通常由Action类执行。开发者需要创建...

    Eclipse Struts基本配置步骤

    本篇文章将详细介绍在Eclipse中进行Struts基本配置的步骤,帮助开发者构建和管理Struts应用。 首先,我们需要准备必要的库文件,这些文件在提供的压缩包中已经包含: 1. struts2-core-2.0.14.jar - Struts2的核心库...

Global site tag (gtag.js) - Google Analytics