那么现在我给你写一个代码如果是在页面中传进去的话是这样的:
<form action="login.action(这个是你表单要提交的action名字)" method="get">
<table>
<tr><td>用户名:<input type="text" name="username"></td></tr>
<tr><td>密 码:<input type="password" name="password"></td></tr>
<tr><td><input type="submit" value="提交"></td></tr>
</table>
</form>
把我上边的 代码 放在 xxx.jsp文件的body之间就可以运行了 首先保证你有这个action 那么就不会报错。在你点击提交的时候就能在地址栏中显示你要的东西了。
还有一种就是硬性的写在地址栏中就是http://localhost:8080/.../xxx.jsp?username=你想要的值&password=你想要的值。
你可以在“你想要的值”这部分填写你用来测试的值。这样就可以达到你要的效果了。
提示:用post方法在地址栏中是看不到参数的。
在使用http请求server时常常要传递一些参数给server,如IMEI号、平台号、渠道号、客户端的版本号等一些通用信息,像这些参数我们没有必要每次都拼在url后,我们可以统一添加到http头里。1.HttpClient的设置http头的参数
HttpClient httpclient = new DefaultHttpClient()
httpclient.getParams().setParameter(
CoreConnectionPNames.CONNECTION_TIMEOUT, CONN_TIME_OUT)
HttpGet httpget = new HttpGet(url)
httpget.addHeader("version", SystemInfo.getVersionChars())
httpget.addHeader("client_token", SystemInfo.getIMEI())
httpget.addHeader("platform", SystemInfo.getPlatForm() + "")
httpget.addHeader("channel_id", SystemInfo.getChannelId() + "")
2.HttpURLConnection的设置http头的参数
httpURLConnection.addRequestProperty("version",
SystemInfo.getVersionChars())
httpURLConnection.addRequestProperty("client_token",
SystemInfo.getIMEI())
httpURLConnection.addRequestProperty("platform",
SystemInfo.getPlatForm() + "")
httpURLConnection.addRequestProperty("channel_id",
SystemInfo.getChannelId() + "")
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)