我导入了以下导入javax.servlet.http.*;
我想获得首选语言浏览器
HttpServletRequest request = ServletActionContext.getRequest();
Locale userPreferredLocale = request.getLocale();
Run Code Online (Sandbox Code Playgroud)
我得到一个错误HttpServletRequest无法解决.
如果可能的话,有人可以帮助我并给我一步一步的指导.我不是一个java开发人员,而是一个.net,只是修复一个bug.
非常感谢
假设我的页面上有一个带有method = POST的表单.现在这个表单有一些基本的表单元素,如文本框,复选框等.它的操作URL为http://example.com/someAction.do?param=value
我确实理解这实际上是一件相互矛盾的事情,但我的问题是它是否会在实践中发挥作用.
所以我的问题是;
由于form方法是POST,我的URL中也有一个查询字符串(?param = value)它会正常工作吗?即我能够在我的接收页面上检索param =值(someAction.do)
假设我使用Java/JSP访问服务器端的值.那么在服务器端获取值的方法是什么?语法是否相同,以访问param = value的值以及textbox/radio button/checkbox等表单元素?
我正在使用TestNG和Selenium WebDriver为webapp编写测试套件.
我需要的是为不同的经过身份验证的用户多次运行测试类的所有方法(数据在运行时拉出:来自数据库).所以我需要将数据传递给具有数据提供者的类,该数据提供者提供所有用户的凭据,然后为每个用户创建一个Web驱动程序(为了实验的纯度)并使用@BeforeClass方法中提供的凭据进行身份验证,运行所有@Test该类的方法,并@AfterClass拆除关闭web驱动程序.
我怎样才能做到这一点?
我尝试这样做的地方是:https: //gist.github.com/4246674
尝试1是@Test(dataProvider="getUsersIdAndName")上课.它不起作用,因为事实证明@Test(dataProvider=),类并不意味着应该使用提供的数据调用类的所有方法.结果是根本没有调用该方法,因为没有数据传递给它参数.我得到了奇怪的测试报告,其中此方法被标记为以0秒的执行时间通过.(这是在NetBeans中打开的Maven项目,如果这是有道理的.)
是否@Test(dataProvider=)在类指了什么呢?
Attempt2是@Test在方法的注释上添加dataProvider .它不起作用,因为这意味着在单个类运行期间调用测试方法两次.结果是,它第二次失败,因为它试图重复测试而web驱动程序没有重新初始化:浏览器已经呈现另一个页面.
第一次和第二次尝试的缺点是登录本身是在测试方法中完成而不是在@BeforeClass方法中,因为我知道无法用数据提供者的数据提供它.
尝试3是一个绝望的尝试结合@BeforeClass和@Test单一方法.它不起作用,因为如果带注释的方法有参数列表@BeforeClass也需要它@Parameters.结果是这个方法被调用了三次:由于上述原因,第一次作为类设置失败,而当成功时由于数据提供者而失败两次.
然后我发现TestNG没有提供一种方法来使用不同的数据多次调用所有类方法:http: //comments.gmane.org/gmane.comp.java.testng.user/864
我还有两个关于如何归档相同效果的想法.
Idea4是@Test(dataProvider=)在每个测试方法上放置一个,每个方法将自己执行身份验证和isAuthenticated()测试,然后执行它自己的测试.无效和丑陋.
Idea5看起来是最经济实惠的,@Test它只用一种方法来标记聚合所有其他测试方法:它从数据提供者接收数据,由给定用户执行身份验证,然后运行isAuthenticated测试和所有其他必要的测试.在这种情况下@BeforeClass,@AfterClass只是设置和拆除Web驱动程序.这种方法的缺点是我失去了使用的能力@BeforeMethod,@AfterMethod但这对我来说是负担得起的:看起来我不需要它们.
有没有更好的方法来存档相同的效果?
对不起,留言很长.
提前致谢.
我的页面内有一个ui-view.单击某个按钮时,将加载ui-view并替换为某些HTML.我希望页面向下滚动到页面的刚刚加载的部分.
这可能吗?提前致谢
我将我的项目更新为Struts2版本2.3.20.现在,我的JSP中使用静态方法访问的所有情况都不起作用.
即.
<s:set var="linkEscaped"
value="@org.apache.commons.lang.StringEscapeUtils@escapeHtml(#attr.myObject.link)" />
Run Code Online (Sandbox Code Playgroud)
我已经设置了我的struts.properties - >
struts.ognl.allowStaticMethodAccess=true
Run Code Online (Sandbox Code Playgroud)
并尝试在struts.xml - >
<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
Run Code Online (Sandbox Code Playgroud)
没有成功.有谁知道发生了什么变化,我需要做些什么才能再次启用它们?
我有一个Maven项目,但我对Maven并不熟悉.我想从这个Maven项目创建一个可执行的JAR文件,以便在eclipse的另一个项目中使用它.我感谢任何帮助.
如何使用spring java config设置值为allow-from的X-Frame-Options响应头?
http.headers().disable()
.addHeaderWriter(new XFrameOptionsHeaderWriter(
new WhiteListedAllowFromStrategy(
Arrays.asList("https://example1.com", "https://example2.com"))));
Run Code Online (Sandbox Code Playgroud)
在Http Response标题中,我得到:
X-Frame-Options:"ALLOW-FROM DENY".
为什么我的起源不在标题值中列出?
spring-security http-headers x-frame-options spring-java-config
大家好,我们正在尝试为我们的Web应用程序实现一些功能,我们正在使用Spring Framework v4.1.1和Spring Security v3.1.7进行Web应用程序.我们正在使用自定义身份验证提供程序进行身份验证过程,一切正常,但是当我们尝试使用Spring Security中的JSP标记隐藏页面中特定角色的某些内容时,它不起作用.
这是我们的security-conf.xml
<http pattern="/resources/**" security="none" />
<http use-expressions="true">
<form-login login-page="/login" authentication-failure-url="/loginerroneo"
default-target-url="/seleccionar-empresa" always-use-default-target="true"/>
<logout logout-success-url="/login" logout-url="/salir"/>
<session-management invalid-session-url="/login" />
</http>
<authentication-manager>
<authentication-provider user-service-ref="userDetailsService">
</authentication-provider>
</authentication-manager>
<global-method-security pre-post-annotations="enabled"/>
<beans:bean id="userDetailsService" class="com.grupo.seguridad.acceso.service.impl.UserDetailsServiceAdapater"/>
Run Code Online (Sandbox Code Playgroud)
当我们<sec:authentication property="principal.authorities"/> 在页面中使用此标记时,我们得到了[VENDEDOR,ADMINISTRADOR]这是正确的.
但是当我们尝试使用标记隐藏页面的某些内容时:
<sec:authorize access="hasRole('ADMINISTRADOR')">
<button class="btn btn-small btnGuardar" href="#dlgGuardar" data-toggle="modal">
<i class="icon-hdd"></i> <strong>Una Opcion</strong>
</button>
</sec:authorize>
Run Code Online (Sandbox Code Playgroud)
这是行不通的.
我们不知道我们做错了什么.谢谢你的帮助,最诚挚的问候,
我@RunWith(Parameterized.class)在Test类上使用Annotation运行参数化的jUnit测试.但是现在我还需要运行我的测试类PowerMockRunner,因此使用注释@RunWith(PowerMockRunner.class).显然这是不可能的,因为只@RunWith允许一个注释.
如何在不使用注释的情况下实现参数化测试@RunWith(Parameterized.class)?
https://github.com/hwz/chirp/blob/master/module-5/completed/routes/api.js
function isAuthenticated (req, res, next) {
// if user is authenticated in the session, call the next() to call the next request handler
// Passport adds this method to request object. A middleware is allowed to add properties to
// request and response objects
//allow all get request methods
if(req.method === "GET"){
return next();
}
if (req.isAuthenticated()){
return next();
}
// if the user is not authenticated then redirect him to the login page
return res.redirect('/#login');
};
Run Code Online (Sandbox Code Playgroud)
为什么作者return …
java ×5
eclipse ×1
forms ×1
http-headers ×1
jar ×1
javascript ×1
jsp-tags ×1
junit4 ×1
maven ×1
node.js ×1
ognl ×1
query-string ×1
scroll ×1
selenium ×1
servlets ×1
spring-mvc ×1
struts-1 ×1
struts2 ×1
testng ×1
webdriver ×1