小编Mar*_*ina的帖子

用gson反序列化json字符串

我的java servlet以这种方式返回一个json字符串:

Gson gson = new Gson();     
String lista = gson.toJson(utenti);
System.out.println(lista);
request.setAttribute("lista", lista);
request.getRequestDispatcher("GestioneUtenti.jsp").forward(request, response);
Run Code Online (Sandbox Code Playgroud)

现在,在jsp页面中我想再次使用我的arrayList.我试着这样做:

<%
String lista = (String)request.getAttribute("lista");
Gson gson = new Gson();
ArrayList<Utente> users = gson.fromJson(lista, TypeToken.get(new ArrayList<Utente>().getClass()).getType());        
out.println(users.get(0).getUsername());
%>
Run Code Online (Sandbox Code Playgroud)

我有这个例外:

java.lang.ClassCastException: com.google.gson.internal.StringMap cannot be cast to classi.Utente
Run Code Online (Sandbox Code Playgroud)

能帮你吗?如果我想念一些细节告诉我!谢谢 :-)

java json jsp arraylist gson

5
推荐指数
1
解决办法
5495
查看次数

Jquery ui组合框(自动完成)消失

我正在尝试这样做http://jqueryui.com/autocomplete/#combobox 问题是,当我用鼠标移动选项时,选项将消失,它出现了建议:"x不匹配任何item"其中x是我在组合框中写的字母.现在我发布网站上的脚本:

  (function( $ ) {
$.widget( "ui.combobox", {
  _create: function() {
    var input,
      that = this,
      wasOpen = false,
      select = this.element.hide(),
      selected = select.children( ":selected" ),
      value = selected.val() ? selected.text() : "",
      wrapper = this.wrapper = $( "<span>" )
        .addClass( "ui-combobox" )
        .insertAfter( select );

    function removeIfInvalid( element ) {
      var value = $( element ).val(),
        matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( value ) + "$", "i" ),
        valid = false;
      select.children( "option" ).each(function() { …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-ui jquery-autocomplete jquery-ui-autocomplete

5
推荐指数
1
解决办法
7016
查看次数

管理FileUpload控件上的编辑

我有一个产品页面.我想将我的产品添加到我的数据库中,我也想更新我的产品.我的图像有问题.当我插入产品时,可以正常使用..在我的aspx页面中,我有以下代码:

<span>
  <asp:FileUpload ID="files" runat="server" AllowMultiple="true" />
</span>
<div runat="server" id="previewImages"></div>
Run Code Online (Sandbox Code Playgroud)

当我保存我的产品时,在代码后面我有这个代码:

string filenm = string.Empty;
HttpFileCollection fileCollection = Request.Files;
for (int i = 0; i < fileCollection.Count; i++)
{
    HttpPostedFile uploadfile = fileCollection[i];
    if (uploadfile.ContentLength > 0)
    {
       string filename = uploadfile.FileName;
       System.IO.Directory.CreateDirectory(Server.MapPath("immScarpe/" + txtStyle.Text));
       file.SaveAs(Server.MapPath("immScarpe/" + txtStyle.Text + "/") + fileName);
       //this is pseudo-code
       INSERT INTO PRODUCT_IMM (IdProduct, Path) VALUES (Id, "immScarpe/" + txtStyle.Text + "/" + fileName)
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,问题是我可以编辑保存的产品.当我单击产品的编辑按钮时,我必须加载它的所有数据并让用户修改它们.还有图像.

主要问题是:如何在asp:FileUpload控件中加载保存的图像?

我想做的另一件事是在插入和编辑中显示图像预览...

我想做的一个例子就是亚马逊所做的事情 在此输入图像描述

但是,如果只有一个FileUpload可以使用AllowMultiple = true

如果有必要,我愿意使用其他技术,如javascript,jquery和Ajax

c# asp.net ajax html5 file-upload

5
推荐指数
1
解决办法
1572
查看次数

mysql事件不起作用

嗨,我将此事件存储在信息架构的事件表中:

event_catalog:def
event_schema: m4af
event_name:aggiornaGiorni
definer:root@localhost
timezone:system
event_body:sql
event_definition:update m4af.utentibloccati set giorni=giorni+1
event_type:recurring
execute at: null
interval_value:1
interval_field:day
sql_mode:STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
starts:2012-11-26 11:40:41
ends:null
status:enabled
on_completion:not preserve
created:2012-11-26 11:40:41
last_altered:2012-11-26 11:40:41
 last_executed:2012-11-26 11:40:41
event_comment: ""
originator:0
character_set_client:utf8
collocation_connection:utf8_general_ci
database_collation:utf8_general_ci
Run Code Online (Sandbox Code Playgroud)

为什么此事件不会增加名为utentibloccati的表的值日?

mysql events information-schema

3
推荐指数
1
解决办法
3490
查看次数

com.mysql.jdbc.PacketTooBigException

我有一个大问题!当我这样做:

 String query = "SELECT * FROM utente WHERE confermato=1 and Username='" + username
            + "' AND Password='" + password + "'";

        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection con = DriverManager.getConnection("ind_server/nome_db","user","password");
Run Code Online (Sandbox Code Playgroud)

Eclipse给了我这个错误:

Packet for query is too large (4739923 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
Run Code Online (Sandbox Code Playgroud)

那么,首先:这个查询真的那么大?-.-之后:我必须在ssh中使用哪些命令?这是我第一次有这个东西!提前致谢!

我在服务器上没有root权限!

我试过用这个:

 mysql>set global max_allowed_packet=32*1024*1024;
Run Code Online (Sandbox Code Playgroud)

但它给了我这个错误:ERROR 1227(42000):访问被拒绝; 您需要此操作的SUPER权限

编辑

现在我已将max_allowed_pa​​cket变量修改为32MB.停止并重新启动服务器但是eclipse给了我同样的错误!

我能做什么?

java mysql database database-connection jdbc

3
推荐指数
2
解决办法
3万
查看次数

角度-将目标添加到路由器导航

我要做的是在另一个选项卡或弹出窗口中打开路由器导航的目标。我的指示是这样的:

private router: Router;
this.router.navigate(['/page', id]);
Run Code Online (Sandbox Code Playgroud)

在路由中,我有:

 const routes: Routes = [
{
    path: '',
    component: LayoutComponent,
    children: [
        { path: 'page', loadChildren: './page/page.module#PageModule' }
    ]
}
];
Run Code Online (Sandbox Code Playgroud)

我想在另一个标签或弹出窗口中打开此链接。我能做什么?


这是page.ts的代码

@Component({
 selector: 'app-etichetta',
 templateUrl: './page.component.html',
 styleUrls: ['./page.component.scss'],
 animations: [routerTransition()]
})
export class PageComponent implements OnInit {


 constructor(private router: Router,
    private route: ActivatedRoute,
    public appService: AppService) {
 }


 ngOnInit() {

 }
}
Run Code Online (Sandbox Code Playgroud)

这是HTML:

<div [@routerTransition]>
  <br>
  <div class="row">

  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

angular angular4-router

2
推荐指数
2
解决办法
4273
查看次数

带有 java.lang.IllegalStateException 的 Servlet:提交响应后无法转发

在我的 servlet 我有这个代码:

protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub

    Utils.CheckSession(request,response);

    String op = request.getParameter("op");
    int DaysToAdd = request.getParameter("daysToAdd") != null ? Integer.valueOf(request.getParameter("daysToAdd")) :  0;

    ArrayList<Giorno> giorni = new ArrayList<Giorno>();

    /*HERE I FILL ArrayList giorni and calculate other variables*/


    if ("cal".equals(op))
    {
        request.setAttribute("giorni", giorni);
        request.setAttribute("daysToAdd", DaysToAdd);
        request.getRequestDispatcher("GestioneCalendario.jsp").forward(request, response);

    }
    else if("utente".equals(op))
    {
        // ricavare abbonamento dell'utente
        String idu = (String) request.getAttribute("idu");
        Abbonamento a = null;
        int iDa = Utils.getIdAbbonamentoAttivoUtente(idu);
        a = Utils.getAbbonamentoFromId(iDa); …
Run Code Online (Sandbox Code Playgroud)

java servlets httpresponse httprequest

1
推荐指数
1
解决办法
4万
查看次数

Java时间:我不想看到秒

我有一个名为Lezione具有time类型属性的类Time.这个属性填充了我的数据库(mysql)中表Lezione的属性时间的值.此外,数据库中的属性时间是类型TIME.

现在:我对db进行查询:

 select * from lezione as l
Run Code Online (Sandbox Code Playgroud)

然后我创建了一个Lezione类型的对象,并设置了所有属性.我这样做的时间:

l.settime(rs2.getTime(3));
Run Code Online (Sandbox Code Playgroud)

而这个作品.

当我尝试用l.gettime()打印值时,我得到值(fe) 13:00:00

我想要的是 13:00

我尝试了表达式

l.gettime().getHours()+":"+l.gettime().getMinutes()
Run Code Online (Sandbox Code Playgroud)

(它使用折旧的方法),但它打印13:0(我想如果我想打印09:02它会打印9:2)

那我该怎么办?

java time

-1
推荐指数
1
解决办法
126
查看次数