servlet3.0 取不到form传回的值
packageservlett;importjava.io.IOException;importjavax.servlet.ServletException;import...
package servlett;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class index
*/
@WebServlet("/index")
public class index extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public index() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String aaString= request.getAttribute("asd").toString();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
今天试验了下 用input submit可以在servlet用getparamater取到,
但是改用javascript提交就取不到form里面的值了 展开
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class index
*/
@WebServlet("/index")
public class index extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public index() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String aaString= request.getAttribute("asd").toString();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
今天试验了下 用input submit可以在servlet用getparamater取到,
但是改用javascript提交就取不到form里面的值了 展开
3个回答
展开全部
你可以system.out.printf一下aaString的值,如果没有 你就改为request.getParameter("asd");再看,aaString的指,还有 去掉toString();你传过来的就是String干嘛还要toString();改吧,不行就把错误代码弄上来,或者doPost里面加个this.doGet(request,response);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Form表单提交的数据,在Servlet中使用request.getParameter("asd");方法来获取相应的值;而request.getAttribute(key)方法是从request作用域中获取指定key的值。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-06
展开全部
request.getAttribute 应该换成request.getParemeter(“asd”);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询