我想设置Accept:我使用Spring的请求中的值RestTemplate.
这是我的Spring请求处理代码
@RequestMapping(
value= "/uom_matrix_save_or_edit",
method = RequestMethod.POST,
produces="application/json"
)
public @ResponseBody ModelMap uomMatrixSaveOrEdit(
ModelMap model,
@RequestParam("parentId") String parentId
){
model.addAttribute("attributeValues",parentId);
return model;
}
Run Code Online (Sandbox Code Playgroud)
这是我的Java REST客户端:
public void post(){
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.add("parentId", "parentId");
String result = rest.postForObject( url, params, String.class) ;
System.out.println(result);
}
Run Code Online (Sandbox Code Playgroud)
这适合我; 我从服务器端获得了一个JSON字符串.
我的问题是:当我使用RestTemplate时,如何指定Accept:标题(例如application/json,application/xml...)和请求方法(例如,...)?GETPOST
我试图用于hibernate annotations将数据插入到MySQL database没有定义主键的表中.
但事实上,该表的2个字段在表中是唯一的.我可以使用hibernate注释实现相同吗?
这是我的代码..
@Entity
@Table(name = "RolesMenuItems")
public class RolesMenuItems {
@Column(name = "RoleID")
private String roleID;
@Column(name = "MenuItemID")
private String menuItemID;
/*setter getter methods */
}
Run Code Online (Sandbox Code Playgroud) 我有以下表格:
<form id="testForm" action="country_Save">
Country Name:<input type="text" id="countryName" />
<input type="submit" id='saveCountry' value="Add Country" />
</form>
Run Code Online (Sandbox Code Playgroud)
并遵循JQuery验证文本字段
$('#testForm')
.jqxValidator({ rules : [
{
input : '#countryName',
message : 'Country Name is required!',
action : 'keyup, blur',
rule : 'required'
}],
theme : theme
});
Run Code Online (Sandbox Code Playgroud)
我在提交表单时如何使用此验证?
我有这个代码片段,我将数据传递给另一个jsp文件.
使用Javascript
$(document).ready(function() {
$("#click").click(function() {
name = $("#name").val();
age = $("#age").val();
$.ajax({
type : "POST",
url : "pageTwo.jsp",
data : "name=" + name + "&age=" + age,
success : function(data) {
$("#response").html(data);
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
HTML
<body>
Name:<input type="text" id="name" name="name">
<br /><br />
Age :<input type="text" id="age" name="age">
<br /><br />
<button id="click">Click Me</button>
<div id="response"></div>
</body>
Run Code Online (Sandbox Code Playgroud)
在pageTwo.jsp中,我的代码是
<%
String name = request.getParameter("name");
String age = request.getParameter("age");
out.println(name + age);
%>
Run Code Online (Sandbox Code Playgroud)
但这不行.我的Jquery有什么错误吗?.任何人都可以帮帮我吗?
我有内部联接的以下MySQL更新查询:
UPDATE Country AS c
INNER JOIN State s ON c.CountryID = s.CountryID
INNER JOIN City cy On s.StateID = cy.StateID
SET c.Active='Y', s.Active='Y',cy.Active='Y'
WHERE c.CountryID='12'
Run Code Online (Sandbox Code Playgroud)
这是我的国家地图类
enter code here
@Entity
@Table(name = "Country")
public class Country {
public Country() {
}
@Id
@Column(name = "CountryID")
private String countryID;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "country")
private Set<State> state = new HashSet<State>(0);
@Column(name = "CountryName")
private String countryName;
}
Run Code Online (Sandbox Code Playgroud)
国家的Mpping课程
@Entity
@Table(name = "State")
public class State {
public State() { …Run Code Online (Sandbox Code Playgroud) 大家好我有一些jsp页面,我使用struts2来处理我的表单.在用户提交表单后,地址栏中显示的URL将变为somthing.action,因此当用户刷新页面时,表单将再次提交.我怎么处理这个?提交表格后.
我有登录参数
1.userName
2.password
3.companyId
Run Code Online (Sandbox Code Playgroud)
我使用以下代码获得了用户名和密码
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String name = auth.getName();
String pwd = auth.getCredentials();
String companyId= ???//How can i set and then get company Id here.
Run Code Online (Sandbox Code Playgroud)
我的问题是如何使用SecurityContextHolder获得额外的登录参数(companyId)?
提取类可能不是spring控制器.这就是我使用SecurityContextHolder而不是HttpSession的原因.
谢谢,
你如何集成或创建一个REST Web应用程序??.我看到这个插件struts-restplugin但是文档没有提供任何正在运行的example.can任何一个请提供一些示例或参考教程相同.
我已经将这个Struts2-maven项目导入了我的Eclipse.
这是我pom.xml的Struts2
<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>manning</groupId>
<artifactId>Form_Tags_Struts2_Mvn</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Form_Tags_Struts2_Mvn</name>
<build>
<finalName>Form_Tags_Struts2_Mvn</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.7.0_05</version>
<scope>system</scope>
<systemPath>/usr/lib/jvm/jdk1.7.0_05/lib/tools.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.1.2</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试运行它时会显示异常.这是我的例外:
SEVERE:在org.apache.catalina上的org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)中启动过滤器struts2 java.lang.ClassNotFoundException:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter的异常位于org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)的.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514 )org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:133)org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:256)org.apache.catalina.core.ApplicationFilterConfig. setFilterDef(ApplicationFilterConfig.java:382)位于org.apache的org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:103)org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650). CA talina.core.StandardContext.startInternal(StandardContext.java:5306)org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)at org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase. java:1559)atg.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1549)at java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:334)at java.util.concurrent .futureTask.run(FutureTask.java:166)位于java的java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603). lang.Thread.run(Thread.java:722)
谁能帮帮我吗?实际发生了什么?
如何在Struts 2中实现客户端显示的分页和Hibernate作为持久层.
这是我到目前为止所做的代码:
<display:table id="students" name="students" pagesize="2"
export="false" requestURI="/student">
<display:column property="studentRoll" title="Roll"
paramId="studentRoll" sortable="true" />
<display:column property="studentName" title="Name" sortable="true" />
<display:column property="studentCourse" title="Course"
sortable="true" />
<display:setProperty name="paging.banner.placement" value="bottom" />
</display:table>
Run Code Online (Sandbox Code Playgroud)
有没有办法在没有display标签的情况下实现这个?
struts2 ×4
hibernate ×2
java ×2
jquery ×2
jsp ×2
rest ×2
spring ×2
eclipse ×1
html ×1
html5 ×1
inner-join ×1
jax-rs ×1
jquery-ui ×1
jqxwidgets ×1
maven ×1
maven-2 ×1
maven-3 ×1
queryover ×1
resttemplate ×1
spring-mvc ×1
validation ×1