CommandLineRunner 里得到的数据页面接收不到

方法没问题,但获取到的值传不过去

 @Component
public class JobCLR implements CommandLineRunner  {
     protected final Logger logger = LoggerFactory.getLogger(JobCLR.class);
  @Autowired
        private JobService js;
      @Override
        public void run(String... args) throws Exception {
           System.out.println(">>>>>>>>>>>>>>>服务启动执行,执行加载数据等操作<<<<<<<<<<<<<");
          /* List<String> jobsListindex=js.queryHotJob(1);*/
        List<Jobs>  jobsList= js.selectByHeat1();
           ModelAndView mav =new ModelAndView("/");   
           mav.addObject("jobsList",jobsList);

           for(Jobs l :jobsList) {
           System.out.println(l);

           }
        } 

}

页面

 <a class="zxzw_fen clearfix"
                        th:classappend="${ jobsListindex.index } % 2 == 0  ? '' : 'mr_0'"
                        href="" th:each="jobsList,jobsListindex:${jobsList}">
         <div class="zxzw_fen_01 clearfix">

    <b th:utext="|<i>|+${jobsList.jobPosition}+|</i>&nbsp;[|+${jobsList.jobAddress}+|]&nbsp;&nbsp;${jobsList.jobReleaseTime}|"></b>
                 <span th:text="${jobsList.jobSalary}">24-36万</span>
         </div>
         <div class="zxzw_fen_02 clearfix">
                 <span  th:text="${jobsList.jobEmployAddress}"></span>
         <i  th:text="${jobsList.jobWelfare}">绩效奖金</i> <i>带薪年假</i>
                        </div>
                    </a>
0

3个回答

以配置文件为application.properties视图为jsp举例

** 在application.properties配置springmvc**

#springmvc
spring.mvc.view.prefix                                    = /WEB-INF/views/
spring.mvc.view.suffix                                    = .jsp

index.jsp 代码举例(哈哈,最简单jsp)

 ${data}

springboot启动代码举例


@Controller
@SpringBootApplication
public class Application implements CommandLineRunner
{
    private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);

    //注入service 举例
    @Autowired
    CustomerService customerService;

    public static void main(String[] args)
    {
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void run(String... args)
        throws IOException
    {
        LOGGER.info("★★★★★★★★  now open Browser ★★★★★★★★ ");
        //windows系统下自动打开浏览器,可根据需要调整url
        Runtime.getRuntime().exec("cmd.exe /c start /min http://127.0.0.1:8080/");
    }

    @RequestMapping(value = "/")
    public ModelAndView index()
    {
        ModelAndView modelAndView = new ModelAndView("index");
        modelAndView.addObject("data", customerService.getAllCustomers());
        return modelAndView;
    }
}

运行效果 图片说明

回答完毕, 希望帮到你 !
本人码云 https://gitee.com/00fly/ 欢迎访问!

1
qq_37852473
qq_37852473 谢谢老哥
11 个月之前 回复

思路二:** jsp里面直接操作**(已经调试通过)

<%@page import="com.fly.hbn.service.CustomerService"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%
    ApplicationContext content = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    CustomerService customerService = content.getBean(CustomerService.class);
    request.setAttribute("data2", customerService.getAllCustomers());
%>

<hr>
${data2}

运行结果
图片说明

回答完毕,希望能帮到你!

1

如果是springboot项目的话其实可以

 @RequestMapping(value="/") 

以达到一开始页面便能加载数据
虽然low了点

0
qq_16127313
爱码少年 controller可移到别的地方, 这边这是方便演示,重点是打开浏览器url代码
11 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
NMUDP接收不到数据
我现在用NMPUDP实现一个UDP小程序,发送程序可以实现,但是接收不到数据,接收事件是通过NMUDP1DataReceived实现的,但是接收不到数据的问题出现了,用断点调试,发现程序根本不执行该函数内容,这是为什么呢?谁来帮忙解决下啊。。。灰常感谢
at指令接收不到数据
过程状态如下:rn 使用超级终端能够和手机正常通讯,发送:at,返回:OK, 关闭睡眠:at+eslp=0其他通用指令都能使用。然后关闭超级终端,重启手机,用自己的程序打开串口,发送指令,都能接收得到。关闭程序,重启手机几次后,用自己的程序和手机执行以上命令,都正常返回。rn int Init()rn rn char ans[128]=0; // 应答串rnrn // 测试GSM-MODEM的存在性rn WriteComm("AT\r", 3);rn ReadComm(ans, 128);rnrn if (strstr(ans, "OK") == NULL)rn rn return 0;rn rnrn //AT+ESLP=0 关闭睡眠rn WriteComm("AT+ESLP=0\r", 10);rn ReadComm(ans, 128); rn rnrn int WriteComm(void* pData, int nLength)rn rn DWORD dwNumWrite; // 串口发出的数据长度rn WriteFile(hComm, pData, (DWORD)nLength, &dwNumWrite, NULL);rn return (int)dwNumWrite;rn rnrn int ReadComm(void* pData, int nLength)rn rn DWORD dwNumRead; // 串口收到的数据长度rn ReadFile(hComm, pData, (DWORD)nLength, &dwNumRead, NULL); rn return (int)dwNumRead;rn rnrn 拔掉数据线,重新插入。开启自己的程序,连接手机,打开串口,发送指令。此时接收不到任何应答数据。rn不知道为何?rn rnrn rn rn
jrtp接收不到数据
这是我的接收端的源代码:[code=css]#include "rtpsession.h"rn#include "rtppacket.h"rn#include "rtpudpv4transmitter.h"rn#include "rtpipv4address.h"rn#include "rtpsessionparams.h"rn#include "rtperrors.h"rn#include rn#include rn#include rn#include rn#include rn#include rnrn#include "rtpsourcedata.h"rnrnclass MyRTPSession : public RTPSessionrnrnprotected:rn void OnPollThreadStep();rn void ProcessRTPPacket(const RTPSourceData &srcdat,const RTPPacket &rtppack);rn;rnrnvoid MyRTPSession::OnPollThreadStep()rnrn BeginDataAccess();rn // check incoming packetsrn if (GotoFirstSourceWithData())rn rn dorn rn RTPPacket *pack;rn RTPSourceData *srcdat;rn rn srcdat = GetCurrentSourceInfo();rn rn while ((pack = GetNextPacket()) != NULL)rn rn rn ProcessRTPPacket(*srcdat,*pack);rn DeletePacket(pack);rn rn while (GotoNextSourceWithData());rn rn rn EndDataAccess();rnrnrnvoid MyRTPSession::ProcessRTPPacket(const RTPSourceData &srcdat,const RTPPacket &rtppack)rnrn printf("got packet!\n");rnrnrnint main()rnrn MyRTPSession sessrecv;rn short portbase;rn std::string ipstr;rn int status,num;rnrn // First, we'll ask for the necessary informationrn rn portbase=8020;rn num=10;rn int i;rn RTPUDPv4TransmissionParams transparams;rn RTPSessionParams sessparams;rn sessparams.SetOwnTimestampUnit(1.0/8000.0); rn rn transparams.SetPortbase(portbase);rn status = sessrecv.Create(sessparams,&transparams); rn checkerror(status);rn rn // Wait a number of secondsrn for(i=0;i
GCDAsyncSocket 接收不到数据
GCDAsyncSocket 接收不到数据
电脑接收不到数据?
电脑连上网络后,接收不到数据,查看IP都是正确的,但是PING不通网关,本机能PING通,是怎么回事?
串口接收不到数据
各位大侠:rn 最近在写一个吊称数据获取程序,通过RS232获取数据,但是吊称跟电脑连接后,C#程序获取不到任何数据,serialPort1_DataReceived事件不能触发,不知道是什么原因?请问怎么样才能接收到串口的数据?我将自个电脑的串口2,3脚短接就能接受到自己发出的数据!rn
后端接收不到数据
@RestController @RequestMapping("/itemsearch") public class ItemSearchController { @Reference private ItemSearchService itemSearchService; @RequestMapping("/search") public Map&lt;St...
recvfrom接收不到数据了
在一个接收子线程里面接收下位机上送的数据,如下: rn while (ConnectFlag)rnrn if (pDlg->RecvFlag)rn rn int err = recvfrom(pDlg->socketclient,recvbuf,1000,0,(SOCKADDR*)&addrsv,&lenp);rn rnrn流程:上位机先下发命令给下位机配置参数,下位机一旦收到相应的信息(不是前句话讲的参数命令)就开始上送数据。问题:如果下位机停止上送数据接近一分钟,再次上送数据,recvfrom却接收不到数据,从PC端的截包工具已经看到下位机上送了数据且数据格式内容正确,这个时候只有再下发一次命令后,下位机一旦收到相应信息,recvfrom又能收到数据,至少说明接收子线程没有退出。注明:下发命令其实主要就是sendto函数,“截包工具已经看到下位机上送了数据”说明配置参数命令其实已经在下位机了,不明白为什么要再次下发命令一下又才能recvform。rn我把 recvfrom改成非阻塞模式,也是同样的现象。
openwithparm接收不到数据
如题,我在w_1中添加了一个按钮,按钮的clicked事件中代码如下:rnlong ll_rowrnstring ls_nbrrnint li_countrnll_row = dw_1.rowcount()rnif ll_row > 0 thenrn ls_nbr = dw_1.object.do_mstr_do_nbr[dw_1.getrow()]rn select count(*) into :li_count from tr_histrn WHERE tr_nbr=:ls_nbr;rn if li_count>0 thenrn messagebox('提示','仓库已经输入数据,你无法修改该单据!')rn return -1rn elsern openwithparm(w_2, ls_nbr)rn end if;rnend if rn在w_2的open中代码如下:rnstring ls_message,ls_deptrnrnrnls_message = message.stringparmrnis_nbr= ls_messagernrndw_1.retrieve(is_nbr)rn用messagebox来条显示在w_1中的代码有实现,且debug运行有看到message.stringparm有值,但是打开了w_2后,就为空,rn请高手不吝赐教
Receive()接收不到数据?
出问题的程序段如下:rnwhile(!bExit)rnrn // 等待主线程传来Accept生成的socket值rn ::WaitForSingleObject(MyView->ReceiveStart.m_hObject, INFINITE);rnrn // 准备开始互斥完成工作rn if (localLock->Lock(0)) rn rn MyView->ReceiveStart.ResetEvent();rn recvSocket.Attach(MyView->m_RecvSocket);// 获得当前这个socketrn MyView->AcceptNow.SetEvent(); rn localLock->Unlock(); // 解锁rn recvdSize = recvSocket.Receive((char*)&recved_pkt, sizeof(PKT));rn if (recvdSize == SOCKET_ERROR) ;rn elsern ;rnrn说明:MyView是指向View的指针,m_RecvSocket是一个View的成员变量,保存Accept时生成的socket,其它一些是CEvent的对象,用来完成线程间同步。rnrnrn每次recvdSize都是SOCKET_ERROR, 即使其中那句“recvSocket.Attach(MyView->m_RecvSocket)”(对Attach()我的理解不太深)改成recvSocket.m_hSocket = MyView->m_RecvSocket.m_hSocket, 也会报错,错误编号10038(WSAENOTSOCK)。真是摸不着头脑,希望有行家能给我解答一下。rnrn多谢多谢!!
网络编程,接收不到数据
刚开始学网络编程,写了个小程序测试了一下,老是第一次接收不到数据,但是就是能接收到结束标志,郁闷。rn一小段代码如下:rnrn 服务端: while(1)rn rn printf("abc\n");rn bzero(buffer2,sizeof(buffer2));rn n=read(pthread->clientsocket,buffer2,sizeof(buffer2));rn printf("read=%d\n",n);rn printf("%s\n",buffer2);rn if(strcmp(buffer2,"quit")==0)rn break;rn rn fwrite(buffer2,n,1,fp);rn rn rn printf("recv over\n");rn fclose(fp);rnrnrn 客服端:rn fd=open(mp.filename,O_RDWR);rn if(fd==-1)rn rn perror("open file error!");rn exit(1);rn rn lseek(fd,0,SEEK_SET);rn bzero(buffer,sizeof(buffer));rn while((n=read(fd,buffer,sizeof(buffer)))>0)rn rn m=write(socket2,buffer,strlen(buffer));rn printf("write=%d\n",m);rn printf("%s\n",buffer);rn sleep(1);rn bzero(buffer,sizeof(buffer));rn rn close(fd);rn bzero(buffer,sizeof(buffer));rn strcpy(buffer,"quit");rn sleep(1);rn write(socket2,buffer,strlen(buffer));rn printf("%s\n",buffer);rn printf("update file over!\n");rnrnrn 客服端终端信息如下:rn Update Files:b.c //输入文件,打印如下rn write=11rn 123456rn 789rnrn quitrn update file over!rnrnrn 服务端终端信息如下:rn abcrn read=4rn quitrn recv over //每次客服端输入文件名,服务端就只打印这四句。rnrnrn 求高手指正一下!
为什么接收不到数据
我写的上位机程序,用串口助手可以接收到它发来的数据,问什么它接收不到串口助手发过来的数据,下面是它接收数据的代码,大家帮我看看,谢谢!rnrnprocedure TForm1.Button7Click(Sender: TObject);rnrnvarrndata:string;rnBufferLength:word;rnBuffer:Pointer;rnbegin rnSetLength(data,BufferLength);rnmove(Buffer^,pchar(data)^,Bufferlength);rnMemo1.lines.Add(data);rnMemo1.Invalidate;rnrnend;
idUdpServer 接收不到数据
在ActiveFormX中使用idUdpServerrn//初始化rnwith idUDPServer1.Bindings.Add dornbeginrn IP:='';rn Port:=6013;rnend;rnidUDPServer1.active:=True;rnrn//idUDPServer1UPPRead 事件处理rnshowmessage('hello');rnrn该程序在ie中使用程序打开后rn用天网防火墙观察看到 ie有在UDP 6013端口监听rn当服务端发来数据时候rn天网防火墙发现ie有在UDP 6013端口监听目的指向了rn服务端ip端口也正确 rn但程序没有按设计的那样出提示rn点了一下IE的刷新 发现程序出 'hello' 提示了rn好像ie 不会把数据提交给程序 只在要刷新时一下提交rn这怎么回事rn希望大家帮助
UDP接收不到数据?
服务端代码:rn private void lxcMain_Load(object sender, EventArgs e)rn rn int recv;rn byte[] revData = new byte[1024];rn byte[] sendData = new byte[1024];rn IPAddress address = IPAddress.Parse("192.168.31.80");rn IPEndPoint ip = new IPEndPoint(address, 6667);rn Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);rn newsock.Bind(ip);rn IPEndPoint sender1 = new IPEndPoint(address, 0);rn EndPoint Remote = (EndPoint)(sender1);rn recv = newsock.ReceiveFrom(revData, ref Remote);rn rn客户端代码放在板子上通过以太网连接。rn代码在项目中ReceiveFrom接收不到数据。新建一个测试项目复制同样代码就可以接收数据了。 请问,可能会有什么原因造成?
完成端口接收不到数据
#include "Server.h"rn#include rn#include rn#include rnrnstatic DWORD WINAPI subThread( LPVOID lpParameter )rnrn DWORD bytesCnt;rn HANDLE cphdl = ( HANDLE )lpParameter;rn SOCKET sock;rn LPOVERLAPPED pOverLapped;rn char *buf;rnrn while( 1 ) rn GetQueuedCompletionStatus( cphdl, &bytesCnt, ( PULONG_PTR )&buf, rn ( LPOVERLAPPED * )&pOverLapped, INFINITE );rnrn std::cout << bytesCnt << std::endl;rn rnrn return 0;rnrnrnbool Server::create()rnrn WSADATA wsaData;rn WSAStartup( MAKEWORD( 2, 2 ), &wsaData );rnrn // 1. create a completion portrn HANDLE cpHdl = CreateIoCompletionPort( INVALID_HANDLE_VALUE, 0, 0, 1 );rn // 2. Create Socketrn SOCKET sock = createSock();rn // 3. create threadrn DWORD subThrdId;rn HANDLE thrdHdl = CreateThread( 0, 0, subThread, ( LPDWORD )cpHdl, 0, &subThrdId );rn CloseHandle( thrdHdl );rn // 4. listenrn startListen( sock, cpHdl );rnrn return true;rnrnrnSOCKET Server::createSock()rnrn SOCKET sock;rn sockaddr_in saServer;rn sock = WSASocket( AF_INET, SOCK_STREAM, 0, NULL, 0, WSA_FLAG_OVERLAPPED );rn saServer.sin_family = AF_INET;rn saServer.sin_addr.s_addr = inet_addr( "127.0.0.1" );rn saServer.sin_port = htons( 5150 );rn bind( sock, ( SOCKADDR * )&saServer, sizeof( saServer ) );rn listen( sock, 1 );rn return sock;rnrnrnvoid Server::startListen( SOCKET sock, HANDLE cpHdl )rnrn SOCKET acceptSock;rn char *buf = ( char * )GlobalAlloc( 0, 256 );rn WSABUF wsaBuf = 256, buf ;rn DWORD bytesCnt;rn DWORD flag = 1;rn WSAOVERLAPPED overLapped;rn bool ret = false;rnrn while( 1 ) rn acceptSock = WSAAccept( sock, NULL, NULL, 0, 0 );rn std::cout << "accept" << std::endl;rn CreateIoCompletionPort( ( HANDLE )acceptSock, cpHdl, ( DWORD )buf, 1 );rn ZeroMemory( &overLapped, sizeof( overLapped ) );rn char *msg = "main thread";rn WSARecv( acceptSock, &wsaBuf, 1, &bytesCnt, &flag, &overLapped, 0 );rn send( acceptSock, msg, strlen( msg ), 0 );rn int err = WSAGetLastError();rn rnrnrn不明白问题出在哪里,一些关键步骤都有检查过,没有什么错误。还请高手指教rn
recv接收不到数据!!
while(1)rn rn byte_count = recv(sock, buf, sizeof(buf), 0);rn if(byte_count>0)rn rn return 1;rn rn elsern rn continue;rn rn rn 这样都接收不到数据。郁闷中................
|M| Post学习 接收页面接收不到
发送:rn rn rn rn rn rnrnrn接收rn protected void Page_Load(object sender, EventArgs e)rn rn Response.Write(Request["txtname"].ToString());rn Response.Write(" ");rn Response.Write(Request["txtpass"].ToString());rn rnrnrn未将对像引用到对像实例
接收页面内容,为什么接收不到
通过post提交进入一个页面,这个页面显示正常,然后点刷新按钮,就出问题了,页面中有两个隐藏的文本框,接收不到它们的值,但其他值都可以接收rnservlet里面的doGet()与doPost()相同
接收不到页面传来的值!
rn rnrnrnpage2rnrn Response.Write("HTML收取:" + Request.Form["txtName"]);rnrnrn按照以上的方法,我收不到值啊rnrn
VBA里接收不到返回值
有一个C++写的DLL,假如里面有一个返回值,但在VBA里接收不到这个值,总是为空rnVBA代码如下:rnPrivate Declare Function GetExifTime Lib "TESTDLL.dll" (ByVal a As String) As Stringrn Dim b As Stringrn b = GetExifTime("c:\c.JPG")rn MsgBox b
串口通信----串口接收框接收不到数据
在进行串口调试时,数据发送没有问题,da
前台为什么接收不到数据
今天花了一上午,后台是证正常的,struts.xml是正常的 。但是就是说找不到这个方法。 最后发现是因为方法应该是public 但是手误成了private
通信上了接收不到数据!
实现个远程注销功能 初学IOCP想试试 通信成功了 但接收数据好象收不到 点完注销按钮没反映,找不出什么毛病rn烦劳高手慧眼识错 感激不尽rnrn服务端IOCP模型rn#include rn#include rn#define BUFFER_SIZE 1024rnrntypedef struct _PER_HANDLE_DATArnrn SOCKET s;rn sockaddr_in addr;rnPER_HANDLE_DATA,*PPER_HANDLE_DATA;rnrntypedef struct _PER_IO_DATArnrn OVERLAPPED ol;rn char buf[BUFFER_SIZE];rn int nOperationType;rn#define OP_READ 1rn#define OP_WRITE 2rn#define OP_ACCEPT 3rnPER_IO_DATA,*PPER_IO_DATA;rnrnchar *ID="PowerOff";rnDWORD WINAPI ServerTheard(LPVOID lpParam);rnrnvoid main()rnrn WORD wVersionRequested;rn WSADATA wsaData;rn int err;rn rn wVersionRequested = MAKEWORD( 2, 2 );rn rn err = WSAStartup( wVersionRequested, &wsaData );rn if ( err != 0 ) rn return;rn rn rn rn if ( LOBYTE( wsaData.wVersion ) != 2 ||rn HIBYTE( wsaData.wVersion ) != 2 ) rn WSACleanup( );rn return; rn rn HANDLE hCompletion=CreateIoCompletionPort(INVALID_HANDLE_VALUE,0,0,0);rn CreateThread(NULL,0,ServerTheard,(LPVOID)hCompletion,0,0);rn rnrn SOCKET sockSrv=socket(AF_INET,SOCK_STREAM,0);rn SOCKADDR_IN addrSrv;rn addrSrv.sin_addr.S_un.S_addr=htonl(INADDR_ANY);rn addrSrv.sin_family=AF_INET;rn addrSrv.sin_port=htons(12345);rn rn bind(sockSrv,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));rn rn listen(sockSrv,5);rn rn SOCKADDR_IN addrClient;rn int len=sizeof(SOCKADDR);rnrn while(1)rn rn rn SOCKET sockConn=accept(sockSrv,(SOCKADDR*)&addrClient,&len);rn PPER_HANDLE_DATA pHandle=(PPER_HANDLE_DATA)GlobalAlloc(GPTR,sizeof(PPER_HANDLE_DATA));rn pHandle->s=sockConn;rn memcpy(&pHandle->addr,&addrClient,len);rn CreateIoCompletionPort((HANDLE)pHandle->s,hCompletion,(DWORD)pHandle,0);rn rn PPER_IO_DATA pIo=(PPER_IO_DATA)GlobalAlloc(GPTR,sizeof(PPER_IO_DATA));rn pIo->nOperationType=OP_READ;rn rn WSABUF buf;rn buf.buf=pIo->buf;rn buf.len=BUFFER_SIZE;rn DWORD dwRecv;rn DWORD dwFlags=0;rn WSARecv(pHandle->s,&buf,1,&dwRecv,&dwFlags,&pIo->ol,NULL);rn rn rnrnrnrnrnDWORD WINAPI ServerTheard(LPVOID lpParam)rnrn HANDLE hCompletion=(HANDLE)lpParam;rn DWORD dwTrans;rn PPER_HANDLE_DATA pHandle;rn PPER_IO_DATA pIo;rnrn while (TRUE)rn rn BOOL bOK=GetQueuedCompletionStatus(hCompletion,&dwTransrn ,(LPDWORD)&pHandle,(LPOVERLAPPED*)&pIo,WSA_INFINITE);rn if (!bOK)rn rn closesocket(pHandle->s);rn GlobalFree(pHandle);rn GlobalFree(pIo);rn continue;rn rn if (dwTrans==0&&(pIo->nOperationType==OP_READ||pIo->nOperationType==OP_WRITE))rn rn closesocket(pHandle->s);rn GlobalFree(pHandle);rn GlobalFree(pIo);rn continue;rn rn switch(pIo->nOperationType)rn rn case OP_READ:rn rn rn if (ID==pIo->buf)rn rn ExitWindowsEx(EWX_LOGOFF,0); //就是实现个远程注销功能rn rn WSABUF buf;rn buf.buf=pIo->buf;rn buf.len=BUFFER_SIZE;rn DWORD dwRecv;rn DWORD dwFlags=0;rn WSARecv(pHandle->s,&buf,1,&dwRecv,&dwFlags,&pIo->ol,NULL);rn rn break;rn case OP_WRITE:rn break;rn case OP_ACCEPT:rn break;rn rn rn rn return 0;rnrnrn客户端:rnrnchar *ID="PowerOff";rnvoid CPowerOffDlg::OnBtnPoweroff() rnrn // TODO: Add your control notification handler code herern send(m_sock,ID,strlen(ID)+1,0);rn rn
问题:gprs_dtu接收不到数据?
BOOL DSGetNextData(DtuDataStruct* pDataStruct,u16t waitseconds)rn功能:读取下一条Dtu送上来的信息rn参数:pDataStruct: 存放Dtu所送上来的信息和数据的结构,读函数执行成功后,返回的数据存放到该参数指向的结构中rnwaitseconds:本函数读到数据后立即返回;如果没有数据到达,则等待最长waitseconds(时间单位:秒)的时间,直到有数据到达,取值范围从0~65535,如果取值为0表明本函数将立即返回。另外,当在另一个线程中执行成功了DSStopService()后,本函数将立即返回。rn返回:如果返回为非零值,表明收到了一条Dtu信息。如果返回为0,则表明没有收到数据。rnrnrn上面是gprs_dtu数据接收函数,我设定每5秒执行一次,为什么每次都读不到数据呢?有谁做过这方面,给点意见啊。rnrn听人说,可能是啥维系连接,注册包之类的问题 ,不懂啊
关于SOCKET接收不到数据
发送端:rn结构体rntypedef struct head_packetrnrn char type[20]; //类型rn int length; //长度rn char aque[20]; //序列号 rn ST_HEAD_PACKET;rn发送数据:rn strncpy(head_package->type , "log" , sizeof("log"));rn head_package->length = strlen(head_package->type);rn strncpy(head_package->aque , "log" , sizeof("log"));rnrn writen(sd , head_package, sizeof(struct head_packet));rn函数:rnssize_t writen(int fd, const void *ptr, size_t n)rnrn size_t nleft;rn ssize_t nwritten;rnrn nleft = n;rn while (nleft > 0) rn if ((nwritten = write(fd, ptr, nleft)) < 0) rn if (nleft == n)rn return(-1); /* error, return -1 */rn elsern break; /* error, return amount written so far */rn else if (nwritten == 0) rn break;rn rn nleft -= nwritten;rn ptr += nwritten;rn rn return(n - nleft); /* return >= 0 */rnrn接收端:rn head_package = (ST_HEAD_PACKET *)malloc(sizeof(struct head_packet));rn memset(head_package , 0 , sizeof(struct head_packet));rn readn(sd , head_package , sizeof(head_package));rn printf("%s\n" , head_package->type);rn printf("%s\n" , head_package->aque);rn问题:rn接收端只能收到head_package->type 不能接收到head_package->aque
wince 串口接收不到数据
各位麻烦给指点一下,我的串口接收长时间接收之后就接收不到数据了,不知道怎么解决,还望各位帮忙看看!下面是我的接收线程,过几个小时后就接收不到数据了,我的线程接收来自模块的串口数据,模块不停的每隔400毫秒发一次数据rnDWORD CRsCom::CommRecvTread(LPVOID lparam)rnrn DWORD dwLength;rn char *recvBuf = new char[512];rn CRsCom *pDlg = (CRsCom*)lparam;rn COMSTAT ComStat;rn DWORD dwErrorFlags;rn PurgeComm(pDlg->m_hComm,PURGE_RXCLEAR|PURGE_TXCLEAR); //清空串口的接收缓 冲区,必要性不大rn ClearCommError(pDlg->m_hComm,&dwErrorFlags,&ComStat); //清除串口状态标rn while(TRUE)rn rn PurgeComm(pDlg->m_hComm,PURGE_RXCLEAR|PURGE_TXCLEAR); //清空串口的接收缓 冲区,必要性不大,但有rn //ClearCommError(pDlg->m_hComm,&dwErrorFlags,&ComStat); //清除串口状态标rn if (WaitForSingleObject(pDlg->m_ExitThreadEvent, 0) == WAIT_OBJECT_0 )rn break; rn if (pDlg->m_hComm != INVALID_HANDLE_VALUE )rn rn ClearCommError(pDlg->m_hComm,&dwErrorFlags,&ComStat);rn BOOL fReadState = ReadFile(pDlg->m_hComm, recvBuf, 512, &dwLength, NULL);rn if(!fReadState)rn rn //MessageBox(_T("无法从串口读取数据!"));rn rn elsern rn if(dwLength!=0)rn rn OnCommRecv(pDlg, recvBuf, dwLength); rn rn rn rn rn delete[] recvBuf;rn return 0;rn
raw socket接收不到数据
初学网络编程,照网上的例子写了个sniffer程序,可是执行到recv的时候,就没有返回了,估计是超时。请高人指点:rnrn[code=C/C++]rn#include "StdAfx.h"rn#include "Sniffer.h"rnrn#define SIO_RCVALL _WSAIOW(IOC_VENDOR,1)rn#define BUFFER_SIZE 65535rnchar RecvBuf[BUFFER_SIZE];rnrnUINT SniffThreadFun(LPVOID pParam);rnvoid SignalHandler(int sig);rnrnSniffer::Sniffer(void)rn : stopSniff(true)rnrnrnrnSniffer::~Sniffer(void)rnrnrnrnbool Sniffer::InitSocket(void)rnrn int err;rn int sockOpt = 1;rn char localName[100];rn struct hostent *hostPtr;rn SOCKADDR_IN sockAddr;rnrn WORD versionRequired = MAKEWORD(1,1);rn err = WSAStartup(versionRequired, &wsaData);rn if(err == SOCKET_ERROR)rn return false;rn sockRaw = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);rn if (sockRaw == INVALID_SOCKET)rn return false;rn err = setsockopt(sockRaw, IPPROTO_IP, IP_HDRINCL, rn (char*)&sockOpt, sizeof(sockOpt));rnrn if (err == SOCKET_ERROR)rn return false;rn err = gethostname(localName, sizeof(localName)-1);rn if (err == SOCKET_ERROR)rn return false;rn hostPtr = gethostbyname(localName);rn if (hostPtr == NULL)rn return false;rn sockAddr.sin_addr = *(in_addr *)hostPtr->h_addr_list[0];rn sockAddr.sin_family = AF_INET;rn sockAddr.sin_port = htons(57274);rn err = bind(sockRaw, (PSOCKADDR)&sockAddr, sizeof(sockAddr));rn if (err == SOCKET_ERROR)rn return false;rn return true;rnrnrnbool Sniffer::StartSniff(void)rnrn stopSniff = false;rn int err;rn unsigned long arg = 1;rnrn err = ioctlsocket(sockRaw, SIO_RCVALL, &arg);rn if (err == SOCKET_ERROR)rn int errCode = WSAGetLastError();rn return false;rnrn AfxBeginThread(rn (AFX_THREADPROC)SniffThreadFun, rn (LPVOID)this, rn THREAD_PRIORITY_NORMAL, rn 0, 0, NULL);rnrn return true;rnrnrnbool Sniffer::StopSniff(void)rnrn stopSniff = true;rn Sleep(2000);rn int err;rn DWORD arg = 0;rn err = ioctlsocket(sockRaw, SIO_RCVALL, &arg);rn if (err = SOCKET_ERROR)rn return false;rnrn return true;rnrnrnvoid Sniffer::DisposeSocket(void)rnrn WSACleanup();rn closesocket(sockRaw);rnrnrnUINT SniffThreadFun(LPVOID pParam)rnrn Sniffer *snifferPtr = (Sniffer *)pParam;rnrn while(!snifferPtr->stopSniff)rn rn //[color=#FF0000]执行recv的时候没有返回[/color]rn if (recv(snifferPtr->sockRaw, RecvBuf, BUFFER_SIZE, 0))rn rn snifferPtr->recvCallback(snifferPtr->pObserver, RecvBuf);rn rn rnrn return 0;rnrn[/code]
udp通讯接收不到数据
http://www.cnblogs.com/keyvip/archive/2010/11/16/1878713.html用的这个大神的代码rn我用的delphi xe7rn接收端接收不到数据,用网上其它的网络调试工具可以接收到数据rnprocedure TForm1.idpsrvr1UDPRead(AThread: TIdUDPListenerThread;rn const AData: TStream; ABinding: TIdSocketHandle);rn var Comm:TCommBlock;rnbeginrn AData.ReadBuffer(Comm,SizeOf(Comm));rn mmo1.Lines.Add('Comm');rnend;rn是不是这个函数有问题?初学,请大神指点。谢谢
UDP为什么接收不到数据?
我做了一个UDP程序,可是不能互传数据,请大家帮忙!rn服务器端:rn Public Sub exam2()rn ' This constructor arbitrarily assigns the local port number.rn Dim udpClient As New UdpClientrn Tryrn udpClient.Connect(IPAddress.Parse("192.168.30.51"), 13579)rn Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Parse("192.168.30.51"), 13579)rn Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint)rn Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)rn MessageBox.Show(("This is the message you received " + _rn returnData.ToString()))rn MessageBox.Show(("This message was sent from " + _rn RemoteIpEndPoint.Address.ToString() + _rn " on their port number " + _rn RemoteIpEndPoint.Port.ToString()))rn udpClient.Close()rn Catch e As Exceptionrn MessageBox.Show(e.ToString())rn End Tryrn End Subrn客户端:rn Dim udpClient As New UdpClientrn Tryrn udpClient.Connect(IPAddress.Parse("192.168.30.51"), 13579)rn Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there?")rn udpClient.Send(sendBytes, sendBytes.Length)rn udpClient.Close()rn Catch e As Exceptionrn MessageBox.Show(e.ToString())rn End Tryrn请问错在哪了?
求助:为什么接收不到数据?
我是新手,前几天跟着网上学写了一个VC++的ping程序,采用原始套接字收发数据,但我运行的时候,数据可以发送,但是接收的时候只有将本机设为目标地址才可以,当我ping了一下其他网站,程序就死了,我调试了几天了,也找不出哪里有问题,我快崩溃了,求助各位大虾指点指点,(我ICMP报文头和数据部分用校验和函数校验过没有问题)
xmlHttp接收不到数据,怎么回事?
function getLabelsGet() rn  xmlHttp=GetXmlHttpObject(); rn  if (xmlHttp==null) rn    alert('您的浏览器不支持AJAX!'); rn    return; rn   rn  var url="getstock.php?token="+token+"&key="+key+"&p1="+p1+"&p2="+p2; rnrn  xmlHttp.open("GET",url,true); rn  xmlHttp.onreadystatechange=getOkGet;//发送事件后,收到信息了调用函数 rn  xmlHttp.send(); rnrnfunction getStock() rn rn  xmlHttp=GetXmlHttpObject(); rn  if (xmlHttp==null) rn    alert('您的浏览器不支持AJAX!'); rn    return; rn   rn  var url="http://hq.sinajs.cn/list=sh601168"; rnrn  xmlHttp.open("GET",url,true); rn  xmlHttp.onreadystatechange=getStockOK;//发送事件后,收到信息了调用函数 rn  xmlHttp.send(); rnrnrnfunction getStockOK() rn rn  if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3) rn    // 本地提示:加载中 rn   rn if(xmlHttp.readyState==4)rnrn rn var data = xmlHttp.responseText;rn alert(data);rn rn rn  rn rngetStock();rnrn我打算取出字符串自己进行拆解,可是取不到数据,该如何得到返回的字符串?并进行拆解呢?
用TWinSocketStream接收不到数据
ClientSocket用阻塞方式,thread中创建,rnTClientSocket *pClientSocket=new TClientSocket(NULL);rn pClientSocket->Address="127.0.0.1";rn pClientSocket->Port=7500;rn pClientSocket->ClientType=ctBlocking;rn rn pClientSocket->Active=true;rnrnvoid __fastcall socketthread::Execute()rnrn //---- Place thread code here ----rn TClientSocket *pClientSocket=new TClientSocket(NULL);rn pClientSocket->Address="127.0.0.1";rn pClientSocket->Port=7500;rn pClientSocket->ClientType=ctBlocking;rn pClientSocket->Socket->ClientType=ctBlocking;rn pClientSocket->Active=true;rnrnwhile(!Terminated)rnrn if(pClientSocket->Active)rn rn const int nBufferCount=2000;rn char cBuffer[nBufferCount];rn TWinSocketStream *pStream;rnrn tryrn rn pStream = new TWinSocketStream(pClientSocket->Socket, 4000);rnrn tryrn rnrn memset(cBuffer,0,nBufferCount);rn pStream->WaitForData(4000);rn //char quest[]="wait";rn //pStream->Write(quest.strlen(quest));rn int i=pStream->Read(cBuffer,strlen(cBuffer));rn Form1->Edit2->Text=AnsiString(cBuffer);rn rn rn catch (Exception &E)rn rn ::MessageBox(NULL,E.Message.c_str(),"eerr",MB_OK);rn rn rn __finallyrn rn delete pStream;rn rn rnrnrnrnrnServerSocket在ClientConnect事件中写rnvoid __fastcall TForm1::ServerSocket1ClientConnect(TObject *Sender,rn TCustomWinSocket *Socket)rnrn Socket->SendText("ServerSocket1ClientConnectokok");rnrn但是接受不到数据,不用thread,ClientSocket用非阻塞,在onread事件却可以独到,help me
C#串口通讯接收不到数据
rn我用C#写的串口通讯软件,串口通讯类用的是.Net的[color=#339966]SerialPort[/color]类。rn不知道为什么,同样的操作,[color=#FF00FF]有时候PDA发送的数据能够接收到,有时候接收不到。[/color]rn而以前别人用Delphi写的串口通讯软件都能和PDA正常通讯。(和我现在做的这个功能一模一样,也是与PDA通讯)并且我们的串口参数:波特率等都设置的一样。
急!!!rs485 接收不到数据
RS485通信,带有RS232转485接口,用电脑的串口调试助手发送命令,在电脑上能看到有正确的数据返回,但是用FPGA发送同样的命令后,没有数据返回(FPGA的tx端有数据发送会亮绿灯,rx端有数据返回会亮红灯,发送端的数据接到电脑上看也是验证了正确的,但是就是没有数据返回,连红灯都不亮一下)求解啊!!用串口调试助手收发都没有问题,在FPGA的板上就不行了。。
串口通讯:接收不到完整的数据?
用mscomm串口控件,rn设置接收20个字节时,触发事件,rnrn但有事件触发,但收到的数据不足20个字节。rnrn用BusHound监控查看,发现,是分二段数据还回。。rnrn请问下,这种情况要怎么处理?rnrn:会提示:rn
MFC 串口通信 接收不到数据
程序之前写好了,运行没问题。但后来我重装了系统,所以要重新装了环境。导致现在的程序出现了问题,只能发送数据了,不能接收数据(我从网上也下载了好几个写的代码,发现是同样的问题)。rn程序可以运行,但一旦接收数据,调试栏就会有这样的异常[img=https://img-bbs.csdn.net/upload/201511/04/1446604050_979741.png][/img]rnDemo.exe 中的0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0030eb7c 处的 COleDispatchException。rnDemo.exe 中的0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x00000000 处的 [rethrow]。rn之后我只运行。发现这样的提示rnDemo.exe 中的0x753db9bc 处最可能的异常: 0x000006BA: RPC 服务器不可用。rnDemo.exe 中的0x753db9bc 处最可能的异常: 0x000006BA: RPC 服务器不可用。rnDemo.exe 中的 0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0039cd20 处的 nNIVISA_PXI_PLUGIN_DM_15_0::nNIPXITOOLS000::tIniFileIOException。rnDemo.exe 中的 0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0039cd20 处的 nNIVISA_PXI_PLUGIN_DM_15_0::nNIPXITOOLS000::tIniFileIOException。rnDemo.exe 中的 0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0039cd20 处的 nNIVISA_PXI_PLUGIN_DM_15_0::nNIPXITOOLS000::tIniFileIOException。rnDemo.exe 中的 0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0039cd20 处的 nNIVISA_PXI_PLUGIN_DM_15_0::nNIPXITOOLS000::tIniFileIOException。rnDemo.exe 中的 0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0039e1fc 处的 _com_error。rn这些都与0x753db9bc有关。
RecvOneOrMore为什么接收不到数据
我测试socket的代码如下,发送一个长度为6字节,内容均为0的请求包,正常情况应该可以从服务器得到一个响应包,但是为什么这段代码接收不到数据,请高手赐教!谢谢rn[code=C/C++]void CTcpEngine::RunL()rn rn switch(iChannelState)rn rn case EChannelConnected:rn rn if (iStatus==KErrNone)rn rn // Connection was made successfullyrn iStatusText=_L("\nConnection established");rn NotifyProgress();rn rn rn TText8 pack[6] = 0, 0, 0, 0, 0, 0;rn iWriteDataBuffer.Append(pack, 6);rn rn iChannelState=EChannelSending;rn iSocket.Send(iWriteDataBuffer, 0, iStatus);rn SetActive();rn rn elsern rn iStatusText=_L("\nFailed to connect");rn NotifyProgress();rn rn rn break;rnrn case EChannelSending:rn rn // Receive data from the "server"rn iStatusText=_L("\nSent data");rn NotifyProgress();rnrn iSocket.RecvOneOrMore(iReadDataBuffer, 0, iStatus, iRecvLen);rn iChannelState=EChannelReceiving;rn SetActive();rn rn break;rnrn case EChannelReceiving:rn rn if (iStatus == KErrNone)rn rn // Data was received successfullyrn iStatusText=_L("\nReceived data");rn NotifyProgress();rn // Display received data in user interfacern //iStatusText=iReadDataBuffer;rn //NotifyProgress();rn rn elsern rn iStatusText=_L("\nError reading data");rn NotifyProgress();rn rnrn iStatusText=_L("\nClose the connection...");rn NotifyProgress();rnrn iSocket.Close();rn iStatusText=_L("\nEnd of test.");rn NotifyProgress();rn rn break;rn default:rn break;rn rn [/code]
ajax springmvc接收不到数据
后台 @RequestMapping(value = &quot;getAllChildByRId&quot;, method = RequestMethod.GET) public ModelAndView getAllChildByRId(String rId, Model model) { XLog.showLogInfo(&quot;rId = &quot; + rId); Model...
C#串口通信 接收不到数据
[code=C#]rnusing System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Linq;rnusing System.Text;rnusing System.Windows.Forms;rnusing System.IO.Ports;rnrnrnnamespace GPSPortrnrn public partial class Form1 : Formrn rn private SerialPort comm = new SerialPort();rn private StringBuilder builder = new StringBuilder();rn private long Receive_count = 0, Send_count = 0;rnrn public Form1()rn rn InitializeComponent();rn rnrn private void Form1_Load(object sender, EventArgs e)rn rn string[] ports = SerialPort.GetPortNames();rn Array.Sort(ports);rnrn PortName.Items.AddRange(ports);rn PortName.SelectedIndex = PortName.Items.Count > 0 ? 0 : -1;rn Baudrate.SelectedIndex = Baudrate.Items.IndexOf("9600");rnrn comm.NewLine = "\r\n";rn comm.RtsEnable = true;rnrn comm.DataReceived += comm_DataReceived;rn rn void comm_DataReceived(object sender,SerialDataReceivedEventArgs e)rn rn int n = comm.BytesToRead;rn byte[] buf=new byte[n];rn Receive_count += n;rn comm.Read(buf,0,n); rn string ReceiveText1;rn ReceiveText1 = builder.ToString();rn builder.Remove(0,builder.Length);rn label3.Text = "Get:" + Receive_count.ToString();rn this.Invoke((EventHandler)(delegatern rn builder.Append(Encoding.ASCII.GetString(buf));rn this.ReceiveText.AppendText(builder.ToString());rn ReceiveText1 = builder.ToString();rn string[] str =ReceiveText1.Split(',');rn foreach (string i in str) Arrtext.AppendText(i.ToString()+" ");rn ReceiveText.AppendText(ReceiveText1+"\n");rn ));rn rnrn private void button1_Click(object sender, EventArgs e)rn rn if (comm.IsOpen)rn rn comm.Close();rn rn elsern rn comm.PortName = PortName.Text;rn comm.BaudRate = int.Parse(Baudrate.Text);rn comm.ReadBufferSize = 4096;rn comm.WriteBufferSize = 4096;rn comm.DataBits = 8;rn comm.ReceivedBytesThreshold = 1024;rn tryrn rn comm.Open();rn rn catch (Exception ex)rn rn comm = new SerialPort();rn MessageBox.Show(ex.Message);rn rn rn button1.Text = comm.IsOpen ? "Close" : "Open";rn button2.Enabled = comm.IsOpen;rn rnrn private void button2_Click(object sender, EventArgs e)rn rn int n = 0;rn comm.Write(SendText.Text);rn n = SendText.Text.Length;rn Send_count+=n;rn label4.Text = "Set:" + Send_count.ToString();rn rn rnrnrn[/code]
$.post回调函数接收不到数据
[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/2.gif][/img]是什么原因