在servlet里面写就可以了
引入一系列包
import java.io.IOException
import java.io.PrintWriter
import javax.servlet.ServletException
import javax.servlet.ServletRequest
import javax.servlet.ServletResponse
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import java.io.*
public class Servlet1 extends HttpServlet {
public void doGet(ServletRequest req,ServletResponse res)throws ServletException, IOException{try{PrintWriter pw=res.getWriter()//在浏览器输出需要
pw.println("<script<script")}catch(exception e){="" e.printstacktrace()="" 为发现调试错误}}}=""
如下:public static String do_post(String url, List<NameValuePair> name_value_pair) throws IOException {
String body = "{}"
DefaultHttpClient httpclient = new DefaultHttpClient()
try {
HttpPost httpost = new HttpPost(url)
httpost.setEntity(new UrlEncodedFormEntity(name_value_pair, StandardCharsets.UTF_8))
HttpResponse response = httpclient.execute(httpost)
HttpEntity entity = response.getEntity()
body = EntityUtils.toString(entity)
} finally {
httpclient.getConnectionManager().shutdown()
}
return body
}
public static String do_get(String url) throws ClientProtocolException, IOException {
String body = "{}"
DefaultHttpClient httpclient = new DefaultHttpClient()
try {
HttpGet httpget = new HttpGet(url)
HttpResponse response = httpclient.execute(httpget)
HttpEntity entity = response.getEntity()
body = EntityUtils.toString(entity)
} finally {
httpclient.getConnectionManager().shutdown()
}
return body
}
。。写个简单的,给个思路吧。。public class FileTestDemo {
public static void main(String[] args) {
File file = new File("E:\\test.html")
OutputStream out = null
try {
out = new FileOutputStream(file)
out.write("<h1>test2</h1>".getBytes())
out.flush()
} catch (Exception e) {
}
}
}
要用到OutputStream输出流,可以看一下API。。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)