在JSP我如何从URL获取参数?

例如,我有一个URL www.somesite.com/Transaction_List.jsp?accountID=5 我要得到5。 有什么要求吗?getAttribute("accountID")就像有会话或类似的东西吗?


当前回答

String accountID = request.getParameter("accountID");

其他回答

request.getParameter("accountID")就是你要找的。这是Java Servlet API的一部分。更多信息请参见http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequest.html。

使用EL (JSP表达式语言):

$ {param.accountID}

String accountID = request.getParameter("accountID");

第一页: 细节 第二页: <% String id = request.getParameter("userid") //现在您可以使用id查询HSQL详细产品

示例:您想删除带有subject_id的主题记录

@RequestMapping(value="subject_setup/delete/{subjectid}",method = RequestMethod.GET)
public ModelAndView delete(@PathVariable int subjectid) {
    subjectsDao.delete(subjectid);
    return new ModelAndView("redirect:/subject_setup");
}

该参数将用于查询的输入

public int delete(int subjectid) {
    String sql = "update tbl_subject set isdeleted= '1' where id = "+subjectid+"";
    return template.update(sql);
}