struts2 + jsonInsert title here function getAjaxObject(){ va

1土xx参2022-10-04 11:39:541条回答

struts2 + json
Insert title here

function getAjaxObject(){
var xmlhttp=null;
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}

function tt(){
var userid=document.getElementById("userid").value;
var password=document.getElementById("password").value;
var url="./test?userid="+userid+"&password="+password;
var xmlhttp=getAjaxObject();
xmlhttp.open("GET",url,true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.send(null);
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
document.write(xmlhttp.responseText)
}
};
}





==
public String execute(){
String str="{"userid":""+userid+"","password":""+password+""}";
result=str;
return SUCCESS;
}

怎么得到的结果是:"{"userid":"123456","password":"123456"}"
会是带引号和转义字符的?

已提交,审核后显示!提交回复

共1条回复
十rr叉 共回答了18个问题 | 采纳率94.4%
简单一点的方法就是不通过struts的返回类型,直接用response写就可以,代码如下: HttpServletResponse response=ServletActionContext.getResponse(); response.setContentType("text/html;charset=utf-8"); ...
1年前

相关推荐

关于struts2通配符问题 /WEB-INF/content/{1}.jsp这里的* 和 {1}是咋样用法?,回答的好
关于struts2通配符问题

/WEB-INF/content/{1}.jsp

这里的* 和 {1}是咋样用法?,回答的好会追加分的哦
yuri_g1年前1
258p4 共回答了21个问题 | 采纳率95.2%
,表示可以匹配任意的action,即所有主请求都可以通过这个aciotn来处理
{1}:这里使用的通配符,{1}是匹配第一个*
举个例子更明确:
/WEB-INF/content/{3}.jsp
一个请求,http://zhidao.baidu.com/question/Baidu_add_success.action
可通过这个 action处理,class="com.Baidu" method="add"
/WEB-INF/content/successjsp
Struts2上传图片问题我把图片上传到本地项目子目录文件夹下面,在eclipse中 每次要刷新文件夹才可以出来,现在把
Struts2上传图片问题
我把图片上传到本地项目子目录文件夹下面,在eclipse中 每次要刷新文件夹才可以出来,现在把项目放到服务器上面,每次上传后,只是把文件路径保存到了数据库,而项目目录下面的文件夹,并没有上传的图片,该怎么办,
public class UploadFile {
private static final int BUFFER_SIZE = 16 * 1024;
String imageFileName;
public static InputStream in;
public static OutputStream out;
private String fileName;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public static int getBufferSize() {
return BUFFER_SIZE;
}
private static void copy(File src, File dst) {
try {
try {
in = new BufferedInputStream(new FileInputStream(src),
BUFFER_SIZE);
out = new BufferedOutputStream(new FileOutputStream(dst),
BUFFER_SIZE);
byte[] buffer = new byte[BUFFER_SIZE];
while (in.read(buffer) > 0) {
out.write(buffer);
}
} finally {
if (null != in) {
in.close();
}
if (null != out) {
out.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static String getExtention(String fileName) {
int pos = fileName.lastIndexOf(".");
return fileName.substring(pos);
}
public String saveImage(File myFile) {
imageFileName = new Date().getTime() + getExtention(fileName);
// File imageFile = new
// File(ServletActionContext.getServletContext().getRealPath("/uploadImage")
// + "/" + imageFileName);
File imageFile = new File("D:/java/workspaces/mjms/WebRoot/image" + "/"
+ imageFileName);
copy(myFile, imageFile);
return imageFileName;
}
}
雪落无痕11161年前1
ddeea 共回答了15个问题 | 采纳率93.3%
File imageFile = new File("D:/java/workspaces/mjms/WebRoot/image" + "/"
+ imageFileName);
服务器上没有这个文件,应该是这里的路径,这是你本机的路径,在服务器上有这个目录?建议写相对路径.
还有个问题,就是你说的每次要刷新的问题,
问题在这里:
if (null != out) {
out.frush();//加上这一句代码,就不用手动刷新了
out.close();
}
struts2 if怎么根据iterator的下标进行判断
struts2 if怎么根据iterator的下标进行判断
如:

下标小鱼等于2



下标》2



其中test里面条件怎么写
jyhhh1年前1
萍儿4 共回答了13个问题 | 采纳率92.3%
#status.count 在struts2迭代标签里代表当前行数


下标小鱼等于2


下标》2
Struts2 +Spring 3.0+hibernate 3.3 注解异常.expected at least 1 b
Struts2 +Spring 3.0+hibernate 3.3 注解异常.expected at least 1 bean which qualifies as autowir
我用注解来实现的SSH,用@Entity 来标示实体bean,用 来让Spring 来注入,可以在service里面用@Autowiredx05
x05@Qualifier("taUser")
x05TaUser taUser;
来使用这个实体bean的时候就报下面这个错,说找不到,貌似Spring没注入耶.再次万谢各位帮忙解决下(据说是 3.0和3.3 jar 冲突,但是我不知道那个有冲突啊).
Unable to instantiate Action,com.ta.action.UserCreateAction,defined for 'user-create' in namespace '/'Error creating bean with name 'com.ta.action.UserCreateAction':Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:Could not autowire field:com.ta.service.UserServices com.ta.action.UserCreateAction.userServices; nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'userServicesImpl':Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:Could not autowire field:com.ta.entity.model.TaUser com.ta.service.impl.UserServicesImpl.taUser; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:No matching bean of type [com.ta.entity.model.TaUser] found for dependency:expected at least 1 bean which qualifies as autowire candidate for this dependency.Dependency annotations:{@org.springframework.beans.factory.annotation.Autowired(required=true),@org.springframework.beans.factory.annotation.Qualifier(value=taUser)}
x05com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:318)
x05com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)
cmj55551年前0
共回答了个问题 | 采纳率
struts2 零配置返回type=json出错
struts2 零配置返回type=json出错
@Action(value = "/image",results ={@Result(name="success",type="json",params = {"root","result" })})
tomcat启动解析@Action、、、时,type类型出错
错误:
The Result type [json] which is defined in the Result annotation on the class [class action.UploadAction] or determined by the file extension or is the default result type for the PackageConfig of the action,could not be found as a result-type defined for the Struts/XWork package [action#convention-default#] - [unknown location]
知道的就说吧
yunenglin1年前1
Jacquelinemao 共回答了21个问题 | 采纳率81%
您好,请问您是否扩展了 json-default 命名空间
Struts2配置Struts.xml的时候,“尽量避免使用带*号的配置,保证可读性”,通常是这样?
shui1111111年前1
freya_fb 共回答了20个问题 | 采纳率95%
通配符的使用,一般是建议谨慎用,即使使用,也要把它放在配置文件的后面,以免影响前面类似的配置文件。
Struts2的标签在什么情况下取值为空(null)?
心情不好5551年前2
聪明糊涂的心 共回答了15个问题 | 采纳率93.3%
当取不到值的时候,例如错误的取值方式 或者延迟加载时取不到值
struts2 的action获取aaa值出现警告:Parameter [aaa] is not on the excl
struts2 的action获取aaa值出现警告:Parameter [aaa] is not on the excludeParams list of patterns and will be appended to action!
jsp页面有个 ,action里面的私有变量和setget方法都写了没有问题.
在action方法中可以得到aaa的取值,但是旧是报了这个警告,这是为什么.测试了一下action不适用该值也是会报.
443355441年前1
偷心WZ 共回答了23个问题 | 采纳率95.7%
这个是struts2的BUG最新版已经修正了 只在DEBUG模式会有 不会有影响的