Servlet course 0425 (Fri) sendredirect sharing data across different pages

Source: Internet
Author: User
Tags null null

Login.java

//Login Interface PackageCom.tsinghua;Importjavax.servlet.http.*;ImportJava.io.*; Public classLoginextendshttpservlet{ Public voiddoget (httpservletrequest req, httpservletresponse res) {//Business Logic        Try{            //Chinese garbled//Browser Default ISO-8859Res.setcontenttype ("TEXT/HTML;CHARSET=GBK"); PrintWriter PW=Res.getwriter (); //Back to login screenPw.println ("); Pw.println ("<body>"); Pw.println ("); Pw.println ("<form action= ' Logincl ' method=post>"); Pw.println ("User name <input type= ' text ' name= ' username '/><br/>"); Pw.println ("Password <input type= ' password ' name= ' userpwd '/><br/> '); Pw.println ("<input type= ' submit ' value= ' Loing '/><br/>"); Pw.println ("</form>"); Pw.println ("</body>"); Pw.println ("); }        Catch(Exception ex) {ex.printstacktrace (); }            }         //Handling GET Requests//req for obtaining client (browser) information//Res is used to return information to the client (browser)     Public voidDoPost (httpservletrequest req, httpservletresponse res) { This. Doget (Req,res); }            }

Logincl.java

//Login Interface PackageCom.tsinghua;Importjavax.servlet.http.*;ImportJava.io.*; Public classLoginclextendshttpservlet{ Public voiddoget (httpservletrequest req, httpservletresponse res) {//Business Logic        Try{                        //receive user name and passwordString u = req.getparameter ("username"); String P= Req.getparameter ("Userpwd"); //Validation                        if(U.equals ("Litao") && p.equals ("Litao"))){                //Legal//Jump to welcomeRes.sendredirect ("wel?uname=" +u+ "&upass=" +Q); }            Else{                //Not legal//write the URL of the servlet you want to go toRes.sendredirect ("Login"); }                                            }        Catch(Exception ex) {ex.printstacktrace (); }            }         //Handling GET Requests//req for obtaining client (browser) information//Res is used to return information to the client (browser)     Public voidDoPost (httpservletrequest req, httpservletresponse res) { This. Doget (Req,res); }            }

Welcome.java

//Login Interface PackageCom.tsinghua;Importjavax.servlet.http.*;ImportJava.io.*; Public classWelcomeextendshttpservlet{ Public voiddoget (httpservletrequest req, httpservletresponse res) {//get the user name and password passed from Logincl//if the name of the parameter is incorrectly written, the resulting null null valueString u = req.getparameter ("uname"); String P= Req.getparameter ("UPass"); //Business Logic        Try{printwriter pw=Res.getwriter (); //Back to login screenPw.println ("Welcome,hello," +u+ "password=" +p); }        Catch(Exception ex) {ex.printstacktrace (); }            }         //Handling GET Requests//req for obtaining client (browser) information//Res is used to return information to the client (browser)     Public voidDoPost (httpservletrequest req, httpservletresponse res) { This. Doget (Req,res); }            }

Servlet course 0425 (Fri) sendredirect sharing data across different pages

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.