我是struts 2的新手.我在使用list属性填充Select标签时遇到问题.这些值是从动作类提供的.请为此方案提供示例sode.
我的动作课
public class TripDetailsAdd extends ActionSupport {
@Override
public String execute() throws Exception {
return SUCCESS;
}
public String populate() {
VehicleDAO vehicleDAO = new VehicleDAO();
this.lstVehicles.addAll(vehicleDAO.getAllVehicles());
return "populate";
}
private String vehicleId;
private Collection lstVehicles = new ArrayList<VehiclesVO>();
}
Run Code Online (Sandbox Code Playgroud)
Jsp页面内容:
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sform" uri="/struts-dojo-tags"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="com.vms.business.dao.VehicleDAO"%>
<%@page import="java.util.Collection"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Trip Details</title>
</head>
<body>
<s:form action="tripDetailsAdd" …Run Code Online (Sandbox Code Playgroud) 我想在jsp页面中进行以下交互
<s:iterator value="familiari" status="entry">
<div id="familiare'<s:property value="#entry.index" />'" style="margin:1% 1%; float:left; width: 48%;">
<h3><a href="#"><s:property value="nome"/> <s:property value="cognome"/></a></h3>
<div style="padding:5px;">
<label><s:text name="detraz.cf"/></label> <s:property value="codiceFiscale"/>
<label><s:text name="detraz.relParent"/></label> <s:property value="descRelParentale"/>
<br />
<br />
<label><s:text name="detraz.dataNascita"/></label> <s:property value="dataNascita"/><br />
<label><s:text name="detraz.comuneNascita"/></label> <s:property value="comuneNascita"/><br />
<label><s:text name="detraz.provNascita"/></label> (<s:property value="provinciaNascita"/>)<br />
<br />
<label><s:text name="detraz.indResidenza"/></label><br />
<s:property value="indirizzo"/><br />
<s:property value="cap"/> <s:property value="comune"/> (<s:property value="provincia"/>)<br />
<s:property value="stato"/>
<s:url id="ajaxModifyAction" value="detraz_getDettagliFamilare"/>
<button id="modifica-<s:property value="#entry.index" />" style="float:right;"><s:text name="button.modifica"></s:text></button>
</div>
</div>
</s:iterator>
Run Code Online (Sandbox Code Playgroud)
如何使用Struts2 If语句检查familiari List是否为空?
我试图使用struts2在jsp(避免表单提交)中实现ajax.我使用ajax代码通过url将请求传递给struts2动作.但struts2的反应并没有在日本出现.它显示"空"值.我使用AJAX在jsp中调用动作的代码如下.
function ajaxEditFunctionCall(){
var xmlHttp;
var url = "ajaxcall.action?stateName="+frm.stateName.value;
try{
xmlHttp=new XMLHttpRequest();
}catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
alert("Your browser does not support AJAX!");
return false;
}
}
}
alert(1);
xmlHttp.onreadystatechange = showMessage;
alert(2);
xmlHttp.open("GET", URL, true);
alert(3);
xmlHttp.send(null);
}
function showMessage() {
alert("Inside Show Message1");
alert(xmlhttp.readyState);
if(xmlhttp.readyState==4)
{
alert("Inside Show Message2&ReadyState4");
alert(xmlhttp.responseText);
}
}
Included following code in Action Class:
public String ajaxcall() throws Exception{
System.out.println("Inside AjaxCall");
String errorXml = "This is a …Run Code Online (Sandbox Code Playgroud) 我想在这样的时候循环代码
<s:iterator value="#session.count">
<TD WIDTH='10%' BGCOLOR='#000080'> </TD>
</s:iterator>
Run Code Online (Sandbox Code Playgroud)
基于值'count',存储在会话中,我需要多次添加标签,但不按预期循环.
我想知道的是数组或集合对象.但是如何在JSP中使用Struts 2标签循环代码N.
我正在使用Hibernate和Spring 3.0我试图将值保存到数据库中但是当我看到一个控制台时,唯一的选择查询显示插入或更新未显示且保存不起作用
我创建了一个sessionFactory bean并将其注入Impl
<bean id="GetStartedDAOBean" class="com.sample.dao.impl.GetStartedDAOImpl" >
<property name="sessionfactory" ref="sessionFactory">
</property>
</bean
<bean id="GetStartedActionBean" class="com.sample.action.GetStartedAction">
<property name="getStartedDAOImpl" ref="GetStartedDAOBean"></property>
<property name="industryDAOImpl" ref="IndustryDAOBean"></property>
<property name="stateDAOImpl" ref="stateDAOBean"></property>
</bean>
Run Code Online (Sandbox Code Playgroud)
在impl我有
private SessionFactory sessionfactory;
public void setSessionfactory(SessionFactory sessionfactory) {
this.sessionfactory = sessionfactory;
}
public void save(Customer customer)throws IllegalStateException,SystemException{
try {
sessionfactory.openSession().saveOrUpdate(customer);
}
catch(Exception e){
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
当我调试sessionFactory中有值但它不保存任何值.并且也不显示任何插入的查询.没有错误.
任何人都可以帮助我吗?
在我的应用程序中,我必须根据配置页面中选择的语言环境用户显示内容.我没有使用浏览器默认语言环境.
使用时s:text,它始终使用默认资源文件.
在Struts1中,我使用下面的代码在我的过滤器中设置默认语言环境
session.setAttribute("org.apache.struts.action.LOCALE",locale);
Run Code Online (Sandbox Code Playgroud)
如何在Struts2中动态设置用户选择的语言环境?
Spring MVC主要使用注释来配置其控制器,据我所知,在Spring中配置Controller而没有Annotions(只有XML)的唯一方法是扩展AbstracController(或类似的Controller类),目前所有这些类都不推荐用于Spring 3.
虽然我认为放弃对这个类的支持是一个好主意,主要是因为扩展这个类会创建几乎不依赖Spring作为依赖关系的控制器,我不明白为什么Spring不提供类似Struts Actions的配置(Actions in Struts 2不扩展任何奇怪的类,因此它们不具有Struts的任何依赖性
为什么Spring MVC不能通过XML提供像Struts 2 Actions这样干净的POJO风格配置?
为什么要使用丑陋的注释放弃对MVC上的XML配置的支持?为什么不把它放在所有Spring Proyects中呢?
我有一个包含以下字段的搜索表单
price, status, owner
Run Code Online (Sandbox Code Playgroud)
当用户填写所有字段时,请求将被发送到后端以显示具有指定价格,状态和所有者的产品的类别列表.用户可以单击每个类别以查看其产品列表.
为了实现它,我有以下方法来检索类别,并将搜索字段(价格,状态,所有者)放入会话中以在搜索的下一页中可用(当选择类别时).
参数的值可能太长了,我更喜欢将它们作为GET来轻松地为结果添加书签.
public String retrieveCategories(){
//... here I retrieve categories which their products are matched
//with the search fields
Map session = ActionContext.getContext().getSession();
session.put("Items", this.items);
return "SUCCESS";
}
Run Code Online (Sandbox Code Playgroud)
显示所有类别后,用户可以单击每个类别以查看其产品.类别的名称将发送到后端,因此我将从会话中检索值以搜索具有所选类别的相同规格的产品.
public String retrieveProductsOfSelectedCategory(){
Map session = ActionContext.getContext().getSession();
this.items = (Items) session.get("Items");
//... here I retrieve products of the selected category based on values retrieved
// from session
}
Run Code Online (Sandbox Code Playgroud)
我想知道如果不是你的建议,实施它是否是一个好习惯?
当我添加struts标签时,格式化消失.我该怎么办?
这是我的代码:
<div class="panel-body" style="background-color:;">
<div align="center">
<font size=3> <s:form id="FormAddUser" name="FormAddUser"
action="AddUser" method="post" class="form-horizontal">
<div class="row" align="center">
<div class="col-sm-6">
<div class="col-sm-4" align="right">
<label>User ID</label>
</div>
<s:textfield name="UserId" class="form-control"></s:textfield>
</div>
</div>
<br>
<div class="row" align="center">
<div class="col-sm-6">
<div class="col-sm-4" align="right">
<label>Name</label>
</div>
<s:textfield name="Name" class="form-control"></s:textfield>
</div>
</div>
<br>
<div class="row" align="center">
<div class="col-sm-6">
<div class="col-sm-4" align="right">
<label>Address</label>
</div>
<s:textarea name="Address" class="form-control"></s:textarea>
</div>
</div>
<br>
<div class="row" align="center">
<div class="col-sm-6">
<div class="col-sm-4" align="right">
<label>Birth date</label>
</div>
<s:textfield name="DOB" class="form-control" placeholder="dd/mm/yy"></s:textfield>
</div> …Run Code Online (Sandbox Code Playgroud) 我有一个弹出窗口,其中有两个onclick方法,如"Submit"和"Discard".
当我单击提交两次时,它会插入两条记录,这意味着重复记录.
我怎么能避免这个?
java ajax struts2 double-submit-prevention double-submit-problem