一 使用工具开发struts有两种方式
1 用工具引入struts包和配置文件,然后自己配置struts-config.xml,完成开发。或称半自动化。
2 完全依赖myeclipse提供的工具完成struts开发。或称全自动化。
二 实例——半自动化实现登录验证系统
1 使用工具建立web工程
2 导入struts开发包
自动引入struts开发包,自动生成struts-config.xml以及web.xml,并完成一些配置。
3 开发login.jsp页面
<%@ 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">
</head>
<body>
<form action="/strutstool1/login.do" method="post">
u:<input type="text" name="username"><br/>
p:<input type="password" name="password"><br/>
<input type="submit" value="login">
</form>
</body>
</html>
4 开发action和actionForm
LoginAction代码
package com.cakin.actions;
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.cakin.forms.UserForm;
public class LoginAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//把form转成对应的UserForm对象
UserForm userForm=(UserForm)form;
if("123".equals(userForm.getPassword())){
//把名字存放到request对象域
//request.setAttribute("username", userForm.getUsername());
return mapping.findForward("ok");
}
else{
return mapping.findForward("err");
}
}
}
UserForm代码
package com.cakin.forms;
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) {
System.out.println("actionservlet调用,传入用户"+username);
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
5 手动配置struts-config.xml文件
<?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="userForm" type="com.cakin.forms.UserForm"></form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/login" name="userForm" type="com.cakin.actions.LoginAction">
<forward name="ok" path="/WEB-INF/ok.jsp"></forward>
<forward name="err" path="/WEB-INF/err.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="com.cakin.struts.ApplicationResources" />
</struts-config>
6 开发ok.jsp和err.jsp
<%@ page language="java" import="java.util.*" import="com.cakin.forms.*" 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 'wel.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">
</head>
<body>
welcome <%=((UserForm)session.getAttribute("userForm")).getUsername() %> <br>
<a href="/strutslogin/">返回重新登录</a>
</body>
</html>
7 测试
8 上面的开发过程,可以提高我们的开发效率
相关推荐
python开发基于Opencv的CCM神经分割半自动化标注工具源码+项目使用说明.zip 1.准备数据集 在./sample文件夹中存放了一些CCM的图像,大小为384x484,其中感兴趣的区域为384x384。 2.边缘检测 ```python from ...
半自动化orm映射 数据的持久化到数据库
美术半自动化工具,加油 需要自己修改代码
# 声明:由于暂时未集成bat动态修改xml文件内容的方案,所有形成了半自动化注册服务工具,等集成此功能后,本系统会同步升级 # 声明:不方案仅为个人学习使用所创建,不计划用于商业用途,希望能对您产生帮助 # 如果...
一直不明白mybaitis根据pdm(powerdesign类型的文件)自动生成bean,mapper.xml,以及操作数据库的接口类,并没有看到接口类的实现,但是却可以正常使用操作数据库,觉得很神奇。今天模仿他们实现了一个简单的例子,并...
此工具适用于不能使用UNION SELECT的情况,通过自己构造语句,可以爆出任何想要的数据. 由于不能做到多线程,并且受制于PHP的max_execution_time最大为30秒, 因此在网络不给力的情况下无法爆出所有想要的字符. 此时...
半自动化钻床设计
工业半自动化数据采集终端解决方案.pdf工业半自动化数据采集终端解决方案.pdf工业半自动化数据采集终端解决方案.pdf工业半自动化数据采集终端解决方案.pdf工业半自动化数据采集终端解决方案.pdf工业半自动化数据采集...
半自动目标检测标注,但适用于只有一个目标且位置不变的情况
基于CodeQL实现的半自动化代码审计工具,目前仅支持java语言。实现从源码反编译
越权半自动化检测实践 威胁情报 安全威胁 系统安全 安全开发 法律法规
电信设备-一种半自动化使用QQ通讯的方法.zip
用于目标检测和实力分割的半自动化标注工具 实现思路: 对待标注图像使用现有网络生成检测结果(基于MMdetection); 将检测结果转为需要的标注文件格式(目前支持有labelImg标注的xml格式,labelme标注的json格式...
Shell半自动化同步(deb仓库)源码
基于领域的本体半自动化构建研究,单玮玮,周晓峰,本体半自动化构建是目前本体研究领域的一个重点和难点。随着信息检索、信息处理方面的飞快进展,能够在语义上给予支持的本体研究
半自动化摩擦力测量装置设计.pdf
半自动化简易颈部压力缓解装置.pdf
音视频数据半自动化标注方法.pdf
机械原理-半自动化钻床设计.doc
半自动化小广告纸处理器探析.pdf