使用工具开发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中添加业务逻辑
<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>actionservlet-name>
<servlet-
class>org.apache.struts.action.ActionServletservlet-
class>
<init-param>
<param-name>configparam-name>
<param-value>/WEB-INF/struts-config.xmlparam-
value>
init-param>
<init-param>
<param-name>debugparam-name>
<param-value>3param-value>
init-param>
<init-param>
<param-name>detailparam-name>
<param-value>3param-value>
init-param>
<load-on-startup>0load-on-startup>
servlet>
<servlet-mapping>
<servlet-name>actionservlet-name>
<url-pattern>*.dourl-pattern>
servlet-mapping>
<welcome-file-list>
<welcome-file>index.jspwelcome-file>
welcome-file-list>
web-app>
<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+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting pagetitle>
<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">
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+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'login.jsp' starting pagetitle>
<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">
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+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'err.jsp' starting pagetitle>
<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">
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+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'ok.jsp' starting pagetitle>
<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">
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;
}
}