gpt4 book ai didi

java - Servlet 代码在不同场景下转发到同一页面而不是另一个页面

转载 作者:行者123 更新时间:2023-12-02 03:15:42 25 4
gpt4 key购买 nike

根据我的要求,主页包含 TextField 和单选按钮。

场景 1:当用户在 TextField 中输入“locationno”并提交时,servlet 将调用 DB 并从数据库中获取输入的 locationno 的记录,然后转发到 locationDetails 页面。其工作正常

场景2:当用户在TextField中输入locationno时,同时单击单选按钮,servlet将调用DB并获取特定locationno的所有详细信息,然后转发到locationAllDetails页面。这里它正在正确获取记录,但是它总是转发到 locationDetails 页面而不是 locationAllDetails 页面。当我在日志中输入 TextField 和单选按钮后单击提交按钮时,它显示 Outputtype(单选按钮名称)为“ALL”,但它仍然始终转发到 locationDetails 页面而不是 locationAllDetails 页面

下面的代码有什么问题,我的怀疑是由于这一行

 request.setAttribute("locationbean", locResultsList);

请找到下面的代码并提供帮助。

          if (strSearchType != null && strSearchType.equals("locationNo")){
inLoop = "siteID : ";
RequestDispatcher rd = null;
String locationNo = null;

String flow = null;
String pagePosition = null;
String sitePagePositon = null;
String outputType = null;

List locResultsList = null;



try{
pagePosition = request.getParameter("pagePosition");

if(pagePosition != null){
request.setAttribute("pagePosition",pagePosition);
rd = this.getServletContext().getRequestDispatcher("/jsp/locationDetails.jsp");
rd.forward(request, response);
}
else{
flow = "locationSearchFlow";
locationNo = request.getParameter("locationNo");
session.setAttribute("locationNo",locationNo);
outputType = request.getParameter("outputType");

rd = this.getServletContext().getRequestDispatcher("/jsp/SiteSearchResults.jsp");

LocationCodeDAOBean locDaoBean = new LocationCodeDAOBean();

List locResultsList = locDaoBean.getLocationResults(locationNo);

request.setAttribute("locationbean", locResultsList);

if(locResultsList.size() == 0){
rd = this.getServletContext().getRequestDispatcher("/jsp/ExceptionPage.jsp");
request.setAttribute("errorMessage","No Records Returned for Site Item Location Details, Req Number = "+siteID);
rd.forward(request, response);
}else if(outputType.equals("ALL")){

locationNo = request.getParameter("locationNo ");
session.setAttribute("locationNo ",locationNo );

LocationCodeDAOBean locDaoALLBean = new LocationCodeDAOBean();
List locAllResultsList = locDaoALLBean .getALLLocationResults(locationNo);

request.setAttribute("pagePosition", "0");
request.setAttribute("locationALLbean", locAllResultsList);
session.setAttribute("flow",flow);
rd = this.getServletContext().getRequestDispatcher("/jsp/LocationSearchAllResults.jsp");
rd.forward(request, response);
}

else{
rd = this.getServletContext().getRequestDispatcher("/jsp/ExceptionPage.jsp");
request.setAttribute("errorMessage","No Records Returned for Site Item Location Details, Req Number = "+siteID);
rd.forward(request, response);
}
}

最佳答案

每次转发后都会返回。

if (pagePosition != null) {
request.setAttribute("pagePosition", pagePosition);
rd = this.getServletContext().getRequestDispatcher("/jsp/locationDetails.jsp");
rd.forward(request, response);
return;
}

关于java - Servlet 代码在不同场景下转发到同一页面而不是另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40345054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com