有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java通过向url添加编辑文本值来访问网站数据库

我希望访问我的网站数据库,并通过编辑文本和onClick向其中添加用户。我已经完成了大部分应用程序。从pc上实现这一点非常简单,因为我只需在URL的适当位置添加用户编号,然后将其添加到数据库中

这是添加了用户的URl

http://something.com/user/426561?token=dYG8hW5TY4LBU8jfPb10D3IcsSx8RTo6

我想使用编辑文本在426561所在的位置插入一个数值。这就是我到目前为止所做的,我的网站抛出了一个无效的用户号错误,这是它应该做的

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);




    edttext= (EditText)findViewById(R.id.editText1);


    Button tutorial2 = (Button) findViewById(R.id.button1);
      tutorial2.setOnClickListener(new OnClickListener() {


        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.putExtra("edttext", edttext.getText().toString());
               intent.setData(Uri.parse("http://something.com/user/= edttext?token=dYG8hW5TY4LBU8jfPb10D3IcsSx8RTo6"));
              startActivity(intent);    

        }

      });

我已经添加到了URL,但显然我做得不对。有什么想法吗


共 (1) 个答案

  1. # 1 楼答案

    用这个。放额外的东西并不能代替数据

    intent.setData(Uri.parse("http://example.com/user/"+edttext.getText() +"?token=dYG8hW5TY4LBU8jfPb10D3IcsSx8RTo6"));