How to send an HTTP request from the servlet to enter the HTTP page

Source: Internet
Author: User

I want to use implicit sending of the HTTP parameter address from the servlet and automatically go to the HTTP page.

 

How to Use servlet to read parameters and page turns in Web. xml

Import java. Io. ioexception;
Import java. Io. printwriter;
Import java. SQL. connection;
Import java. SQL. drivermanager;
Import java. SQL. preparedstatement;
Import java. SQL. sqlexception;

Import javax. servlet. servletconfig;
Import javax. servlet. servletexception;
Import javax. servlet. http. httpservlet;
Import javax. servlet. http. httpservletrequest;
Import javax. servlet. http. httpservletresponse;

Public class loginv1servlet extends httpservlet {
Private string xmlname, xmlpass;
Protected void doget (httpservletrequest arg0, httpservletresponse arg1)
Throws servletexception, ioexception {

Dopost (arg0, arg1 );
}

Public void Init (servletconfig config) throws servletexception {
// Read the content of the XML document during initialization // This Is A superclass method to override
Xmlname = config. getinitparameter ("name ");
Xmlpass = config. getinitparameter ("pass ");

/*
* <Init-param>

* <Param-Name> pass </param-Name>

* <Param-value> 123456 </param-value>

* Write the statement in the XML file in the <servlet> Block
* </Init-param>
*/

}
Protected void dopost (httpservletrequest req, httpservletresponse res)
Throws servletexception, ioexception {
// First, the data stream encoding on the client solves the Chinese problem.
Req. setcharacterencoding ("gb2312 ");
// Obtain the data transmitted by the customer

String STR = Req. getparameter ("action ");
String id = Req. getparameter ("ID ");
String name = Req. getparameter ("name ");
String amount = Req. getparameter ("amount ");
Res. setcontenttype ("text/html; charset = gb2312 ");
Printwriter PW = res. getwriter ();
PW. println ("<HTML> ");
PW. println ("<title> prepared product information </title> <body> ");
PW. println ("No.:" + id );
PW. println ("name:" + name );
PW. println ("Quantity:" + amount );

If ("1". Equals (STR )){
// Electronic Payment
PW. println ("<a href = 'HTTP: // www.post.com.cn 'target = _ blank> go to online banking </a> ");
} Else {
// Remittance
PW. println ("<a href0000'info.html '> fill in the details </a> ");
}
PW. println ("</body> ");

 

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.