Summary of common JSP Project Development Technologies

Source: Internet
Author: User

1. jquery submits a form in the form of post:

$. Ajax ({
Type: "Post ",
Async: false,
URL: "addbgnetdisk. Action ",
Data: $ ("# form1"). serialize (),
Success: function ()
{
SetTimeout ("parent. tb_remove (1); parent. Ts ()", 0 );
}
});

2. jquery obtains data in get mode and executes the callback function:

$. Ajax ({
URL: 'showschoolname. Action? Random = '+ math. Random (),
Async: false,
Type: 'get ',
Success: callback1
});
// Callback function
Function callback1 (DA)
{
VaR JSON = eval (DA );
VaR schoolname = JSON [0]. schoolname;
Document. getelementbyid ("systemname"). innerhtml = schoolname;
}

3. jquery obtains data in get mode and directly uses

VaR STR = $. Ajax ({URL: 'bmksjson. action', type: 'get', async: false, cache: false}). responsetext;

 

4. dynamically change the action method. Sometimes, for example, when the query result is displayed again after data retrieval, it seems that post must be used for submission, which is inconvenient to submit with Ajax.

VaR form = Document. getelementbyid ("form1 ");

Form. Action = "showaction. Action ";
Form. Submit ();

 

5. Eclipse prompts the import javax. servlet cannot be resolved

Import java. servlet. * In servlet; Where is the package?

This package is in Tomcat and is not in JDK.
Download Tomcat andJsp-api.jarAndServlet-api.jarYou can import these two packages to classpath.
The correct statement is import javax. servlet. *, instead of import java. servlet .*;

6. Example of iteration:

 

<S: If test = "# request. totalrows = 0">
<Tr class = "out" onmouseover = "highthis (this, 0)" onmouseout = "highthis (this, 1)">
<TD colspan = "6">
No query results
</TD>
</Tr>
</S: If>
<S: else>
<S: iterator value ="# Request. pagebean. querylist"Status =" rsdepartment "id =" department ">
<Tr class = "out" onmouseover = "highthis (this, 0)" onmouseout = "highthis (this, 1)">

<TD>
<S: If test = "Disabled = 0">
<Input id = "Chk" type = "checkbox" name = "Chk" value = "<s: property value =" bm_id "/>" onclick = 'oss (form) '/>
</S: If>
<S: else>
<Input id = "Chk" type = "checkbox" name = "Chk" Disabled = "disabled"/>
</S: else>
</TD>
<TD>
<S: property value = "# rsdepartment. index + 1"/>
</TD>
<TD>
<A Title = "department Introduction: <s: property value =" bmjj "/>"> <s: property value = "BMMC"/> </a>
</TD>
<TD>
<A href = 'strsks. Action? Id = <s: property value = "bm_id"/>'
Target = "_ Self"> maintenance department </a>
</TD>
<TD>
<Input type = "text" value = <s: property value = "sort_id"/>
Style = "width: 50px"
Onkeyup = "If (/[^ 0-9]/g. test (this. value) {This. value = This. value. substr (0, this. value. length-1 )}"
Id = "<s: property value =" bm_id "/>"/>
</TD>
<TD>
<Input class = "button_edit" type = "button" value = "" Title = "modify" style = "cursor: Pointer"
Onclick = "modifybm (<s: property value =" bm_id "/>)"/>
<S: If test = "Disabled = 0">
<Input class = "button_del" type = "button" value = "" Title = "delete" style = "cursor: Pointer"
Onclick = "delbm (<s: property value =" bm_id "/>)"/>

</S: If>
<S: else>
<Input class = "button_nodel" type = "button" value = ""
Disabled = "disabled" Title = "this department has lower-level departments or personnel. You cannot delete this department. "/>
</S: else>
</TD>
</Tr>
</S: iterator>
</S: else>

 7,

Obtain request from struts2

 

Obtain Request Method 1 in action:
Code in action:
Map request = (MAP) actioncontext. getcontext (). Get ("request ");
List <task> tasks = TASKMANAGER. findall ();
Request. Put ("Tasks", tasks );
Obtain the value on the JSP page:
<S: iterator id = "task" value = "# request. Tasks">
<Tr class = "table_header">
<TD> <s: property value = "# task. tname"/> </TD>
<TD> <s: property value = "# task. tuid"/> </TD>
<TD> <s: property value = "# task. tstarttime"/> </TD>
<TD> <s: property value = "# task. tendtime"/> </TD>
<TD> <s: property value = "# task. tstate"/> </TD>
<TD> <input type = "radio" id = "choose" name = "choose" onclick = "GETID (this. value) "value =" <s: property value = '# task. tid'/> "/> </TD>
</Tr>
</S: iterator>
Bytes --------------------------------------------------------------------------------------------

 

Method 2: Use the servletactioncontext class to obtain
Code in action:
Httpservletrequest request = servletactioncontext. getrequest ();
Request. setattribute ("username", "zhangsan ");
Obtain the value in JSP.
<S: property value = "# request. username"> or $ {requestscope. req}

Bytes --------------------------------------------------------------------------------------------
Method 3: Use the servletrequestaware interface to inject the request object through the IOC Mechanism
Code in action:
Action implements the servletrequestaware interface and the methods in the interface
Private httpservletrequest request;
// Method in the implementation Interface
Public void setservletrequest (httpservletrequest request ){
This. Request = request;
}
// You can use it in the execute () method.
Public String execute (){
Request. setattribute ("username", "zhangsan ");
Request. getsession (). getservletcontext (). getapplication (); // obtain the application
}
This method must be implemented and is automatically called.
When this method is called, it will pass the created request object to you through parameters. You can assign it to the variables in this class, and then the request can be used.
Note: The setservletrequest () method will be executed before the execute () method is called.
Obtain the value on the JSP page.
<S: property value = "# request. task. tname"/>

 

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.