为什么获取不到username的值
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws
ServletException,
IOException {
// TODO Auto-generated method stub
String username=request.getParameter("username");
System.out.println(username);
if(username!=null&&username.equals("amaker")){
request.getRequestDispatcher("success.html").forward(request, response);
}
else{
request.getRequestDispatcher("faile.html").forward(request, response);
}
<servlet>
<description></description>
<display-name>BasicServlet</display-name>
<servlet-name>BasicServlet</servlet-name>
<servlet-class>demo.BasicServlet</servlet-class>
<init-param>
<param-name>username</param-name>
<param-value>amaker</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>BasicServlet</servlet-name>
<url-pattern>/BasicServlet</url-pattern>
</servlet-mapping>
------解决方案--------------------你在web.xml定义的初始化参数只有在servlet的
init()方法中才能得到,doPost方法只能得到你以post方式提交的数据。
------解决方案--------------------1.看看你的页面代码名字的ID是不是“username”
2.你是有的get还是post方法
3.你的跳转是用的外部跳转还是内部跳转
4.有没有存值到request域中