Javaservlet重定向
你好,我正在努力使一个在线电视节目跟踪器的前端是这样实现的 您输入一个节目名称,背景图像发生变化,小图片向下显示,就像上面给出的网站一样,请参考 我面临的问题是,我有一个名为servlet的servlet,一旦按下按钮就会调用它,因此从页面重定向,一旦我从servlet重定向回来,html页面上完成的所有计算都会消失 这是我搜索的htmlJavaservlet重定向,java,javascript,jquery,html,servlets,Java,Javascript,Jquery,Html,Servlets,你好,我正在努力使一个在线电视节目跟踪器的前端是这样实现的 您输入一个节目名称,背景图像发生变化,小图片向下显示,就像上面给出的网站一样,请参考 我面临的问题是,我有一个名为servlet的servlet,一旦按下按钮就会调用它,因此从页面重定向,一旦我从servlet重定向回来,html页面上完成的所有计算都会消失 这是我搜索的html <html> <head> <meta content="text/html;charset=utf-8" http-
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
<link href='http://fonts.googleapis.com/css?family=Special+Elite' rel='stylesheet' type='text/css'>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>
<style>
body{
background-color: #ffffff;
}
#custom-search-input {
margin:0;
margin-top: 10px;
padding: 0;
}
#custom-search-input .search-query {
padding-right: 3px;
padding-right: 4px \9;
padding-left: 3px;
padding-left: 4px \9;
/* IE7-8 doesn't have border-radius, so don't indent the padding */
margin-bottom: 0;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
#custom-search-input button {
border: 0;
background: none;
/** belows styles are working good */
padding: 2px 5px;
margin-top: 2px;
position: relative;
left: -28px;
/* IE7-8 doesn't have border-radius, so don't indent the padding */
margin-bottom: 0;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
color:#D9230F;
}
.search-query:focus + button {
z-index: 3;
}
.bg
{
position: fixed;
top: 0;
left: 0;
z-index: -1;
width: 100%;
height: 100%;
background-image: url(images/126.42.jpg);
background-size: cover;
background-position: 50% 0;
-webkit-filter: blur(3px);
-moz-filter: blur(3px);
filter: blur(3px);
filter: alpha(Opacity=10);
opacity: .6;
-webkit-transition: all .3s;
-moz-transition: all .3s;
-o-transition: all .3s;
transition: all .3s;
-webkit-transform: translate3d(0,0,0);
-moz-transform: translate3d(0,0,0);
-ms-transform: translate3d(0,0,0);
-o-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
</style>
<script>
var val;
function myFunction()
{
val = document.getElementById("tvshow").value;
var i=0;
var data = {results: []};
var imurl;
$.ajax ({
type: "GET",
url: 'http://api.trakt.tv/search/shows.json/58269f85e4333c18234bb68b93397031/'+ val +'/5/seasons/',
dataType: "jsonp",
json: "callbackname",
crossDomain : true,
success: function (result) {
$.each(result, function (i, show) {
// write everything in an array
data.results.push({id: this.tvdb_id, text: this.title, runtime: this.runtime, poster: this.images.poster, bg: this.images.fanart});
console.log(this.title);
//selectedTVshow = this.title;
// results = data.results;
// return array
if(i==0)
{
imurl=this.images.fanart;
i++;
}
$('.bg').css('background-image','url('+ imurl +')');
//imurl=this.images.fanart;
})
},
error: function (data) {
console.log('error');
}
})
}
</script>
<title>T.V Dose</title>
身体{
背景色:#ffffff;
}
#自定义搜索输入{
保证金:0;
边缘顶部:10px;
填充:0;
}
#自定义搜索输入。搜索查询{
右侧填充:3px;
右填充:4px\9;
左:3倍;
左侧填充:4px\9;
/*IE7-8没有边框半径,所以不要缩进填充*/
页边距底部:0;
-webkit边界半径:3px;
-moz边界半径:3px;
边界半径:3px;
}
#自定义搜索输入按钮{
边界:0;
背景:无;
/**下面的样式很好用*/
填充物:2px 5px;
边缘顶部:2倍;
位置:相对位置;
左:-28px;
/*IE7-8没有边框半径,所以不要缩进填充*/
页边距底部:0;
-webkit边界半径:3px;
-moz边界半径:3px;
边界半径:3px;
颜色:#D9230F;
}
.搜索查询:焦点+按钮{
z指数:3;
}
.bg
{
位置:固定;
排名:0;
左:0;
z指数:-1;
宽度:100%;
身高:100%;
背景图片:url(images/126.42.jpg);
背景尺寸:封面;
背景位置:50%0;
-webkit过滤器:模糊(3px);
-moz过滤器:模糊(3px);
过滤器:模糊(3px);
过滤器:α(不透明度=10);
不透明度:.6;
-webkit转换:all.3s;
-moz转换:all.3s;
-o-transition:all.3s;
过渡:全部3秒;
-webkit转换:translate3d(0,0,0);
-moz变换:translate3d(0,0,0);
-ms变换:translate3d(0,0,0);
-o变换:translate3d(0,0,0);
变换:translate3d(0,0,0);
}
var-val;
函数myFunction()
{
val=document.getElementById(“tvshow”).value;
var i=0;
var data={results:[]};
var-imurl;
$.ajax({
键入:“获取”,
网址:'http://api.trakt.tv/search/shows.json/58269f85e4333c18234bb68b93397031/“+val+”/5/季节/”,
数据类型:“jsonp”,
json:“callbackname”,
跨域:是的,
成功:功能(结果){
$。每个(结果、功能(i、显示){
//将所有内容写入数组
data.results.push({id:this.tvdb_id,text:this.title,runtime:this.runtime,poster:this.images.poster,bg:this.images.fanart});
console.log(this.title);
//selectedTVshow=this.title;
//结果=数据。结果;
//返回数组
如果(i==0)
{
imurl=this.images.fanart;
i++;
}
$('.bg').css('background-image','url('+imurl+'));
//imurl=this.images.fanart;
})
},
错误:函数(数据){
console.log('error');
}
})
}
电视剂量
下面是正在使用的Servlet Post方法,正确使用了注释
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession newSession=request.getSession(false);
if(newSession==null)
{
//response.sendRedirect("http://localhost:8080/Jotter2/");
}
else
{
String showname = request.getParameter("show");
Document sid = Jsoup.connect("http://services.tvrage.com/feeds/search.php?show="+showname+"&exact=1").timeout(1000*100).get();
Elements show_id=sid.select("showid");
String shwname=show_id.first().text();
System.out.print(shwname);
//System.out.print(sid);
String sname=sid.select("name").first().text();
Shows temp= new Shows();
int id=Integer.parseInt(shwname);
temp.setShow_id(id);
temp.setTitle(sname);
Login usr = (Login)newSession.getAttribute("user");
temp.setPid(usr.getPid());
DataAccessUtil.save(temp);
Document doc = Jsoup.connect("http://services.tvrage.com/feeds/episode_list.php?sid="+id+"").get();
System.out.print(doc);
Elements ep_name=doc.select("title");
Elements air_date=doc.select("airdate");
int count=ep_name.size();
Episodes[] ep_temp=new Episodes[count];
int i=0;
while(i<count)
{
ep_temp[i]=new Episodes();
i++;
}
int a=0;
String date_air;
SimpleDateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd");
while(a<count)
{
ep_temp[a].setEp_name(ep_name.get(a).text());
ep_temp[a].setPid(usr.getPid());
ep_temp[a].setS_id(temp.getSid());
date_air=air_date.get(a).text();
Date date = null;
try {
date = dt1.parse(date_air);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
ep_temp[a].setAir_date(sqlDate);
DataAccessUtil.save(ep_temp[a]);
a++;
}
}
@覆盖
受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应)
抛出ServletException、IOException
{
HttpSession newSession=request.getSession(false);
if(newSession==null)
{
//response.sendRedirect(“http://localhost:8080/Jotter2/");
}
其他的
{
字符串showname=request.getParameter(“show”);
文档sid=Jsoup.connect(“http://services.tvrage.com/feeds/search.php?show=“+showname+”&exact=1”).timeout(1000*100).get();
元素show_id=sid。选择(“showid”);
字符串shwname=show_id.first().text();
系统输出打印(shwname);
//系统输出打印(sid);
字符串sname=sid.select(“name”).first().text();
Shows temp=新的Shows();
int id=Integer.parseInt(shwname);
温度设置显示id(id);
温度设置标题(sname);
Login usr=(Login)newSession.getAttribute(“用户”);
temp.setPid(usr.getPid());
DataAccessUtil.save(临时);
Document doc=Jsoup.connect(“http://services.tvrage.com/feeds/episode_list.php?sid=“+id+”).get();
系统输出打印(doc);
元素ep_名称=文件选择(“标题”);
元素air_date=doc.select(“airdate”);
int count=ep_name.size();
剧集[]ep_temp=新剧集[计数];
int i=0;
while(i因为您使用的是ajax,所以不应该在提交时刷新它。您应该在myFunction()的末尾返回false
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession newSession=request.getSession(false);
if(newSession==null)
{
//response.sendRedirect("http://localhost:8080/Jotter2/");
}
else
{
String showname = request.getParameter("show");
Document sid = Jsoup.connect("http://services.tvrage.com/feeds/search.php?show="+showname+"&exact=1").timeout(1000*100).get();
Elements show_id=sid.select("showid");
String shwname=show_id.first().text();
System.out.print(shwname);
//System.out.print(sid);
String sname=sid.select("name").first().text();
Shows temp= new Shows();
int id=Integer.parseInt(shwname);
temp.setShow_id(id);
temp.setTitle(sname);
Login usr = (Login)newSession.getAttribute("user");
temp.setPid(usr.getPid());
DataAccessUtil.save(temp);
Document doc = Jsoup.connect("http://services.tvrage.com/feeds/episode_list.php?sid="+id+"").get();
System.out.print(doc);
Elements ep_name=doc.select("title");
Elements air_date=doc.select("airdate");
int count=ep_name.size();
Episodes[] ep_temp=new Episodes[count];
int i=0;
while(i<count)
{
ep_temp[i]=new Episodes();
i++;
}
int a=0;
String date_air;
SimpleDateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd");
while(a<count)
{
ep_temp[a].setEp_name(ep_name.get(a).text());
ep_temp[a].setPid(usr.getPid());
ep_temp[a].setS_id(temp.getSid());
date_air=air_date.get(a).text();
Date date = null;
try {
date = dt1.parse(date_air);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
ep_temp[a].setAir_date(sqlDate);
DataAccessUtil.save(ep_temp[a]);
a++;
}
}
function myFunction() {
.................
return false;
}