网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
05月10日漏签0天
jsp吧 关注:44,503贴子:301,870
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 0回复贴,共1页
<<返回jsp吧
>0< 加载中...

急求大神帮忙!!!!这个要怎么弄?

  • 只看楼主
  • 收藏

  • 回复
  • 袁袁袁
  • 玩转架构
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
package com.neusoft.api;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class DataTest5 extends HttpServlet {
/**
* Constructor of the object.
*/
public DataTest5() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String contentType=request.getHeader("Accept");
PrintWriter out = response.getWriter();
if(contentType.contains("application/json"))
{
response.setContentType("application/json;charset=utf-8");
out.println("{\"name\":\"huangbo\",\"age\":39}");
}
else if(contentType.contains("application/xml")||contentType.contains("text/xml"))
{
response.setContentType("text/xml;charset=utf-8");
out.println("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
out.println("<studnet>");
out.println("<name>黄波</name>");
out.println("<age>39</age>");
out.println("</studnet>");
}
//out.println(contentType);
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String contentType=request.getContentType();
PrintWriter out = response.getWriter();
if(contentType.contains("application/json"))
{
response.setContentType("application/json;charset=utf-8");
out.println("{\"name\":\"huangbo\",\"age\":39}");
}
else if(contentType.contains("application/xml")||contentType.contains("text/xml"))
{
response.setContentType("text/xml;charset=utf-8");
out.println("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
out.println("<studnet>");
out.println("<name>huangbo</name>");
out.println("<age>39</age>");
out.println("</studnet>");
}
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
1.以ajax POST方式请求DataTest5,可以得到xml或json格式数据(用户可选);2.把名字huangbo弹出来(用js代码写出来)


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 0回复贴,共1页
<<返回jsp吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示