小编vin*_*nit的帖子

在servlet中读取表单数据.使用post方法和servlet发布的数据用?q = test1调用

嘿我正在尝试读取使用post方法发送的servlet中的表单数据.并且servlet被称为OnlineExam?q=saveQuestion.现在servlet正在工作:

public class OnlineExam extends HttpServlet {
protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
if(request.getParameter("q").equals("saveQuestion")){
                /*
                 * Save the question provided with the form as well as save the uploaded file if any.
                 */
                saveQuestion(request);
            }
}

protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
//      doGet(request, response);
        saveQuestion(request);
    }
public String saveQuestion(HttpServletRequest request){         
        System.out.println(request.getParameter("question"));

        return "";

    }       
}
Run Code Online (Sandbox Code Playgroud)

HTML表单:

<form action="OnlineExam?q=saveQuestion" method="post">
        <fieldset>
        <legend>Question</legend>
        <textarea class="questionArea" id="question" …
Run Code Online (Sandbox Code Playgroud)

java post servlets

8
推荐指数
2
解决办法
8万
查看次数

标签 统计

java ×1

post ×1

servlets ×1