我通过url向servlet里传值,
url是:
http://localhost:8000/Serclet/test?name=qq&pwd=123
servlet里是这样写的:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name=request.getParameter("name");
String pwd=request.getParameter("pwd");
System.out.println("发送的内容:"+name+"#"+pwd);
request.getSession().setAttribute("name", name);
request.getSession().setAttribute("pwd", pwd);
response.sendRedirect("MyJsp.jsp");
out.flush();
out.close();
}
现在我要通过调用url获得servlet的返回值,请问在servlet里怎么写才可以在下面的代码中获得返回值呢?求高手指教下:
我调用的代码如下:
public static void main(String[] args) {
URL url=null;
BufferedReader budr=null;
try {
url=new URL("http://localhost:8000/Serclet/test?name=qq&pwd=123");
budr=new BufferedReader(new InputStreamReader(url.openStream()));
System.out.println("qqqqqq");
System.out.println(budr.readLine());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}