用myeclipse时,编译时显示代码无错,但是运行jsp的时候网页显示服务器遇到一个内部错误,无法满足请求
代码无错,不代表你的代码健壮性就很强,很明显,楼主你犯了个错误,你这是空指针异常,因为你获取到一个null,但是你仍然引用了这个null,所以报错了,就在SaveAction的execute里面
路径没写对!
src="/image/2jpg" 意思是项目根目录下的image文件夹下的2jpg;
如果你写src="image/2jpg",那就是当前WEB路径下的image文件夹下的2jpg;
路径有相对路径和绝对路径。如果你是JSP,又搞不清相对路径和绝对路径,我建议这样:
<%@ page language="java" import="javautil" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://javasuncom/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = requestgetContextPath();
String basePath = requestgetScheme() + "://"
+ requestgetServerName() + ":" + requestgetServerPort()
+ path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<title>Admin Maintain</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">
<script type="text/javascript" src="<%=basePath%>js/jquery-182js"></script>
</head>
<body style="margin: 0;padding: 0;" onload="init()">
<img src="<%=basePath %>image/2jpg"/>
<form action=Servlet method="post">
用户名:<input type="text" name=username><br>
密码:<input type="password" name=password><br>
<input type="submit" value=登录>
<input type="button" value=取消>
</form>
<body>
是的,没错,
JSP中,
<%
String path = requestgetContextPath();
String basePath = requestgetScheme() + "://"
+ requestgetServerName() + ":" + requestgetServerPort()
+ path + "/";
%>
这端代码是获取Web当前路径;
然后下面 <img src="<%=basePath %>image/2jpg"/>
意思就是你当前Web路径(也就是WebRoot目录)下的imge目录下的2jpg
有可能是URL不对导致造成的
在td标签里是用background可以实现:
<td background="" width="宽" height="高"> </td>
定义和用法
background 简写属性在一个声明中设置所有的背景属性。
可以设置如下属性:
background-color
background-position
background-size
background-repeat
background-origin
background-clip
background-attachment
background-image
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>个人主页</title>
<style type="text/css">
<!--
body {background-image: url(<%=requestgetContextPath()%>/images/1jpg);
}
-->
</style>
</head>
<frameset rows="30%," frameborder="no">
<frame src="ddjsp" name="dd" scrolling="no">
<frame src="ssjsp" name="ss" scolling="no">
</frameset>
<body >
</body>
</html>
要不用css试试
解决方法一:
<filter>
<filter-name>struts2</filter-name>
<filter-class>
orgapachestruts2dispatcherFilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern> / </url-pattern>
</filter-mapping>
改为
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>jsp</url-pattern>
</filter-mapping>
解决方法二:
在strutsxml文件中修改,添加
<constant name="strutsactionextension" value="action"></constant>
还是路径的问题。你的jsp和不是在服务器的根下面吧。
肯定是在某一个目录下面。
因为你增加了
<base href="<%=basePath%>">代码。
所以页面中间的所有url路径都是相对于你整个网站的根而不是你当前页面的。
假如你的jsp页面和都在网站根目录下的aa目录下面
建议你写成如下样子
<img src="/aa/13207429619151gif"></img>
都是base惹的错。你好好搞懂<base href="<%=basePath%>">的含义就明白了
0条评论