我正在开发一个struts2项目.我在我的项目中创建了url并使用标签传递了参数.我的问题是如何读取动作中的参数?如果这样做,我将能够将参数看作查询字符串.我问,因为我无法在一个教程中看到它.
我想在 url 中发送 json 数据,如下所示。
editTest.jsp?details=374889331-{"aNumber":2}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我发现这个问题令人困惑(但也很有趣),我想向这里的人寻求见解。
我一直在自学JSP和相关技术。我要做的是从JSP到servlet检索参数,然后将它们与If()结合使用。这是我的编码的一部分。
if ((request.getParameter("ID_A") != null || request.getParameter("Password_A") != null) &&
(request.getParameter("ID_B") != null || request.getParameter("Password_B") != null)) {
errorMessage = "Information is detected for the both side";
request.setAttribute("errorMessage", errorMessage);
request.getRequestDispatcher("4_enter_personal_info.jsp").forward(request, response);
} // Other conditions...
Run Code Online (Sandbox Code Playgroud)
这是JSP的一部分(上一步)
<form action="PersonalInfor_to_confirmation_servlet" method="POST">
<h2>For an existing customer</h2>
<p>Customer ID</p>
<input type="text" name="ID_A" value="" />
<p>Password</p>
<input type="text" name="Password_A" value="" />
<br>
<h2>For a new customer</h2>
<p>Set your customer ID</p>
<input type="text" name="ID_B" value="" />
<p>Set your password</p>
<input type="text" name="Password_B" value="" />
//There …Run Code Online (Sandbox Code Playgroud) 当我发送带有空输入的表单时,我正在尝试解决一个错误。
这是我的方法:
@RequestMapping(value = "/modifier.html", method = RequestMethod.POST)
public String modifier(ModelMap map, @ModelAttribute("FormObject") FormObject formObject, BindingResult result, HttpServletRequest req) {
formObject.setModif(true);
String idParam = req.getParameter("idTypeOuverture");
if (result.hasErrors()) {
return "redirect:/gestion.html?section=Configuration&panel=4&ouvrir=modifier";
} else {
//Instructions
}
Run Code Online (Sandbox Code Playgroud)
当出现错误(空输入)时,控制器重定向到此链接以告诉用户更正错误。问题是当我在这里检查参数时,它们看起来是正确的(id、name ...),但在以下方法中 id 变为 null:
@Override
public ModelAndView dispatcher(HttpServletRequest request, HttpServletResponse response) throws RorException {
Map<String, Object> myModel = (Map<String, Object>) request.getAttribute(EnumParam.R_MY_MODEL.getKey());
Enumeration<?> keys = request.getParameterNames();
while (keys.hasMoreElements()) {
String paramName = (String) keys.nextElement();
String value = request.getParameter(paramName);
myModel.put(paramName, value);
}
GlobalSession globalSession = (GlobalSession) …Run Code Online (Sandbox Code Playgroud) 我有一个函数来调用我的Web API.如果TestCallingRemotely设置为,它运行良好[AllowAnonymous].
var httpWebRequest = (HttpWebRequest)WebRequest.Create(
"http://localhost/api/services/myApp/commonLookup/TestCallingRemotely");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) {
string input = "{}";
streamWriter.Write(input);
streamWriter.Flush();
streamWriter.Close();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Run Code Online (Sandbox Code Playgroud)
如何通过username并password到HttpWebRequest授权?
我需要从CLR集成调用我的Web API,它只支持System.Net.
c# httpwebrequest http-request-parameters asp.net-web-api aspnetboilerplate
我想通过Spring过滤器或aspect记录HTTP请求中的请求参数。我尝试了不同的方法,但要么请求参数被调用null,要么方法未被调用。
我正在使用 Postman,这是一个POST请求。
示例请求网址:
http://localhost:8080/AvailableData
请求正文示例:
{
"keyUserAgent": "CFNetwork/1209 Darwin/20.2.0",
"locale": "en_US",
"eid": "8904977033",
"sessionId": "VGA-G20201030-776878787-1AD5-11EB-895C-H78789GJJH"
}
Run Code Online (Sandbox Code Playgroud)
这里调用@Override的方法beforeRequest(),但不会调用我创建的重载方法(我添加了@RequestBody按照其他解决方案获取正文)。
{
"keyUserAgent": "CFNetwork/1209 Darwin/20.2.0",
"locale": "en_US",
"eid": "8904977033",
"sessionId": "VGA-G20201030-776878787-1AD5-11EB-895C-H78789GJJH"
}
Run Code Online (Sandbox Code Playgroud)
在这里它是这样的null:
@Component
public class CustomLoggingFilter extends AbstractRequestLoggingFilter {
protected void beforeRequest(HttpServletRequest request, String message, @RequestBody RequestDTO requestBody) {
requestBody.getKeyUserAgent();
requestBody.getEid();
System.out.println("Eid: " + requestBody.getEid());
System.out.println("getKeyUserAgent: " + requestBody.getKeyUserAgent());
}
}
Run Code Online (Sandbox Code Playgroud) 我的豆有这个:
@ManagedBean
@ViewScoped
public class BookBean implements Serializable
{
@ManagedProperty(value = "#{param.id}") // does not work with @ViewScoped
private String id;
public void init()
{
id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id")
if (id != null) {
System.out.println("ID: " + id);
currentBook = bookService.find(id);
}
}
@PostConstruct
public void post()
{
// does not work with @ViewScoped
System.out.println("ID: " + id);
currentBook = bookService.find(id);
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
Run Code Online (Sandbox Code Playgroud)
目的地Facelet有这个:
<f:metadata> …Run Code Online (Sandbox Code Playgroud) 我有一个这样的链接:http://localhost:8080/ESA/login.jsp?login=failed
在上面的链接结束时设置一个名称login和值的参数failed.
我如何在带有struts的jsp页面中使用此参数if tag.我使用以下代码,但它不起作用.
<s:if test="%{#parameters.login='failed'}">
<div class="error">
<s:text name="user.login.failed"></s:text>
</div>
</s:if>
Run Code Online (Sandbox Code Playgroud) 是否有一些函数可以将请求参数添加到 http 请求中,而您不必“手动”执行此操作?例如,如果我想"user": "x"作为我的请求的参数,以某种方式实现类似
http:test/testing?user=x
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
我知道这个问题可能会重复,但我尝试了很多但没有成功
我需要在 spring boot rest 控制器中创建多个 RequestParam 如下:
@GetMapping("/prd-products/test")
@Timed
public ResponseEntity<List<Test>> getAllTests(@RequestParam (required = false) String search, @RequestParam (required = false) Pageable pageable) {
Page<Test> page = prdProductsService.findAllTest(search, pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/prd-products");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)
当我尝试通过以下网址调用此服务时:
http://localhost:9116/api/prd-products/test?search=id==1,id==2&pageable=0&size=2
Run Code Online (Sandbox Code Playgroud)
它给了我以下错误
"title": "Bad Request",
"status": 400,
"detail": "Failed to convert value of type 'java.lang.String' to required type 'org.springframework.data.domain.Pageable'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.domain.Pageable': no matching editors or conversion …Run Code Online (Sandbox Code Playgroud) java ×4
jsp ×2
request ×2
spring ×2
spring-boot ×2
struts2 ×2
c# ×1
dart ×1
flutter ×1
http ×1
jsf ×1
jsf-2 ×1
json ×1
ognl ×1
pageable ×1
restful-url ×1
servlets ×1
spring-mvc ×1
view-scope ×1