package org.shaw;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
public class BaiyouBBS {
static final String LOGON_SITE = "";
public Cookie[] login(String name, String pas) {
try {
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);
PostMethod post = new PostMethod("/logging.php?action=login");
client.executeMethod(post);
String responseString = new String(post.getResponseBody(), "gbk");
post.releaseConnection();
String formhash = getFormHash(responseString);
System.out.println(formhash);
post = new PostMethod("/logging.php?action=login");
NameValuePair[] params = new NameValuePair[11];
params[0] = new NameValuePair("loginfield", "username");
params[1] = new NameValuePair("username", name);
params[10] = new NameValuePair("styleid", "");
post.setRequestBody(params);
//responseString = new String(post.getResponseBody(), "gbk");
GetMethod get = new GetMethod("/index.php");
client.executeMethod(get);
responseString = new String(get.getResponseBody(), "gbk");
get.releaseConnection();
System.out.println(responseString);
} catch (Exception e) {
e.printStackTrace();
}
return null;
public String getFormHash(String htmlContent) {
int start = htmlContent.indexOf("name=\"formhash\"");
int end = htmlContent.indexOf("\"", start);
String formhash = htmlContent.substring(start, end);
return formhash;
} catch (RuntimeException e) {
throw e;
public static void main(String[] args) {
new BaiyouBBS().login("zzzxxxzzz", "zzzxxxzzz");
Java中字符串转码,根据实际运用的环境有以下三种方式
使用Java.lang.String这是最常用的方法,先用对应编码获取字节,然后重新构造新编码,示例代码如下:String?s?=?"清山";?
java.io.InputStreamReader/OutputStreamWriter:桥转换读写文件的应用中,可以使用这种方式,直接在IO流构造中转换,示例代码如下:
InputStream?is?=?new?FileInputStream("C:/项目进度跟踪.txt");//文件读取?
CharsetDecoder?de?=?inSet.newDecoder();?//?解码器
CharsetEncoder?en?=?outSet.newEncoder();//?编码
使用Java中的File类,url为文件的绝对地址,str为输入的字符串内容.
代码如下图所示:
String str="i love china!"
File txt=new File("url");
if(!txt.exists()){
txt.createNewFile();
bytes=str.getBytes(); //新加的
int b=str.length(); //改
FileOutputStream fos=new FileOutputStream(txt);
fos.write(bytes,0,b);
fos.close();
不是很明白你的需求.
这么说吧,要想生成html页面的话,容器会替我们直接把jsp编译成servlet输出成html静态页面进行展示.
还有如果你想写入html文件的话,你可以通过fileinput字节写入.(这种写法servlet教程上很多实例,包括如何生成文件,如何通过字节或者字符流的形式写入和保存)
那么你问的是哪一种呢?
可以把这段代码写在隐藏域里,如果需要把它显示出来的时候,用java取消隐藏域,就可以了吧.
form是转到后台,通过后台再做跳转到Show.jsp的,如果你仅仅只是在show.jsp中显示的话,可以通过JS传参的方式去实现,具体如下:
script language="javascript" type="text/javascript"
window.location.href="show.jsp?name="+ document.getElementById("name").value;
/script
以上就是土嘎嘎小编为大家整理的java实现html代码的简单介绍java实现html代码的简单介绍相关咨询咨询主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!