One. Use 3 jar packages.
Zxing-core-1.7.jar,zxing-j2se-1.7.jar,qrgen-1.2.jar
: http://download.csdn.net/detail/jiazhipeng12/8442665
public class Main {
/**
* Generate a two-dimensional code
* @param args
* @throws unsupportedencodingexception
*/
public static void Main (string[] args) throws Unsupportedencodingexception {
String content= You;
Bytearrayoutputstream out = qrcode.from (content). to (Imagetype.png). Stream ();
try {
FileOutputStream fout = new FileOutputStream (New File (
"C:fuck.jpg"));
Fout.write (Out.tobytearray ());
Fout.flush ();
Fout.close ();
} catch (FileNotFoundException e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/B1/wKioL1TcTFOwNCphAAL2jCO4FHg388.jpg "title=" ukqh% 9upq@}s$o%ekm~otp8.png "alt=" Wkiol1tctfowncphaal2jco4fhg388.jpg "/>
Two. Servler generate the QR code of the URL
index.jsp
<body>
<form action= "Xian" method= "get" >
<p>enter Text to create QR code</p>
<input type= "text" name= "Qrtext"/>
<input type= "Submit" value= "Generate QR Code"/>
</form>
</body>
Xian.servlert
public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
Response.setcontenttype ("text/html");
String Qrtext = Request.getparameter ("Qrtext");
Bytearrayoutputstream out = Qrcode.from (Qrtext). to (Imagetype.png). Stream ();
Response.setcontenttype ("Image/png");
Response.setcontentlength (Out.size ());
OutputStream OutStream = Response.getoutputstream ();
Outstream.write (Out.tobytearray ());
Outstream.flush ();
Outstream.close ();
}
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/B4/wKiom1TcStziMVihAACtxNjvdro073.jpg "title=" y4]e7[ Cj$vk ' 3y]e88kv55w.png "alt=" wkiom1tcstzimvihaactxnjvdro073.jpg "/>650) this.width=650;" src= "http:// S3.51cto.com/wyfs02/m00/59/b1/wkiol1tcs_zrhvxtaac5cmtyvjq918.jpg "title=" Nb%upkt@lrztvf2$c566t_1.png "alt=" Wkiol1tcs_zrhvxtaac5cmtyvjq918.jpg "/> Scan two-dimensional code can open Baidu.
Three. Unable to recognize the problem of garbled Chinese.
I search the method on the Internet. Modify the Com.google.zxing.qrcode.encoder.Encoder.java file for the Zxing-core-1.7.jar package. Modify the following:
static final String default_byte_mode_encoding = "UTF-8";
Use tool: http://download.csdn.net/detail/jiazhipeng12/8442743
Then use the jar command jar cvf hello.jar com under CMD to recompile the jar package
This article is from the "Jia Xiaoxian" blog, make sure to keep this source http://hackerxian.blog.51cto.com/9240575/1614059
Java code generates two-dimensional code