java判断url中参数为空,java – 如何确保url中没有任何参数?

本文介绍了在JSP中如何使用Spring MVC框架处理没有查询参数的情况,提供了两种方法:通过RequestParam映射和HttpServletRequest对象检查。适合扩展Spring MVC应用的Model属性处理。
摘要由CSDN通过智能技术生成

跟进

由于新的要求必须在JSP中完成,即使下面原始答案中列出的Spring处理程序代码可以添加具有相关信息的Model属性,下面是如何执行此操作.

类似的两种方式如下:

原始答案

你标记了spring-mvc,这意味着你有这样的东西(如果你发布它会很好):

@Controller

public class ProductController {

@RequestMapping("/Product/UniqueId")

public String uniqueId(Model model,

@RequestParam(path="code" , required=false) String code,

@RequestParam(path="sig" , required=false) String sig,

@RequestParam(path="pod" , required=false) String pod,

@RequestParam(path="circle" , required=false) String circle,

@RequestParam(path="location", required=false) String location,

@RequestParam(path="color" , required=false) String color) {

// code here

}

}

以下是检查“无查询参数”的两种方法:

// Get all parameters in a Map

public String uniqueId(Model model,

...,

@RequestParam Map allParams) {

if (allParams.isEmpty()) {

// no query parameters given

}

// code here

}

// Use the request object

public String uniqueId(Model model,

...,

HttpServletRequest request) {

if (request.getQueryString() == null) {

// no query parameters given

}

// code here

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值