Flex Access Session

Source: Internet
Author: User

In fact, I think we all know what is going on, but I still take out write, consolidate the knowledge, if someone is not clear can look.

Example: my example is the user login, the user first click the login button to determine the success of the login by verifying the account password (here I assume the same account password for landing success), the user second click the login button to determine whether the account is empty, of course, my example is a bit inappropriate ha.

Now let's write the code one step at a time:

1) First to write Loginservlet.java

1 Package servlet;
2
3 import java.io.IOException;
4 import Java.io.PrintWriter;
5
6 import javax.servlet.ServletException;
7 import Javax.servlet.http.HttpServlet;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10 import javax.servlet.http.HttpSession;
11
12 Public class Loginservlet extends httpservlet {
13
14 Public void doPost (httpservletrequest request, httpservletresponse response)
15 Throws Servletexception, IOException {
16 String account = Request.getparameter ("account");
17 String password = request.getparameter ("password");
18 HttpSession session = Request.getsession ();
19 string useraccount = (string) Session.getattribute ("UserAccount");
20 PrintWriter out = Response.getwriter ();
21st if (useraccount!=null) {
22
23 Out.print ("Congratulation" +useraccount+ ", you have logined through session!");
24 }
25 else if(account.equals (password)) {
26
27 Session.setattribute ("UserAccount", account);
28 Out.print ("Congratulation" +account+ ", you had logined through account and password!");
29 }
30
31
32
33 }
34
35 }

Here is the configuration file for Loginservlet:

1 <servlet>
2 <description>LoginServlet</description>
3 <display-name>LoginServlet</display-name>
4 <servlet-name>LoginServlet</servlet-name>
5 <servlet-class>servlet. Loginservlet</servlet-class>
6 </servlet>
7
8 <servlet-mapping>
9 <servlet-name>LoginServlet</servlet-name>
10 <url-pattern>/servlet/LoginServlet</url-pattern>
11 </servlet-mapping>

Here I would like to explain, if through the password account verification login success, the prompt congratulations, you through the password account login success, if through the session to check the successful landing, prompted you with the session successfully.

2) Write Flex access Selvlet, oh, I'm still talking here. Through the Httpservice visit, previously saw someone through the BlazeDS to visit session, very good, interested can go to search ha, there is time I also go to try, if successful I will post it.

1 <?xml version= "1.0" encoding= "Utf-8"?>
2 <s:application xmlns:fx= "http://ns.adobe.com/mxml/2009"
3 Xmlns:s= "Library://ns.adobe.com/flex/spark"
4 xmlns:mx= "Library://ns.adobe.com/flex/mx" minwidth= "955" minheight= ">"
5 <fx:Declarations>
6 <s:httpservice id= "Login" url= "Http://localhost:8080/FlexSession/servlet/LoginServlet" showbusycursor= "true"
7 Method= "POST" result= "Loginhandler (event)"/>
8 </fx:Declarations>
9 <fx:Script>

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.