Action文件:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.vaannila;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.LabelValueBean;
import org.apache.struts.util.MessageResources;
/**
*
* @author eswar@vaannila.com
*/
public class LoginAction extends org.apache.struts.action.Action {
/* forward name="success" path="" */
private final static String SUCCESS = "success";
private final static String FAILURE = "failure";
/**
* This is the action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
* @throws java.lang.Exception
* @return
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
LoginForm loginForm = (LoginForm) form;
MessageResources messageResources = getResources(request);
String s1 = messageResources.getMessage("t");
String[] strList = s1.split(",");
List<LabelValueBean> valueBeans = new ArrayList<LabelValueBean>();
for (String key : strList) {
System.out.println("key : "+key+" value : "+messageResources.getMessage(key));
valueBeans.add(new LabelValueBean(messageResources.getMessage(key),key));
}
request.setAttribute("mtypelist", valueBeans);
if (loginForm.getUserName().equals(loginForm.getPassword())) {
return mapping.findForward(SUCCESS);
} else {
return mapping.findForward(FAILURE);
}
}
}
-------------------------------------
javaForm文件:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.vaannila;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
/**
*
* @author eswar@vaannila.com
*/
public class LoginForm extends org.apache.struts.action.ActionForm {
private String userName;
private String password;
private String timeId;
/**
*
*/
public LoginForm() {
super();
// TODO Auto-generated constructor stub
}
/**
* This is the action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param request The HTTP Request we are processing.
* @return
*/
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (userName == null || userName.length() < 1) {
errors.add("userName", new ActionMessage("error.userName.required"));
// TODO: add 'error.name.required' key to your resources
}
if (password == null || password.length() < 1) {
errors.add("password", new ActionMessage("error.password.required"));
// TODO: add 'error.name.required' key to your resources
}
return errors;
}
/**
* @return the userName
*/
public String getUserName() {
System.out.println("Inside getter "+userName);
return userName;
}
/**
* @param userName the userName to set
*/
public void setUserName(String userName) {
System.out.println("Inside setter "+userName);
this.userName = userName;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
public String getTimeId() {
return timeId;
}
public void setTimeId(String timeId) {
this.timeId = timeId;
}
}
-------------------------
资源文件:
t=t1,t2,t3,t4,t5,t6,t7
t1=hour
t2=day
t3=week
t4=tttt4
t5=tttt5
t6=tttt6
t7=tttt7
--------------------------------------
jsp文件:
<%--
Document : success
Created on : Dec 15, 2008, 4:08:53 AM
Author : eswar@vaannila.com
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<!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>JSP Page</title>
<script type="text/javascript">
function showImage(value){
alert(value);
}
</script>
</head>
<body>
<h1>Login Success. Welcome <bean:write name="LoginForm" property="userName"></bean:write></h1>
<html:select name="LoginForm" property="timeId" onchange="showImage(this.value)">
<!--mtypelist为request中设置的属性值 labelProperty="label" property="value"固定写法-->
<html:options collection="mtypelist" labelProperty="label" property="value" />
</html:select>
</body>
</html>
分享到:
相关推荐
请查收、请查收、请查收、文档代码、一般人俺不告诉他。很容易上手
小小消防员.zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码小小消防员.zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码小小消防员.zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码小小消防...
将单位所有的人员名换成拼音,不用发愁,小小代码帮你搞定
关于旅游的小小代码,希望朋友们借鉴下,帮我修改修改,真心希望
小小记事本(C#代码编写) 小小记事本是仿Woindow记事本的程序,功能同Woindow记事本, 代码基本完善。运行在FrameWork2.0平台以上。 本程序经多次调试,可以使用。如有bug,请与我联系,谢谢。
此 小小黑客之路代码 为无毒版,功能测试正常,无毒请放心下载。
C++实验课程书中的实验------小小图书馆源代码下载
java课程设计源代码,小小画图板的开发 大学课程设计用这个很不错..原代码
俩游戏角色,初始经验 初始血的数量 经过打斗最后判断打斗次数及输赢。代码比较简单,适合java初学者。
dos下使用gui界面的4个小小源代码
用C写的代码,大家用visual c++打开后调试,可以看到流星雨效果
小小矩阵计算器——源代码,供大家相互学习
小小记事本C#源代码,摸拟windows记事本
25--[小小企鹅].zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码25--[小小企鹅].zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码25--[小小企鹅].zip源码scratch2.0 3.0编程项目源文件源码案例素材源...
26--[小小赛车].zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码26--[小小赛车].zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码26--[小小赛车].zip源码scratch2.0 3.0编程项目源文件源码案例素材源...
2--[小小计算器].zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码2--[小小计算器].zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码2--[小小计算器].zip源码scratch2.0 3.0编程项目源文件源码案例...
76--[小小画笔].zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码76--[小小画笔].zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码76--[小小画笔].zip源码scratch2.0 3.0编程项目源文件源码案例素材源...
这个小小的例子是我们入门vue的入门基础 ,同志们可以去学习了解
具有浏览器的功能的源代码 连接 前进 后退 刷新 返回主页 简单实用
用于研究代码的编辑,可供参考哦,希望采纳