success

Struts框架登录示例
<%--
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" src="jquery.js"></script>
<script type="text/javascript">
function showImage(value){
var img =document.getElementById("img");
switch(value){
case "t1":
img.src = "1.jpg";
break;
case "t2":
img.src = "2.jpg";
break;
case "t3":
img.src = "3.jpg";
break;
}
//ajax(value)

$.ajax({
url: "http://localhost:8888/discuz_ucenter_api_for_java/Executer.do",
success: function(data){
alert("成功 "+data+" !");
},
data: "timeId="+value,
error:function(){
alert("error");
}
});
}
</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>
<img width="50" alt="" src="" name="img" height="50">
</body>
</html>
-------------------------------------
package com.vaannila;

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;

public class ExecuterAction extends Action{

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("ExecuterAction.execute()");
String timeId = request.getParameter("timeId");
if("".equals(timeId)){
}
response.getWriter().print("sdfsdafdsaf"+timeId);
return super.execute(mapping, form, request, response);
}
private String getC(){
// db operator
return "C";
}

}
---------------------------------
/*
* 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);
}
}


}
在系统、API或操作中,"status"和"success"通常用于描述程序执行的结果或当前状态。以下是对这两个术语的具体信息和实现方式的探讨: ### 1. 系统或程序执行状态(Status) 在程序执行过程中,状态码用于指示操作是否成功完成。例如,在C语言中,`EXIT_SUCCESS` 和 `0` 都表示程序成功执行完毕。尽管 `EXIT_SUCCESS` 不一定等于 `0`,但它们都表示程序的执行是成功的。通过返回不同的状态码,可以提供更详细的执行结果信息,尤其是在调试或自动化脚本中非常有用[^2]。 ```c #include <stdio.h> #include <stdlib.h> int main(void) { FILE *fp = fopen("data.txt", "r"); if (fp == NULL) { fprintf(stderr, "fopen() failed in file %s at line # %d\n", __FILE__, __LINE__); exit(EXIT_FAILURE); } /* Normal processing continues here. */ fclose(fp); printf("Normal Return\n"); return EXIT_SUCCESS; } ``` ### 2. API 成功状态(Success) 在网络请求或API调用中,状态码用于指示请求的成功或失败。例如,HTTP协议中的状态码200表示请求成功,而404表示资源未找到。API设计中通常会返回特定的状态码以及描述信息,以帮助客户端理解请求的结果。例如,RESTful API通常会返回JSON格式的响应,包含状态码和消息。 ```json { "status": "success", "message": "Operation completed successfully.", "data": { "id": 1, "name": "Example" } } ``` ### 3. 实现方式 在实现状态和成功处理时,可以通过定义常量或枚举来表示不同的状态码,以提高代码的可读性和可维护性。此外,可以使用日志记录工具来记录详细的执行信息,以便于调试和监控。 ```python class OperationStatus: SUCCESS = 0 FAILURE = 1 def perform_operation(): try: # Simulate a successful operation print("Operation started.") # Perform some operations print("Operation completed.") return OperationStatus.SUCCESS except Exception as e: print(f"Operation failed: {e}") return OperationStatus.FAILURE result = perform_operation() if result == OperationStatus.SUCCESS: print("The operation was successful.") else: print("The operation failed.") ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值