我正在使用JSF,我有一个支持bean方法,它执行一些处理并设置一个变量'outcome',然后根据faces-config.xml导航规则决定导航到的下一页.
我想要做的是在导航下一页时将参数添加到URL(在支持bean中?).但是在支持bean方法的Handler中,没有对HttpRequest对象的引用.这是一个已经存在了很长时间的现有处理程序,所以我想知道我该怎么做
request.setAttribute("name", value);
Run Code Online (Sandbox Code Playgroud)
JSF有不同的方法吗?任何帮助非常感谢.
HI BalusC,
我正在尝试实现您在下面解释的内容,但是我遇到了问题.这就是我所拥有的:
StringBuffer url = ( (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()).getRequestURL();
url.append( "?serialNumber=");
url.append(regBean.getSerialNumber());
try{ FacesContext.getCurrentInstance().getExternalContext().redirect(url.toString());
}catch (Exception ex){
ex.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
没有生成异常,但是我收到500 Http错误"服务器遇到了未知错误." 日志显示了更多细节但不足以提供帮助:
ERROR [生命周期] JSF1054 :(阶段ID:INVOKE_APPLICATION 5,视图ID:/registration/productValidation.jsp)阶段执行期间抛出异常:javax.faces.event.PhaseEvent [source = com.sun.faces.lifecycle.LifecycleImpl@591dae ] 11:19:12,186 ERROR [[Faces Servlet]] servlet Faces Servlet的Servlet.service()在com的org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435)抛出异常java.lang.IllegalStateException .sun.faces.context.ExternalContextImpl.redirect(ExternalContextImpl.java:421)at com.sun.faces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:181)at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl .java:130)at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents上的org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)中的javax.faces.component.UICommand.broadcast(UICommand.java:387) AjaxViewRoot.java:296)org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRo)ot.java:253)org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)at com.sun.faces.lifecycle .Phase.doPhase(Phase.java:100)
任何想法都将非常感激.谢谢!
好的,谢谢你的评论,我改变了一些东西,现在我有:
FacesContext.getCurrentInstance().getExternalContext().redirect("mypage.jsp?serialNumber=555555");
Run Code Online (Sandbox Code Playgroud)
在调试时,我可以看到重定向正在工作,因为在mypage.htm上我正在显示来自resourcebundle(属性文件)的一些头文件,所以当它试图获得要显示的头时,它在下面的行上遇到NullPointer:
FacesContext context = FacesContext.getCurrentInstance();
Run Code Online (Sandbox Code Playgroud)
context为null,因此日志显示NullPointer错误,但页面的url是正确的我可以看到地址栏显示 http://..../mypage.jsp?serialNum = 5555 正如预期的那样!它似乎只是显示页面的内容有困难.到目前为止如此接近;-(
我想用@QueryParam重载一个方法,但每次我尝试执行这个代码时它会抛出:
SEVERE: Exception occurred when intialization
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
Run Code Online (Sandbox Code Playgroud)
我的代码是:
@GET
@Path("/test")
@Produces("text/plain")
public String getText(@QueryParam("PID") String pid)
{
return pid;
}
@GET
@Path("/test")
@Produces("text/plain")
public String getText(@QueryParam("PID") String pid, @QueryParam("NAME") String name)
{
return pid + name;
}
Run Code Online (Sandbox Code Playgroud) TableName:人
id | 名字| 年龄| 地点
id_1 | A | 23 | 新西兰
id_2 | B | 12 | 印度
id_3 | C | 26 | 新加坡
id_4 | D | 30 | 火鸡
keys:id - > hash和age-> range
问题1
我正在尝试执行一个查询:"从年龄> 25岁的人中选择*"我可以使用"从id = id_1和年龄> 25岁的人中选择年龄"这样的查询,这不是我需要的,只需要选择所有值.
如果我不需要年龄作为范围索引,我应该如何修改我的查询参数只返回符合标准的记录列表:年龄> 25?
问题2
当第23行或第24-41行被注释时,AWS会抛出错误.:查询错误:ValidationException:必须在请求中指定KeyConditions或KeyConditionExpression参数.状态码:400,请求ID:[]
是否需要KeyConditions/KeyConditionsExpressions参数?这是否意味着我无法在不属于索引一部分的参数上查询表?
func queryDynamo() {
log.Println("Enter queryDynamo")
svc := dynamodb.New(nil)
params := &dynamodb.QueryInput{
TableName: aws.String("people"), // Required
Limit: aws.Long(3),
// IndexName: aws.String("localSecondaryIndex"),
ExpressionAttributeValues: map[string]*dynamodb.AttributeValue{
":v_age": { // Required
N: aws.String("25"),
},
":v_ID": …Run Code Online (Sandbox Code Playgroud) 我正在为我的应用程序构建一个RESTful API,我希望尽可能保持干净透明.
我需要创建一个身份验证端点,我最有意义的是构建它,以便用户可以通过以下方式进行身份验证:
GET https://example.com/
auth?identity=<username_or_email>&password=<password>
Run Code Online (Sandbox Code Playgroud)
正如我所说,在查询参数中使用HTTP GET方法传递用户auth数据对我来说似乎很干净.
但我想问你实际上有多安全.考虑到它将通过SSL/TLS加密,您认为传输这样的用户凭据是个好主意吗?
我想将枚举值列表作为HTTP查询参数传递。服务器端的入口点如下所示:
@GET
@Path("/getMyResult")
public MyResultType getMyResult(@QueryParam("me") final List<MyEnum> myEnums)
Run Code Online (Sandbox Code Playgroud)
无法修改。考虑MyEnum包含的值MyValue1,MyValue2,MyValue3和MyValue4。(MyResultType与该问题无关。)仅传递一个值,如下所示,效果很好(这对我来说有点奇怪):
http://localhost/getMyResult?me=MyValue1
Run Code Online (Sandbox Code Playgroud)
但是,以这种方式传递元素列表:
http://localhost/getMyResult?me=[MyValue1,MyValue3,MyValue4]
Run Code Online (Sandbox Code Playgroud)
或者这样:
http://localhost/getMyResult?me=MyValue1,MyValue3,MyValue4
Run Code Online (Sandbox Code Playgroud)
或者这样:
http://localhost/getMyResult?me=["MyValue1","MyValue3","MyValue4"]
Run Code Online (Sandbox Code Playgroud)
不起作用,它将引发类似以下的异常(第一个选项的错误消息):
RESTEASY001720: Unable to extract parameter from http request: javax.ws.rs.QueryParam(\"me\") [...]
No enum constant com.mycompany.myapp.MyEnum.[MyValue1,MyValue3,MyValue4]
Run Code Online (Sandbox Code Playgroud)
谁能告诉我如何将MyEnum元素列表作为HTTP GET查询参数传递?谢谢!
我在页面上使用标准Google分析代码段将信息发送到Google Analytics.
由于各种原因,我的页面到达时带有查询参数.
在理想的世界中,情况并非如此,但它不是一个完美的世界,所以我必须避免将其发送到谷歌分析,因为它包含个人信息.
我尝试过以下方法:
这里有什么建议:https: //stackoverflow.com/a/3669333/2295284,如下:((我很抱歉格式化的确不是玩球D :)
_gaq.push(['_trackPageview', location.pathname ]);
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject']=r;
i[r]=i[r]||function() {
(i[r].q=i[r].q||[]).push(arguments)
}, i[r].l=1*new Date();
a=s.createElement(o), m=s.getElementsByTagName(o)[0];
a.async=1;
a.src=g;
m.parentNode.insertBefore(a,m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', '@gaToken', 'auto');
ga('send', 'pageview', location.pathname);
Run Code Online (Sandbox Code Playgroud)我一直在手动向网址添加查询参数,并使用ObservePoint检查内容.内容信息包含文档位置URL" http:// localhost/my/url/page?uiop = qwert "...这似乎意味着_gaq.push行根本没有做任何事情.
我尝试深入了解该功能并手动更改网址,但它只是导致无限循环的页面刷新:
(function(i,s,o,g,r,a,m){alert(i.location.href); var locn = i.location.href.indexOf("?")i.location.href = i. location.href.substring(0,locn)i ['GoogleAnalyticsObject'] = r; i [r] = i [r] || function(){(i [r] .q = i [r] .q || []).push(arguments)},i …
高级REST客户端似乎是一个简洁的REST客户端实现来尝试REST-API.但是,我找不到如何将查询参数添加到API的URI中,但是没有将它与URI本身相提并论.
例如,生成一些像
https://api.example.com/v2/users/?age=25&fanOf=lakers
我想添加像"age"=25和的参数"fanOf"="lakers".
我知道它存在于某个地方,但无法明确地找到它,否则直观的界面,"高级REST客户端".
我有一条路
<Route path="/account/:accountid/LoginPage"
component={LoginPage}/>
Run Code Online (Sandbox Code Playgroud)
如果网址是 - >,这可以正常工作/account/12332/LoginPage.我想要可选的查询参数.网址结构就像
/account/12322/LoginPage?User=A&User=B
Run Code Online (Sandbox Code Playgroud)
我修改了路径为
<Route path="/account/:accountid/LoginPage(/:User)"
component={LoginPage}/>
Run Code Online (Sandbox Code Playgroud)
在此之后,如果我尝试访问该网址,它不会将我重定向到相应的页面,而是会抛出错误
useBasename.js:56 Uncaught TypeError: history.getCurrentLocation is not a function
at Object.getCurrentLocation (useBasename.js:56)
at Object.getCurrentLocation (useQueries.js:64)
at Object.listen (createTransitionManager.js:246)
at Object.componentWillMount (Router.js:97)
at ReactCompositeComponent.js:347
at measureLifeCyclePerf (ReactCompositeComponent.js:75)
at ReactCompositeComponentWrapper.performInitialMount (ReactCompositeComponent.js:346)
at ReactCompositeComponentWrapper.mountComponent (ReactCompositeComponent.js:257)
at Object.mountComponent (ReactReconciler.js:45)
at ReactCompositeComponentWrapper.performInitialMount (ReactCompositeComponent.js:370)
Run Code Online (Sandbox Code Playgroud) 将多维数组传递给rails控制器时,它似乎无法正确解析.我做错了吗?
url: http://localhost:3000/people?sort[][]=lastname&sort[][]=1&sort[][]=firstname&sort[][]=1
params: {
"sort" => [
[0] nil,
[1] nil,
[2] nil,
[3] nil
],
"action" => "index",
"controller" => "people"
}
Run Code Online (Sandbox Code Playgroud)
应该:
params: {
"sort" => [
[0] => [
[0] => 'lastname',
[1] => 1
],
[1] = > [
[0] => 'firstname',
[1] => 1
]
],
"action" => "index",
"controller" => "people"
}
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,有多个链接,其中我有一些links相同route但有不同query parameters.
说,我有像这样的链接:
.../deposits-withdrawals
.../deposits-withdrawals?id=1
.../deposits-withdrawals?id=2&num=12321344
Run Code Online (Sandbox Code Playgroud)
当我在上述路线之一并且原生于上述其他路线时,路线不会改变.甚至没有任何类似ngOnInit或被ngOnChanges调用的函数.我已经将参数更改queryParameters为matrixParameters但没有成功.我经历了很多链接和答案.但是,他们都没有解决我的问题.帮帮我解决这个问题.
谢谢...
编辑:
<button routerLink="/deposits-withdrawals" [queryParams]="{ type: 'deposit' ,'productId': selectedBalance.ProductId}" class="wallet-btns">DEPOSIT {{selectedBalance.ProductSymbol}}</button>
<button routerLink="/deposits-withdrawals" [queryParams]="{ type: 'withdrawal' ,'productId': selectedBalance.ProductId }" class="wallet-btns">WITHDRAW {{selectedBalance.ProductSymbol}}</button>
Run Code Online (Sandbox Code Playgroud) query-parameters ×10
http ×2
java ×2
rest ×2
angular ×1
aws-sdk ×1
client ×1
controller ×1
get ×1
go ×1
javascript ×1
jersey ×1
jsf ×1
list ×1
overloading ×1
react-router ×1
reactjs ×1
routing ×1
spring ×1