这是我的jsp:
<form method='post' action='/controller'>
<div >
<input class="form-control" type="text" id="name-input-field" pattern="[A-Z][a-z]+([ -][A-Z][a-z]+)*" required >
</div>
</form>
这是我的servlet:
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.getParameter("name-input-field");//appears null
}
请帮我找到错误。
答案 0 :(得分:6)
getParameter()
方法包含name
标记的input
属性,而不是id
属性。它返回value
的{{1}}属性值。
将input
添加到您的name="name-input-field"
代码,以便在input
中获取其值。
答案 1 :(得分:1)
正如Yogesh所说,req.getParameter使用了名字,但你也必须知道:
想象一下这种情况:
您必须在html中禁用输入选项或任何可以使用的选项:
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
public class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {
private GestureDetector gestureDetector;
private ClickListener clickListener;
public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) {
Log.d("Slider", "constructer");
this.clickListener = clickListener;
gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
@Override
public void onLongPress(MotionEvent e) {
View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
if (child != null && clickListener != null) {
clickListener.onLongClick(child, recyclerView.getChildPosition(child));
}
}
});
}
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
View child = rv.findChildViewUnder(e.getX(), e.getY());
if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
clickListener.onClick(child, rv.getChildPosition(child));
}
Log.d("Slider", "onInterceptTouchEvent" + gestureDetector.onTouchEvent(e));
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
Log.d("Slider", "onTouchEvent" + e);
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
public static interface ClickListener {
public void onClick(View view, int position);
public void onLongClick(View view, int position);
}
}
Well Sr你会得到一个null因为你的请求中没有发送禁用输入;)所以要小心