小编ris*_*iag的帖子

如何在URL中传递多个参数?

我试图弄清楚如何在URL中传递多个参数.我想将我的android类的纬度和经度传递给java servlet.我怎样才能做到这一点?

URL url;
double lat=touchedPoint.getLatitudeE6() / 1E6;
double lon=touchedPoint.getLongitudeE6() / 1E6;
url = new URL("http://10.0.2.2:8080/HelloServlet/PDRS?param1="+lat+lon);
Run Code Online (Sandbox Code Playgroud)

在这种情况下,输出(写入文件)是28.53438677.472097.这是有效的,但我想在两个单独的参数中传递纬度和经度,以便减少我在服务器端的工作.如果不可能,我怎么能至少在lat和lon之间添加一个空格,以便我可以使用tokenizer类来获取我的纬度和经度.我尝试过以下行,但无济于事.

    url = new URL("http://10.0.2.2:8080/HelloServlet/PDRS?param1="+lat+" "+lon);
output- Nothing is written to file
        url = new URL("http://10.0.2.2:8080/HelloServlet/PDRS?param1="+lat+"&?param2="+lon);
output- 28.534386 (Only Latitude)
        url = new URL("http://10.0.2.2:8080/HelloServlet/PDRS?param1="+lat+"?param2="+lon);
output- 28.532577?param2=77.502996
Run Code Online (Sandbox Code Playgroud)

我的servlet代码如下:

req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("UTF-8");
final String par1 =  req.getParameter("param1");
final String par2 = req.getParameter("param2");
FileWriter fstream = new FileWriter("C:\\Users\\Hitchhiker\\Desktop\\out2.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write(par1);
out.append(par2);
out.close();
Run Code Online (Sandbox Code Playgroud)

此外,我想知道这是将数据从Android设备传递到服务器的最安全和最安全的方式.

java url android servlets

32
推荐指数
1
解决办法
32万
查看次数

无法在Android模拟器中使用键盘

我刚刚在Ubuntu 12.04中设置了Android开发环境.我为Android版本2.3.3制作了AVD并在其上运行了我的应用程序.但我无法使用右侧的计算机键盘或键盘.这是什么原因?

我的ADT版本是20.0.我之前在Windows上开发,它工作正常.

android android-virtual-device android-emulator

28
推荐指数
2
解决办法
2万
查看次数

如何从Java中的文本文件中读取逗号分隔值?

我有这个文本文件,其中包含地图上不同点的纬度和经度值.

我如何将我的弦乐分成纬度和经度?与其他分隔符(如空格或制表符等)一起执行这些类型的事物的一般方法是什么?样本文件:

28.515046280572285,77.38258838653564
28.51430151808072,77.38336086273193
28.513566177802456,77.38413333892822
28.512830832397192,77.38490581512451
28.51208605426073,77.3856782913208
28.511341270865113,77.38645076751709
Run Code Online (Sandbox Code Playgroud)

这是我用来从文件中读取的代码:

try(BufferedReader in = new BufferedReader(new FileReader("C:\\test.txt"))) {
    String str;
    while ((str = in.readLine()) != null) {
        System.out.println(str);
    }
}
catch (IOException e) {
    System.out.println("File Read Error");
}
Run Code Online (Sandbox Code Playgroud)

java string io

7
推荐指数
1
解决办法
11万
查看次数

Getline不断获得换行符.我怎么能避免这个?

基本上我首先采用整数作为输入然后测试用例.我的每个测试用例都是一个字符串.如果字符串的起始模式匹配"HI A"并且它不区分大小写,我想要打回字符串.我写下面的代码来完成这个.我的问题是,当我在每次输入后按Enter键时,getline将换行符作为新输入.我试图通过在每次输入后使用额外的getline来解决这个问题,但问题仍然存在.程序卡在循环中,即使我已经设置了休息条件.我究竟做错了什么?

#include <iostream>
#include <string>
using namespace std;
int main(){
    int N;
    cin >>N;
    string nl;
    getline(cin,nl);
    for (int i=0;i<N;i++){
        string s;
        getline(cin,s);
        //cout <<"string"<<s<<endl;
        int flag=0;
        if ((s.at(0)=='h'||s.at(0)=='H')&&(s.at(1)=='i'||s.at(1)=='I')&&(s.at(2)==' ')&&(s.at(3)=='a'||s.at(3)=='A')) flag=1;

        if (flag==1) cout << s;
        //cout << "not " <<s;
        string ne;
        cout << "i="<< i<<endl;
        if (i==N-1) {break;}
        getline(cin,ne);

    }
}
Run Code Online (Sandbox Code Playgroud)

以下是示例输入:

5
Hi Alex how are you doing
hI dave how are you doing
Good by Alex
hidden agenda
Alex greeted Martha by saying Hi Martha …
Run Code Online (Sandbox Code Playgroud)

c++ string getline

7
推荐指数
2
解决办法
3万
查看次数

malloc的以下代码行是什么?

我有以下实现来镜像二叉树.

#include<stdio.h>
#include<stdlib.h>

/* A binary tree node has data, pointer to left child
   and a pointer to right child */
struct node
{
    int data;
    struct node* left;
    struct node* right;
};

/* Helper function that allocates a new node with the
   given data and NULL left and right pointers. */
struct node* newNode(int data)

{
  struct node* node = (struct node*)
                       malloc(sizeof(struct node));
  node->data = data;
  node->left = NULL;
  node->right = NULL;

  return(node);
}


/* Change a tree …
Run Code Online (Sandbox Code Playgroud)

c malloc pointers sizeof

4
推荐指数
1
解决办法
2万
查看次数

为什么我得到未定义的睡眠错误参考?

码:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

struct subscriber {
    char phonenumber[20];
    char name[50];
    float amount;
} s;

void addrecords();
void listrecords();
void modifyrecords();
void deleterecords();
void searchrecords();
void payment();

char get;

int main()
{
    int password;
    int phonenumber;
    char choice;

    system("cls");

    printf
    ("\n\n\n\n\n\n\n\n\n**********************************************************************");
    printf("\n\t\t---WELCOME TO THE TELECOM BILLING MANAGEMENT SYSTEM---");
    printf("\n\t\t****************************************************************");

    Sleep(2000);

    getch();

    system("cls");

    while (1) {
        system("cls");
        printf("\n enter\n A : for adding new records.\n L : for list of records");
        printf("\n M : for modifying records.\n P …
Run Code Online (Sandbox Code Playgroud)

c sleep include

2
推荐指数
1
解决办法
1万
查看次数

我该怎么办才能不显示所有情节的图例?

这是我的代码:

N=100;
n=50;
tau=0.001;
h=0.01;
lambda=tau/h;
mu=lambda/2;
u=zeros(N,n);
u1=zeros(N,n);
u2=zeros(N,n);
phi=zeros(n,1);
for i=1:n
    for j=1:N
        u(j,i)=cos(2*pi*i*(j-1)*h);
        u1(j,i)=cos(2*pi*i*((j-1)*h-tau));
    end

    for j=2:N
        u2(j,i)=u(j,i)-lambda*(u(j,i)-u(j-1,i));
    end
u2(1)=0;
phi(i,1)=2*pi*i/N;    
end
uf=zeros(n,1);
uf1=zeros(n,1);
uf2=zeros(n,1);

for i=1:n
   for j=1:N
       uf(i,1)=uf(i,1)+(u(j,i)*exp(-1i*(j-1)*phi(i,1)))/100;
       uf1(i,1)=uf1(i,1)+u1(j,i)*exp(-1i*j*phi(i,1))/100;
       uf2(i,1)=uf2(i,1)+(u2(j,i)*exp(-1i*(j-1)*phi(i,1)))/100;
   end
end
final=zeros(n,1);
for i=1:n
    final(i,1)=-(h/(1i*tau))*(log(uf2(i)/uf(i)));
end


figure;
hold on 
z=1:1:n;
b = real(final(z,1));
%plot(phi(z,1),b,'o');
c = imag(final(z,1));
%plot(phi(z,1),c,'-');
%plot(phi(z,1),0,'-');
plot(phi(z,1),b,'ro',phi(z,1),c,'ko',phi(z,1),0,'k-');
legend('Real','Imaginary');
legend ('Location','NorthWest');
xlabel('Reduced Wavenumber')
ylabel('Modified Wavenumber')
Run Code Online (Sandbox Code Playgroud)

我正在y = 0处绘制一条线作为参考.我不希望他们在传说中.但我得到这个数字: 在此输入图像描述 我该如何解决这个问题?

matlab plot matlab-figure

2
推荐指数
1
解决办法
217
查看次数

我如何使用此调试宏?

using namespace std;
#ifdef DEBUG
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
     #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;


int main(){
    int a=1,b=2,c=3;
    debugger(a,b,c);
}
Run Code Online (Sandbox Code Playgroud)

我找到了这个调试宏,我正在尝试使用它,但这不起作用.我收到以下错误:

ubuntu:~ g++ -DEBUG a.cpp -o a
a.cpp: In function ‘int main()’:
a.cpp:81:16: error: no matching function for call to ‘debugger::debugger(int&, int&, int&)’
a.cpp:81:16: note: candidates are:
a.cpp:62:8: note: debugger::debugger()
a.cpp:62:8: note:   candidate expects 0 …
Run Code Online (Sandbox Code Playgroud)

c++ macros

2
推荐指数
1
解决办法
212
查看次数

为什么我在C中获取参数初始化错误?

struct subscriber

{

  char phonenumber[20];

  char name[50];

  float amount;

}s;

void modifyrecords()

  FILE *f;

  char phonenumber[20];

  long int size=sizeof(s);

  if((f=fopen("c:/file.ojs","rb+"))==NULL)

    exit(0);

  system("cls");

  printf("Enter phone number of the subscriber to modify:");

  scanf("%[^\n]",phonenumber);

  fflush(stdin);

  while(fread(&s,sizeof(s),1,f)==1)

  {

    if(strcmp(s.phonenumber,phonenumber)==0)

    {

      system("cls");

      printf("\n Enter phone number:");

      scanf("%s",&s.phonenumber);

      printf("\n Enter name: ");

      fflush(stdin);

      scanf("%[^\n]",&s.name);

      printf("\n Enter amount: ");

      scanf("%f",&s.amount);

      fseek(f,-size,SEEK_CUR);

      fwrite(&s,sizeof(s),1,f);

      break;

    }

  }

  fclose(f);

}
Run Code Online (Sandbox Code Playgroud)

C:\ Users***\Desktop\ac | 394 |错误:参数'size'已初始化| 我在这段代码中得到参数'size'的初始化错误.谷歌搜索后我发现我可能必须通过某些参数来抑制这些错误.这是唯一的解决方案吗?实际上我正在使用Code :: Blocks,所以如果是唯一的方法如何在其中传递命令行参数?

c parameters initialization

1
推荐指数
1
解决办法
1万
查看次数

在这里进行按位移位有什么意义?

我发现这个代码用于快速I/O.

    #include <cstdio>

inline void fastRead_int(int &x) {
    register int c = getchar_unlocked();
    x = 0;
    int neg = 0;

    for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

    if(c=='-') {
        neg = 1;
        c = getchar_unlocked();
    }

    for(; c>47 && c<58 ; c = getchar_unlocked()) {
        x = (x<<1) + (x<<3) + c - 48;
    }

    if(neg)
        x = -x;
}

inline void fastRead_string(char *str)
{
    register char c = 0;
    register int i = 0;

    while …
Run Code Online (Sandbox Code Playgroud)

c c++ io bitwise-operators

1
推荐指数
2
解决办法
514
查看次数