用jquery 如何获取servlet中输出的值
packagecom.wensheng.uidesign;importjava.io.IOException;importjava.io.PrintWriter;impo...
package com.wensheng.uidesign;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class UICardDataSourceServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//classNode表中的 实体表节点的 nodeCode
String nodeCode = request.getParameter("nodeCode");
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset=GBK");
UIBiz uibiz = new UIBiz();
StringBuilder outJson=uibiz.getUIListData2(nodeCode);
System.out.println("[UICardDataServlet].[outJson2]:"+outJson);
//在这里增加为没有表单数据的表添加表单界面数据。
if (outJson.length()<10){
System.out.println("[UICardDataServlet].[outJson]: 没有表单设计数据" );
//在这里进行表单设计数据初始化。
uibiz.buildDefaultCardData(nodeCode);
outJson= uibiz.getUICardDataByNodeCode(nodeCode);
}
PrintWriter out=response.getWriter();
out.print(outJson);
out.flush();
out.close();
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
} 展开
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class UICardDataSourceServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//classNode表中的 实体表节点的 nodeCode
String nodeCode = request.getParameter("nodeCode");
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset=GBK");
UIBiz uibiz = new UIBiz();
StringBuilder outJson=uibiz.getUIListData2(nodeCode);
System.out.println("[UICardDataServlet].[outJson2]:"+outJson);
//在这里增加为没有表单数据的表添加表单界面数据。
if (outJson.length()<10){
System.out.println("[UICardDataServlet].[outJson]: 没有表单设计数据" );
//在这里进行表单设计数据初始化。
uibiz.buildDefaultCardData(nodeCode);
outJson= uibiz.getUICardDataByNodeCode(nodeCode);
}
PrintWriter out=response.getWriter();
out.print(outJson);
out.flush();
out.close();
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
} 展开
展开全部
ajax
function getDaily1(cui){
var startTime=$('#daily_date_begin').val();
var endTime=$('#daily_date_end').val();
var v = $("#dept").val();
$.ajax({
url:'DQ_deptQueryAjax.do',
type:'post',
data:{date1:startTime,date2:endTime,dept:v},
cache:false,
dataType:'json',
timeout: 2000000,
beforeSend: function(){
},
complete: function(){
},
error: function(){
},
success:function(data){
if(data.states.length==1){
alert("NO ONE HAS WRITE DAILY");
}else{
$('#t').remove();
var startDatestr=$('#daily_date_begin').val();
var startstr=startDatestr.replace(/-/g,"/");
var endDatestr=$("#daily_date_end").val();
var endstr=endDatestr.replace(/-/g,"/");
var count=(new Date(endstr)-new Date(startstr))/(24*3600*1000);
var array_name=new Array(count+1);
var arr=new Array();
var arr_name=new Array();
arr.push("@@@@");
for(var i=0;i<data.user.length;i++){
arr.push(data.user[i].user_id);
arr_name.push(data.user[i].user_name);
}
var allitems=arr_name.length;
var nowpage=cui;
var pagesize=10;
var allpage=Math.ceil(1.0 * allitems /pagesize);
var startrow=(nowpage-1)*pagesize;
var endrow=nowpage*pagesize;
if(endrow>=allitems){
endrow=allitems;
}
var str='<table id="t" class="title" border="1">';
str=str+'<tr style="background: #DAF0F0"><th>---</th>';
for(var x=0;x<=count;x++){
var da=new Date(startstr);
var days=new Date(da.getTime()+x*24*3600*1000);
str=str+'<th>'+days.getYear()+'-'+(days.getMonth()+1)+'-'+days.getDate()+'</th>';
}
str=str+'</tr>';
str=str+'<tr style="background: #DAF0F0"><th>姓名</th>';
for(var x=0;x<=count;x++){
var da=new Date(startstr);
var days=new Date(da.getTime()+x*24*3600*1000);
var m="";
switch(days.getDay()){
case 1:
m="一";
break;
case 2:
m="二";
break;
case 3:
m="三";
break;
case 4:
m="四";
break;
case 5:
m="五";
break;
case 6:
m="六";
break;
case 0:
m="日";
break;
}
if(m=="六"||m=="日"){
array_name[x]="weekend";
}
str=str+'<th>星期'+m+'</th>';
}
str=str+'</tr>';
for(var n=startrow;n<endrow;n++)
{
str=str+'<tr><th style="background: #DAF0F0">'+arr_name[n]+'</th>';
for(var m=0;m<=count;m++){
var da=new Date(startstr);
var days=new Date(da.getTime()+m*24*3600*1000);
var ty=days.getDate();
var my=days.getMonth()+1;
if(my<9){
my='0'+my;
}
if(ty<10){
ty='0'+days.getDate();
}
var str1=days.getYear()+'-'+my+'-'+ty;
if(array_name[m]!=null){
str=str+'<td style="background: #ADD8E6"></td>';
}else{
for(var k=0;k<data.city.length;k++)
{
if(data.city[k].id==arr[n+1]&&data.city[k].date==str1)
{
str=str+'<td style="background:#CCCCCC"></td>';
break;
}if(k==data.city.length-1){
str=str+'<td style="background:red"></td>';
}
}
}
}
str=str+'</tr>';
}
str=str+"<tr class='title'><td colspan='"+(count+2)+"'>";
str=str+"当前页:"+nowpage+"/"+allpage+" ";
if(nowpage>1){
str=str+"<a href='Javascript: getDaily1(1)'>首 页</a> "
}
if(nowpage>1){
str=str+"<a href='Javascript: getDaily1("+(nowpage-1)+")'>上一页</a> ";
}
后台
package neusoft.team101.dms.action.dailyquery;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import neusoft.team101.dms.dao.imp.dailyquery.dailyQueryImpl;
import neusoft.team101.dms.domain.common.User;
import neusoft.team101.dms.domain.dailyquery.Dept;
import neusoft.team101.dms.json.JSONArray;
import neusoft.team101.dms.json.JSONObject;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class DQ_deptcheckQueryAjaxAction extends Action {
private dailyQueryImpl dept;
public void setDept(dailyQueryImpl dept) {
this.dept = dept;
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session=request.getSession();
User user = (User) session.getAttribute("user");
int user_id=Integer.parseInt(user.getUser_id());
PrintWriter out=response.getWriter();
String startTime=request.getParameter("date1");
String endTime=request.getParameter("date2");
int dept_id=Integer.parseInt(request.getParameter("dept"));
dept.setNowpage(Integer.parseInt(request.getParameter("num")));
List<Dept> dailys=dept.deptnocheckQuery(startTime, endTime,dept_id,user_id);
JSONObject json=new JSONObject();
JSONArray jsonMembers = new JSONArray();
for(Dept daily:dailys){
JSONObject member = new JSONObject();
member.put("dept_name", daily.getDPT_NAME());
member.put("user_name", daily.getUser_name());
if(daily.getE_mail()==null){
daily.setE_mail("暂无");
}
member.put("email",daily.getE_mail());
member.put("daily_date", daily.getDaily_date());
jsonMembers.put(member);
}
JSONArray jsonMembers1 = new JSONArray();
JSONObject member1 = new JSONObject();
member1.put("pagesize",dept.getPagesize());
member1.put("allpage", dept.getAllpage());
member1.put("allitems", dept.getAllitems());
member1.put("nowpage", dept.getNowpage());
jsonMembers1.put(member1);
json.put("check", jsonMembers);
json.put("page", jsonMembers1);
out.print(json);
return null;
}
}
function getDaily1(cui){
var startTime=$('#daily_date_begin').val();
var endTime=$('#daily_date_end').val();
var v = $("#dept").val();
$.ajax({
url:'DQ_deptQueryAjax.do',
type:'post',
data:{date1:startTime,date2:endTime,dept:v},
cache:false,
dataType:'json',
timeout: 2000000,
beforeSend: function(){
},
complete: function(){
},
error: function(){
},
success:function(data){
if(data.states.length==1){
alert("NO ONE HAS WRITE DAILY");
}else{
$('#t').remove();
var startDatestr=$('#daily_date_begin').val();
var startstr=startDatestr.replace(/-/g,"/");
var endDatestr=$("#daily_date_end").val();
var endstr=endDatestr.replace(/-/g,"/");
var count=(new Date(endstr)-new Date(startstr))/(24*3600*1000);
var array_name=new Array(count+1);
var arr=new Array();
var arr_name=new Array();
arr.push("@@@@");
for(var i=0;i<data.user.length;i++){
arr.push(data.user[i].user_id);
arr_name.push(data.user[i].user_name);
}
var allitems=arr_name.length;
var nowpage=cui;
var pagesize=10;
var allpage=Math.ceil(1.0 * allitems /pagesize);
var startrow=(nowpage-1)*pagesize;
var endrow=nowpage*pagesize;
if(endrow>=allitems){
endrow=allitems;
}
var str='<table id="t" class="title" border="1">';
str=str+'<tr style="background: #DAF0F0"><th>---</th>';
for(var x=0;x<=count;x++){
var da=new Date(startstr);
var days=new Date(da.getTime()+x*24*3600*1000);
str=str+'<th>'+days.getYear()+'-'+(days.getMonth()+1)+'-'+days.getDate()+'</th>';
}
str=str+'</tr>';
str=str+'<tr style="background: #DAF0F0"><th>姓名</th>';
for(var x=0;x<=count;x++){
var da=new Date(startstr);
var days=new Date(da.getTime()+x*24*3600*1000);
var m="";
switch(days.getDay()){
case 1:
m="一";
break;
case 2:
m="二";
break;
case 3:
m="三";
break;
case 4:
m="四";
break;
case 5:
m="五";
break;
case 6:
m="六";
break;
case 0:
m="日";
break;
}
if(m=="六"||m=="日"){
array_name[x]="weekend";
}
str=str+'<th>星期'+m+'</th>';
}
str=str+'</tr>';
for(var n=startrow;n<endrow;n++)
{
str=str+'<tr><th style="background: #DAF0F0">'+arr_name[n]+'</th>';
for(var m=0;m<=count;m++){
var da=new Date(startstr);
var days=new Date(da.getTime()+m*24*3600*1000);
var ty=days.getDate();
var my=days.getMonth()+1;
if(my<9){
my='0'+my;
}
if(ty<10){
ty='0'+days.getDate();
}
var str1=days.getYear()+'-'+my+'-'+ty;
if(array_name[m]!=null){
str=str+'<td style="background: #ADD8E6"></td>';
}else{
for(var k=0;k<data.city.length;k++)
{
if(data.city[k].id==arr[n+1]&&data.city[k].date==str1)
{
str=str+'<td style="background:#CCCCCC"></td>';
break;
}if(k==data.city.length-1){
str=str+'<td style="background:red"></td>';
}
}
}
}
str=str+'</tr>';
}
str=str+"<tr class='title'><td colspan='"+(count+2)+"'>";
str=str+"当前页:"+nowpage+"/"+allpage+" ";
if(nowpage>1){
str=str+"<a href='Javascript: getDaily1(1)'>首 页</a> "
}
if(nowpage>1){
str=str+"<a href='Javascript: getDaily1("+(nowpage-1)+")'>上一页</a> ";
}
后台
package neusoft.team101.dms.action.dailyquery;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import neusoft.team101.dms.dao.imp.dailyquery.dailyQueryImpl;
import neusoft.team101.dms.domain.common.User;
import neusoft.team101.dms.domain.dailyquery.Dept;
import neusoft.team101.dms.json.JSONArray;
import neusoft.team101.dms.json.JSONObject;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class DQ_deptcheckQueryAjaxAction extends Action {
private dailyQueryImpl dept;
public void setDept(dailyQueryImpl dept) {
this.dept = dept;
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session=request.getSession();
User user = (User) session.getAttribute("user");
int user_id=Integer.parseInt(user.getUser_id());
PrintWriter out=response.getWriter();
String startTime=request.getParameter("date1");
String endTime=request.getParameter("date2");
int dept_id=Integer.parseInt(request.getParameter("dept"));
dept.setNowpage(Integer.parseInt(request.getParameter("num")));
List<Dept> dailys=dept.deptnocheckQuery(startTime, endTime,dept_id,user_id);
JSONObject json=new JSONObject();
JSONArray jsonMembers = new JSONArray();
for(Dept daily:dailys){
JSONObject member = new JSONObject();
member.put("dept_name", daily.getDPT_NAME());
member.put("user_name", daily.getUser_name());
if(daily.getE_mail()==null){
daily.setE_mail("暂无");
}
member.put("email",daily.getE_mail());
member.put("daily_date", daily.getDaily_date());
jsonMembers.put(member);
}
JSONArray jsonMembers1 = new JSONArray();
JSONObject member1 = new JSONObject();
member1.put("pagesize",dept.getPagesize());
member1.put("allpage", dept.getAllpage());
member1.put("allitems", dept.getAllitems());
member1.put("nowpage", dept.getNowpage());
jsonMembers1.put(member1);
json.put("check", jsonMembers);
json.put("page", jsonMembers1);
out.print(json);
return null;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要用jquery得到后台的信息,那么你就得用ajax来提交
下面是jquery里的一种提交方式,url就是你要提交到后台的url地址,null就是你要传递的参数,callback(data)就是回调函数,在这里对你得到的后台信息进行其它操作
$.post( url,null,
function callback(data){
//这里面的data就是你后台要输出的
}) ;
下面是jquery里的一种提交方式,url就是你要提交到后台的url地址,null就是你要传递的参数,callback(data)就是回调函数,在这里对你得到的后台信息进行其它操作
$.post( url,null,
function callback(data){
//这里面的data就是你后台要输出的
}) ;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询