我有一个使用Spring Security 3.0.x的应用程序.我有一个习惯AuthenticationProvider:
public class AppAuthenticationProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
...
if (!check1()) throw new UsernameNotFoundException();
if (!check2()) throw new DisabledException();
...
}
Run Code Online (Sandbox Code Playgroud)
我想在每个异常上发送cutom响应代码,例如404为UsernameNotFoundException,403为DisabledException等.现在我只在我的spring安全配置中有authentication-failure-url所以我在每个异常中重定向到authenticate ().
我需要使用特定格式在数字单元格中写入Double值,我的意思是,生成的xls必须包含包含Double值的数字单元格,例如:8,1.我正在尝试这样的事情:
DecimalFormat dFormat = new DecimalFormat("##.#");
dFormat.format(doubleValue);
Run Code Online (Sandbox Code Playgroud)
但是,由于format方法返回一个String,无论我是否将单元格创建为数字,它们总是表现为文本单元格.我在想两个选择:
任何的想法?
一个例子应该有希望证明这个问题.我有10个文档显示在页面上,其中3个包含在zip包中的附加信息.在初始页面加载期间,我只知道哪些文档有这些附加信息,我不知道这些zip文件的URL.然后,我在包含其他zip文件的3个文档中显示一个链接("获取Zip包").当用户点击"获取Zip包"时,它会调用支持bean中的一个方法,该方法会进入数据库以找出zip包的URL.完成后,我想将zip包提供给浏览器,然后弹出"另存为..."对话框,用户可以保存zip包.
我尝试了两种方法,但它们都不起作用.
方法1
<p:commandLink actionListener="#{myBackingBean.zipPackage(aDocument)}"
value="Get Zip Package"
ajax="false"
rendered="#{aDocument.packageAvailable}"/>
Run Code Online (Sandbox Code Playgroud)
public String zipPackage(DocItem item){
//logic here to figure out the URL for this item's zip package
return packageLink;
}
Run Code Online (Sandbox Code Playgroud)
方法2
<h:outputLink onclick="getPackageLink([{name:'product', value: '#{aResult.product}'}, {name:'version',value:'#{aResult.version}'}])"
<h:outputText value="Get Documentation Package"/>
</h:outputLink>
<p:remoteCommand name="getPackageLink" actionListener="#{kbBackingBean.zipPackage()}"/>
Run Code Online (Sandbox Code Playgroud)
public String zipPackage() {
Map map = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
String product = (String) map.get("product");
String version = (String) map.get("version");
//logic here to figure out the URL for this item's zip package
return packageLink;
}
Run Code Online (Sandbox Code Playgroud)
当页面加载并显示10个文档时,"获取Zip包"链接(对于3个文档)指向任何内容,基本上与页面具有相同的URL.当我点击它时,它会向服务器发送一个GET请求并调用支持bean函数.使用方法1,浏览器似乎在开始呈现响应之前等待辅助bean方法完成.使用方法2,没有等待,浏览器立即重新加载页面.我怀疑由于'Get Zip …
我想使用primefaces fileUpload上传doc或docx文件,虽然我指定它显示的 文件类型无效的文件类型

<p:fileUpload cancelLabel="#{contenu.annuler}"
fileUploadListener="#{utilAdminBean.fileUpload}"
allowTypes="/(\.|\/)(doc|docx)$/"
multiple="false" mode="advanced" sizeLimit="52428800"
showButtons="false" />
Run Code Online (Sandbox Code Playgroud) 我有一个pom.xml文件,其中包含以下内容:
<sourceDirectory>${basedir}/src/main/test</sourceDirectory>
<outputDirectory>${basedir}/src/main/bin </outputDirectory>
Run Code Online (Sandbox Code Playgroud)
在里面${basedir}/src/main/test我有一些不包含任何.java文件的文件夹.当我开始编译时,它们不会被复制到${basedir}/src/main/bin目录.
仅移动.java文件(在编译之后)并存储在右侧文件夹中.
有人帮我解决这个问题而不使用任何插件吗?
我试过了
<resources>
<resource>
<filtering>false</filtering>
<directory>${basedir}/src/main/test/scenarios</directory>
<includes>
<include>*.xml</include>
</includes>
<targetPath>${basedir}/src/main/bin/scenarios</targetPath>
</resource>
<resource>
<filtering>false</filtering>
<directory>${basedir}/src/main/test/sut</directory>
<includes>
<include>*.xml</include>
</includes>
<targetPath>${basedir}/src/main/bin/sut</targetPath>
</resource>
</resources>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.怎么了?
我在Spring框架中登出时遇到了问题.
首先,当我希望j_spring_security_logout为我处理它时,我得到404找不到j_spring_security_logout:sample-security.xml:
<http>
<intercept-url pattern="/messageList.htm*" access="ROLE_USER,ROLE_GUEST" />
<intercept-url pattern="/messagePost.htm*" access="ROLE_USER" />
<intercept-url pattern="/messageDelete.htm*" access="ROLE_ADMIN" />
<form-login login-page="/login.jsp" default-target-url="/messageList.htm"
authentication-failure-url="/login.jsp?error=true" />
<logout/>
</http>
Run Code Online (Sandbox Code Playgroud)
示例url链接到JSP页面中的注销:
<a href="<c:url value="/j_spring_security_logout" />">Logout</a>
Run Code Online (Sandbox Code Playgroud)
当我尝试使用自定义JSP页面,即我使用登录表单为此目的,然后我得到更好的结果,至少它到达登录页面,但另一个问题是,你不能被注销,因为你可以直接键入url应该保持警惕,无论如何都要过去.
从以前的列表略有修改:
<http>
<intercept-url pattern="/messageList.htm*" access="ROLE_USER,ROLE_GUEST" />
<intercept-url pattern="/messagePost.htm*" access="ROLE_USER" />
<intercept-url pattern="/messageDelete.htm*" access="ROLE_ADMIN" />
<form-login login-page="/login.jsp" default-target-url="/messageList.htm"
authentication-failure-url="/login.jsp?error=true" />
<logout logout-success-url="/login.jsp" />
</http>
Run Code Online (Sandbox Code Playgroud)
<a href="<c:url value="/login.jsp" />">Logout</a>
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
我从头开始做一个Web应用程序.在我一直在处理已经运行了很长时间的应用程序之前,所以我没有必要处理完整的设置阶段.我使用的是Spring 3和Tomcat 6,我正在使用Eclipse 3.6
我提供图像(或其他与控制器响应不同的东西)存在很大问题.事实上,我无法找到一种方法将我的图像放在我的jsps中.我的配置,适用于:
<servlet-mapping>
<servlet-name>springDispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
在web.xml和
<bean name="/accise" class="it.jsoftware.jacciseweb.controllers.MainController">
</bean>
Run Code Online (Sandbox Code Playgroud)
对于servlet上下文(当然还有其他).
我在这里阅读了很多消息,其他论坛也在谈论这个:
<mvc:resources mapping="/resources/**" location="/resources/" />
Run Code Online (Sandbox Code Playgroud)
但如果我在我的servlet-context.xml中插入它,我将能够提供图像,但控制器"accise"将无法访问.我误用了还是误解了资源标签?什么是正确的方法?
更新解决方案!!! :)
问题是我的servlet-config.xml错过了一个声明:
现在它是(使用控制器上的注释):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="it.jsoftware.jacciseweb.controllers"></context:component-scan>
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<mvc:resources mapping="/resources/**" location="/resources/" />
Run Code Online (Sandbox Code Playgroud)
我在尝试在Liferay 6.0 portlet中设置会话cookie时遇到问题.我希望能够将cookie设置到客户端浏览器以存储用于linkedin身份验证的应用程序密钥,然后可以由其他portlet检索它.
我可以通过以下方式阅读cookie:
public void addLinkedInCV(ActionRequest request, ActionResponse response)
throws PortalException, SystemException {
HttpServletRequest convertReq = PortalUtil.getHttpServletRequest(request);
Cookie[] cookies = convertReq.getCookies();
...
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试阅读一个失败的尝试.
@Override
public void doView(RenderRequest renderRequest,RenderResponse renderResponse) throws IOException, PortletException {
HttpServletResponse convertRes = PortalUtil.getHttpServletResponse(renderResponse);
HttpServletResponse originalRes = (HttpServletResponse) ((HttpServletResponseWrapper) convertRes).getResponse();
Cookie linkedInCookie = new Cookie("linkedIn", util.getAppKey());
originalRes.addCookie(linkedInCookie);
}
Run Code Online (Sandbox Code Playgroud) Primefaces 3.5,Mojarra 2.1.14.这是我的PF数据表,它包含一个名为'automatic'的不可编辑的布尔列,以及可编辑的'label'列:
<p:dataTable value="#{bean.contents}" paginator="true" var="row"
editable="true" editMode="cell" rows="25" rowsPerPageTemplate="10,25,50" id="list">
<p:column>
<f:facet name="header"><h:outputText value="header1" /></f:facet>
<p:selectBooleanCheckbox value="#{row.automatic}" disabled="true" id="isAutomatic"></p:selectBooleanCheckbox>
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="header2" /></f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{row.label}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{row.label}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:ajax event="cellEdit" process="@this" listener="#{myBean.onEditLabel}" update="isAutomatic"/>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)
单元格编辑事件监听器:
public void onEditLabel(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
if(newValue != null && !newValue.equals(oldValue)) {
DataTable s = (DataTable) event.getSource();
MyEntity d = (MyEntity) s.getRowData();
try {
d.setAutomatic(false);
myDAO.save(d); …Run Code Online (Sandbox Code Playgroud) 我正在使用弹簧安全
我有表格登录
<http auto-config="true">
<intercept-url pattern="/pages/**" access="ROLE_USER" />
<form-login authentication-success-handler-ref="authenticationSuccessHandler" login-page="/login.html" default-target-url="/pages/index.html"
always-use-default-target="true" authentication-failure-url="/login.html" />
<logout logout-success-url="/login.html" invalidate-session="true" />
<anonymous enabled='false'/>
</http>
Run Code Online (Sandbox Code Playgroud)
在这里我可以设置一个authentication-success-handler-ref,如何在我的基本身份验证中添加一个:
<http pattern="/REST/**" realm="REALM" entry-point-ref="authenticationEntryPoint">
<intercept-url pattern="/**" access="ROLE_USER" />
<http-basic />
<logout logout-url="/REST/logout" success-handler-ref="restLogoutSuccessHandler" />
</http>
Run Code Online (Sandbox Code Playgroud)
我认为abour会覆盖BasicAuthenticationFilter,但我怎么能注入我的cutom类 <http-basic />
java ×4
primefaces ×3
jsf ×2
apache-poi ×1
excel ×1
facelets ×1
file-upload ×1
jsp ×1
liferay ×1
maven ×1
maven-2 ×1
portlet ×1
spring ×1
spring-mvc ×1
tomcat ×1