The relationship between saving and modifying in JSP action _JSP programming

Source: Internet
Author: User

Code fragment in action

Copy Code code as follows:

private string epid;//global variable gets a comma-delimited string
Public String Getepid () {
return epid;
}

public void Setepid (String epid) {
This.epid = Epid;
}

Public String edit () {
try {
if ("Save". Equals (Save)) {//Click the Save button to execute
return save ();
} else {
Loadinfo ();
return return_edit;
}
catch (Exception e) {
Super.printerrors (This.getrequest (), E, className);
return return_error;
}
}

private void Loadinfo () throws Exception {
Epid = This.getrequest (). GetParameter ("id");//Get a single epid
Long UserID = Getloginuser (). GetUser (). GetUserID ();
/**
Function:
Get a single object and put each object in a Vo object
The value of the data displayed in the page

**/

EP EP = New EP ();
Ep.setid (Long.parselong (epid));
EP = Epservice.getepbyid (EP);
Epvo.setep (EP);
Depart objects
Depart depart = new Depart ();
Depart.setdeptid (Ep.getdeptid ());
Depart.setplatenumber (Ep.getname ());
Depart.setcreateby (userid);
Depart.setjudgetype (Integer.parseint ("0"));
String str[] = Ep.getinfo (). Split (";");
String S1 = "";
for (int i = 0; i < str.length; i++) {
S1 = str[0];
}

if ("". Equals (S1) | | NULL = = S1) {
Depart.setroute ("no route");
} else {
Depart.setroute (S1);
}
Epvo.setdepart (depart);
Dept Objects
Dept Dept = new Dept ();
Dept = Deptservice.getdeptbyid (Ep.getdeptid ());
Epvo.setdept (dept);

}


Public String Save () {

Long DeptID = Epvo.getdept (). Getdeptid ();
try {
Depart depart = Epvo.getdepart ();
Depart.setdeptid (DeptID);

Departservice.insertdepart (depart);
Super.printmsg (This.getrequest (), "Save success!");

Cleanobject ();
catch (Exception e) {
Super.printerrors (This.getrequest (), E, className);
return return_error;
}

return list ();
}

Jap page

Copy Code code as follows:

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%>
<%@ taglib uri= "/struts-tags" prefix= "s"%>
<%@ taglib uri= "/web-inf/web.tld" prefix= "WEB"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> Revise payment information </title>
<web:jquery validate= "true" formid= "Tableform"/>
<link type= "Text/css" rel= "stylesheet" href= "Styles/css.css" >
<script language= "javascript" type= "Text/javascript" src= "Scripts/datepicker/wdatepicker.js" ></script >
<script language= "javascript" type= "Text/javascript" src= "Scripts/globals.js" ></script>
<body>
<form action= "" method= "POST" id= "Tableform" name= "Tableform" >
<web:error/>
<web:tabletitle name= "Revise payment information information"/>
<s:hidden name= "EpVO.dept.deptid" id= "DeptID"/>//hide the values passed over
<s:hidden name= "EpVO.depart.createBy"/>
<s:hidden name= "id"/>
<div class= "Table_border" >
<table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" class= "HS" >

</table>
</div>
<div class= "T_center" >
<input id= "submitbtn" type= "Submit" value= "Save" style= "Display:none"/>
<a href= "#" class= "Sava_b B" onclick= "Save ()" > Save </a>
</div>
</form>
</body>

<script language= "JavaScript" type= "Text/javascript" >
Save
function Save () {
var obj = document.getElementById ("Tableform");
obj.action = ' <s:property value= ' #request. Saveurl "/>";
var submitbtn = document.getElementById ("submitbtn");
Submitbtn.click ()//Through JS Time Control commit Events
}
Show
function query () {
window.location.href= ' <s:url value= '/listep.action '/> ';
}
Load Date Control
$ (document). Ready (function () {
Addformvalidator ();
$ ("#sendTime"). attr ("ReadOnly", "ReadOnly");
$ ("#sendTime"). Click (function () {Wdatepicker ({isshowclear:false,datefmt: ' Yyyy-mm-dd HH:mm:ss '});
});

</script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.