struts教程笔记2

使用工具开发struts,用工具导入struts开发包,手动配置

struts-config.xml

1.建立web工程
2.导入struts开发包
3.开发login.jsp
4.开发action和actionForm
5.开发ok.jsp和err.jsp
6.测试

半自动可以提高开发效率

完全依赖myEclipse工具开发struts

1.建立web工程
2.引入struts capabilities
3.创建login.jsp
4.用struts-config.xml design界面创建userForm表单
5.创建action
6.ok.jsp err.jsp
7.在action中添加业务逻辑

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
使用工具开发struts,用工具导入struts开发包,手动配置

struts-config.xml

1.建立web工程
2.导入struts开发包
3.开发login.jsp
4.开发action和actionForm
5.开发ok.jsp和err.jsp
6.测试

半自动可以提高开发效率

完全依赖myEclipse工具开发struts

1.建立web工程
2.引入struts capabilities
3.创建login.jsp
4.用struts-config.xml design界面创建userForm表单
5.创建action
6.ok.jsp err.jsp
7.在action中添加业务逻辑

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

version="2.4" 

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <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>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software 

Foundation//DTD Struts Configuration 1.2//EN" 

"http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
  <data-sources />
  <form-beans >
    <form-bean name="userForm" 

type="com.xinghua.struts.form.UserForm" />

  </form-beans>

  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action
      attribute="userForm"
      input="/WEB-INF/login.jsp"
      name="userForm"
      path="/login"
      scope="request"
      type="com.xinghua.struts.action.LoginAction"
      validate="false" >
      <forward name="err" path="/WEB-INF/err.jsp" />
      <forward name="ok" path="/WEB-INF/ok.jsp" />
    </action>


  </action-mappings>

  <message-resources 

parameter="com.xinghua.struts.ApplicationResources" />
</struts-config>

<%@ page language="java" import="java.util.*" 

pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme

()+"://"+request.getServerName

()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 

Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-

cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" 

content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is 

my page">
	<!--
	<link rel="stylesheet" type="text/css" 

href="styles.css">
	-->
  </head>
  
  <body>
    <jsp:forward page="/WEB-INF/login.jsp"></jsp:forward>
  </body>
</html>
<%@ page language="java" import="java.util.*" 

pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme

()+"://"+request.getServerName

()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 

Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'login.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-

cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" 

content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is 

my page">
	<!--
	<link rel="stylesheet" type="text/css" 

href="styles.css">
	-->

  </head>
  
  <body>
    <form action="/strutsTools2/login.do" method="post">
    username:<input type="text" name="username"><br/>
    password:<input type="password" name="password"><br/>
    <input type="submit" value="login">
    </form>
  </body>
</html>


<%@ page language="java" import="java.util.*" 

pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme

()+"://"+request.getServerName

()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 

Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'err.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-

cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" 

content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is 

my page">
	<!--
	<link rel="stylesheet" type="text/css" 

href="styles.css">
	-->

  </head>
  
  <body>
    err <br>
  </body>
</html>
<%@ page language="java" import="java.util.*" 

pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme

()+"://"+request.getServerName

()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 

Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'ok.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-

cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" 

content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is 

my page">
	<!--
	<link rel="stylesheet" type="text/css" 

href="styles.css">
	-->

  </head>
  
  <body>
    ok<br>
  </body>
</html>
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.xinghua.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.xinghua.struts.form.UserForm;

/** 
 * MyEclipse Struts
 * Creation date: 02-20-2020
 * 
 * XDoclet definition:
 * @struts.action path="/login" name="userForm" 

scope="request"
 */
public class LoginAction extends Action {
	/*
	 * Generated Methods
	 */

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping 

mapping, ActionForm form,
			HttpServletRequest request, 

HttpServletResponse response) {
		UserForm userForm = (UserForm) form;// 

TODO Auto-generated method stub
		
		if("123".equals(userForm.getPassword())){
			return mapping.findForward("ok");
		}else return mapping.findForward("err");
	}
}

/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.xinghua.struts.form;

import org.apache.struts.action.ActionForm;

/** 
 * MyEclipse Struts
 * Creation date: 02-20-2020
 * 
 * XDoclet definition:
 * @struts.form name="userForm"
 */
public class UserForm extends ActionForm {
	/*
	 * Generated fields
	 */

	/** password property */
	private String password;

	/** username property */
	private String username;

	/*
	 * Generated Methods
	 */

	/** 
	 * Returns the password.
	 * @return String
	 */
	public String getPassword() {
		return password;
	}

	/** 
	 * Set the password.
	 * @param password The password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/** 
	 * Returns the username.
	 * @return String
	 */
	public String getUsername() {
		return username;
	}

	/** 
	 * Set the username.
	 * @param username The username to set
	 */
	public void setUsername(String username) {
		this.username = username;
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值