我正在使用Struts2,当我访问值堆栈变量时,我不知道是否使用%或#或$.我尝试了所有这些,直到找到正确的.
任何人都能解释一下这些有什么区别吗?
有谁知道Struts2和Spring 3 MVC之间的区别.我知道Struts 1和Spring 2.5之间的区别,但Struts2在Spring 3或其他方面的优势是什么.
我试过在网上寻找,但在任何地方都没有全面的答案.
我有一个基于struts的webapp,我希望默认的"欢迎"页面是一个动作.我发现的唯一解决方案似乎是使欢迎页面成为包含重定向到操作的JSP的变体.例如,在web.xml:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)
并在index.jsp:
<%
response.sendRedirect("/myproject/MyAction.action");
%>
Run Code Online (Sandbox Code Playgroud)
当然有更好的方法!
在我开始之前,我要说的是我找到的最接近的答案就在这里,但说实话,我并不真正理解那里发生了什么.
我正在使用Struts2 + Spring Security 2.06与自定义身份验证提供程序和访问决策管理器来消除对"ROLE_"前缀的需求.
我的applicationContext-security.xml看起来像这样:
<beans:bean id="customAuthenticationProvider"
class="com.test.testconsole.security.CustomAuthenticationProvider">
<beans:property name="userManagementService" ref="userManagementService"/>
<custom-authentication-provider/>
</beans:bean>
<!--Customize Spring Security's access decision manager to remove need for "ROLE_" prefix-->
<beans:bean
id="accessDecisionManager"
class="org.springframework.security.vote.AffirmativeBased">
<beans:property name="decisionVoters">
<beans:list>
<beans:ref bean="roleVoter"/>
<beans:ref bean="authenticatedVoter"/>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean
id="roleVoter"
class="org.springframework.security.vote.RoleVoter">
<beans:property name="rolePrefix" value=""/>
</beans:bean>
<beans:bean
id="authenticatedVoter"
class="org.springframework.security.vote.AuthenticatedVoter">
</beans:bean>
<global-method-security secured-annotations="enabled" access-decision-manager-ref="accessDecisionManager"/>
Run Code Online (Sandbox Code Playgroud)
我的web.xml的相关部分:
<!--Spring Security-->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<!--Has to be placed _Before_ the struts2 filter-mapping-->
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern> …Run Code Online (Sandbox Code Playgroud) 我使用struts2-archtype-starter在eclipse中创建了一个新的struts项目.
在做任何事情之前我的项目中已经出现了一些错误.解决了他们中的大多数,但有1仍然给我一些问题.
Missing artifact com.sun:tools:jar:1.5.0:system pom.xml
我试图手动将tools.jar添加到我的存储库,但这并没有解决问题.
我的pom看起来像这样
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.divespot</groupId>
<artifactId>website</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>E-Divespot diving community</name>
<url>http://www.e-divespot.com</url>
<description>A website to support divers from all around the world.</description>
<dependencies>
<!-- Junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<!-- Struts 2 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.0.11.2</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-sitemesh-plugin</artifactId>
<version>2.0.11.2</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.0.11.2</version>
</dependency>
<!-- Servlet & Jsp -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version> …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的Struts2应用程序重定向到生成的URL.在这种情况下,我希望URL使用当前日期或我在数据库中查找的日期.因此/section/document变得/section/document/2008-10-06
最好的方法是什么?
我在我的网络应用程序中收到"未找到线程绑定请求"错误,并希望得到一些帮助.我正在尝试使用struts2 + spring + hibernate,并使用spring来管理hibernate会话工厂,并将hibernate会话注入我的struts操作.我希望这是有道理的.当应用程序启动时,没有错误,但是当我发出第一个Web请求时,它会弹出"未找到线程绑定请求"错误.这是我的春季配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="hibernateSessionFactory" scope="singleton"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<bean id="hibernateSession" factory-bean="hibernateSessionFactory"
factory-method="openSession" destroy-method="close" scope="request" class="org.hibernate.Session" />
</beans>
Run Code Online (Sandbox Code Playgroud)
这是我的行动:
package actions.events;
import org.hibernate.Session;
public class Listing {
Session session;
public void setHibernateSession(Session value) throws Exception
{
session = value;
}
public String execute() {
return "success";
}
}
Run Code Online (Sandbox Code Playgroud)
我唯一的领先是,如果我删除上面的'setHibernateSession'函数,我不会得到错误,因为如果动作不需要一个(懒惰的实例化),大概春天不打扰创建会话.
这是例外:
Unable to instantiate Action, actions.events.Listing, defined for 'Listing' in namespace '/events'Error creating bean with …Run Code Online (Sandbox Code Playgroud) 我是一名java开发人员,没有经验丰富,但我对大多数概念都很熟悉.
我最近使用Tomcat/JSP(~30个动态页面)构建了一个网站.我犯了新的错误,在JSP中包含大部分核心逻辑,使用合理化,它只是"一个简单的项目".
我学到了很多困难.因此,我现在使用servlet在谷歌应用引擎中重新构建应用程序,并计划使用Velocity使用模型 - 视图 - 控制器设计模式实现它.
我也在看Struts,但之前没有使用过这个框架.
有人能说服我为什么要将struts纳入这个项目吗?对于一两个人的中型项目,真的会给我买很多东西吗?
在有额外学习曲线的情况下,有一个明显的成本,它的好处是否会超过成本?或者Velocity的使用是否足以隔离逻辑?意见?
想澄清一些困惑.我有applicationContext.xml.
问题1: 1和2之间的区别是什么?它们是否与不同的方法相同?
问题2:
我在Spring论坛上询问了一些问题.他提到的有关汇集的内容如下
如果您需要/想要使用内部连接池来进行hibernate,我会建议它,并简单地配置一个支持连接池的数据源并将其注入到sessionfactory中.
hibernate的内部连接池=这是下面的数字2.对?
只需配置一个支持连接池的数据源并将其注入sessionfactorybean =这是下面的数字1.对?
1# -
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="maxActive" value="100"/>
<property name="maxIdle" value="30"/>
<property name="maxWait" value="16000"/>
<property name="minIdle" value="0"/>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedClasses">
<list>
<value>com.mkyong.customer.model.Customer</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.generate_statistics">true</prop>
</props>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
2# -
池和连接信息位于hibernate.cfg.xml中
<bean …Run Code Online (Sandbox Code Playgroud) 我在应用程序中执行某些操作时得到了
java.lang.IllegalStateException无法调用sendError()
当我再次重新加载页面时,它会正常工作一段时间,但经过一段时间再次显示相同的异常.我怎样才能克服这个例外?
以下是例外情况:
HTTP Status 500 - Cannot call sendError() after the response has been committed
type Exception report
message Cannot call sendError() after the response has been committed
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:451)
org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:725)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.40 logs.
Run Code Online (Sandbox Code Playgroud)
在struts.xml
<struts>
<package name="default" extends="hibernate-default"> …Run Code Online (Sandbox Code Playgroud)