jsp页面:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
var xmlHttp; //XMLHttpRequest对象
function createXMLHttpRequest(){
if(window.ActiveXObject){ //IE浏览器
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
window.alert("创建XMLHttpRequest对象错误"+e);
}
}
}else if(window.XMLHttpRequest){
window.alert("创建XMLHttpRequest对象成功");
}
if(!(xmlHttp)){
window.alert("创建对象失败");
}
}
function onStrat(){
createXMLHttpRequest();
var url="http://127.0.0.1:8080/strust2/user/user";
xmlHttp.open("get",url,true);
xmlHttp.onreadystatechange = userinfo;
xmlHttp.send();
window.alert(xmlHttp.readyState);
var html = xmlHttp.responseText;
if(html.indexOf("Hello Struts2")>0){
window.alert("success");
}
}
function userinfo(){
if(xmlHttp.readState==4){
alert("success");
}
}
</script>
</head>
<body>
<input type="submit" value="submit" onclick="onStrat();"/>
<br>
</body>
</html>
问题:
为什么url = "http://127.0.0.1:8080/strust2/Hello.jsp"就可以,但用"http://127.0.0.1:8080/strust2/user/user"就不可以呢?我在struts.xml里配置就不行吗?必须是jsp页面?
望各位大大解决下,谢谢
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
var xmlHttp; //XMLHttpRequest对象
function createXMLHttpRequest(){
if(window.ActiveXObject){ //IE浏览器
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
window.alert("创建XMLHttpRequest对象错误"+e);
}
}
}else if(window.XMLHttpRequest){
window.alert("创建XMLHttpRequest对象成功");
}
if(!(xmlHttp)){
window.alert("创建对象失败");
}
}
function onStrat(){
createXMLHttpRequest();
var url="http://127.0.0.1:8080/strust2/user/user";
xmlHttp.open("get",url,true);
xmlHttp.onreadystatechange = userinfo;
xmlHttp.send();
window.alert(xmlHttp.readyState);
var html = xmlHttp.responseText;
if(html.indexOf("Hello Struts2")>0){
window.alert("success");
}
}
function userinfo(){
if(xmlHttp.readState==4){
alert("success");
}
}
</script>
</head>
<body>
<input type="submit" value="submit" onclick="onStrat();"/>
<br>
</body>
</html>
问题:
为什么url = "http://127.0.0.1:8080/strust2/Hello.jsp"就可以,但用"http://127.0.0.1:8080/strust2/user/user"就不可以呢?我在struts.xml里配置就不行吗?必须是jsp页面?
望各位大大解决下,谢谢
如果配置错的话,应该在后台有错 找不到action