servlets

How to access a servlet variable inside javascript

谁说胖子不能爱 提交于 2020-01-01 09:16:16
问题 I have a servlet which has a variable which holds a JSON string. JSONObject obj = new JSONObject(); obj.put("parameter", jsonList); request.setAttribute("jsonstring", obj.toString()); RequestDispatcher rd = request.getRequestDispatcher("/file.jsp"); rd.forward(request, response); Now I am forwarding my request and response objects to a JSP page which contains a JS file. How can I access the value of jsonstring variable inside the JS file.As I need to parse my JSON string further using jQuery.

Jetty http session is always null (Embedded Container, ServletHolder)

时光毁灭记忆、已成空白 提交于 2020-01-01 08:56:27
问题 I am trying to implement a simple servlet which uses a HTTP session in an embedded jetty (7.3.0 v20110203) container. To start jetty I use the following code: Server server = new Server(12043); ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS); handler.setContextPath("/"); server.setHandler(handler); ServletHolder holder = new ServletHolder(new BaseServlet()); handler.addServlet(holder, "/*"); server.start(); server.join(); The servlet acquires a

why tomcat does not require restart when jsp is changed

梦想与她 提交于 2020-01-01 08:42:36
问题 I have been using JSP,Servlet for quite sometime. I know that whenever we change anything in Servlet we need to restart Tomcat Server to get the changes. Where as in case of JSP change, tomcat does not require restart. As per my knowledge JSP page gets converted into Servlet only when compiled. So, after all its a Servlet .So, How does it works without Tomcat restart. I have knowledge of cases when a JSP page gets compiled like on first time access after server restart etc. 回答1: Because by

why tomcat does not require restart when jsp is changed

北城余情 提交于 2020-01-01 08:41:47
问题 I have been using JSP,Servlet for quite sometime. I know that whenever we change anything in Servlet we need to restart Tomcat Server to get the changes. Where as in case of JSP change, tomcat does not require restart. As per my knowledge JSP page gets converted into Servlet only when compiled. So, after all its a Servlet .So, How does it works without Tomcat restart. I have knowledge of cases when a JSP page gets compiled like on first time access after server restart etc. 回答1: Because by

What is the exact uses of REALM term in security?

倖福魔咒の 提交于 2020-01-01 07:36:04
问题 The term REALM has an overloaded & confusing using in security, what is the exact uses of this term in security? 回答1: Take a look at this in-depth explanation: Security Realm A security realm is a mechanism used for protecting Web application resources. It gives you the ability to protect a resource with a defined security constraint and then define the user roles that can access the protected resource. I hope this helped! 回答2: In simple terms when you want to access a protected resource you

Kill user session

馋奶兔 提交于 2020-01-01 05:51:09
问题 I have 3 tabs. Home, tab1, tab2. When user launches the app, its directed to Home tab & I create a new session using HttpSession session = request.getSession(); When user browses to other tabs, I maintain the session using HttpSession session = request.getSession(false); Now if the user click back on Home tab, I want to destroy the previous session and start fresh with new session. Please tell me how to do it? 回答1: Replace the code behind home tab by HttpSession session = request.getSession()

How do I obtain a new stateful session bean in a servlet thread?

我的梦境 提交于 2020-01-01 05:35:07
问题 I'm experimenting with EJB3 I would like to inject a stateful session bean into a servlet, so that each user that hits the servlet would obtain a new bean. Obviously, I can't let the bean be an instance variable for the servlet, as that will be shared. And apparantly injecting local variables isn't allowed. I can use the new operator to create a bean, but that doesn't seem the right approach. Is there a right way to do this? It seems like what I'm trying to do is fairly straightforward, after

IntelliJ Idea: Deploy a simple Java servlet (no JSP) to Tomcat 7

≯℡__Kan透↙ 提交于 2020-01-01 04:31:09
问题 I tried following the tutorial here to deploy a servlet but that only works if you specify a JSP file. The problem is that without the JSP, I don't know what to set the Startup Page in the Tomcat Run/Debug configuration. So any idea what to do? Thanks! 回答1: You should define a servlet-mapping in the web.xml like this: Then add the url-pattern to the server root URL: 回答2: Set it to your servlet mapping. IMO opening new browser window every time you start the server is a PITA. 来源: https:/

Get URL of the request sender with HttpServletRequest

China☆狼群 提交于 2020-01-01 04:16:09
问题 How do you get the source domain using HttpServletRequest? Source domain is the requester's domain. Thanks. 回答1: You could do either // gets client (browser)'s hostname String host = request.getRemoteHost(); OR // get the server's domain name. String domain = new URL(request.getRequestURL().toString()).getHost(); 回答2: Hostname request InetAddress ip = InetAddress.getLocalHost(); String hostname = ip.getHostName(); out.print("Your current IP address : " + ip+"\n"); out.print("Your current

CSS file is not loading?

主宰稳场 提交于 2020-01-01 03:47:11
问题 I am having a JSP file with the below codes <HTML> <head> <link rel="stylesheet" type="text/css" href="../CSS/home.css" /> <link rel="stylesheet" type="text/css" href="../CSS/left.css" /> <script type="text/javascript" src="../js/friend_request.js"></script> </head> <body> <div class="menu"> <form name="search_form" method="post"> <table id="menutabel" class="color"> <tr> <td class="alt"><A class="one"HREF="home.jsp">Home</A></td> <td class="alt" ><A class="one"HREF="../HTML/falbum.html">My