Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read xml file in grails?
    primarykey
    data
    text
    <p>I am very new to grails and perhaps it would be the most simplest of questions that I am asking. I am creating a very simple application for self-learning where I created a login page. On successful login,the xml file should be read and the output should be displayed. Can anyone please illustrate this with a sample example. Also please tell what should be the folder location for the xml file?Below is my code: <strong>UserController.groovy</strong></p> <pre><code>class UserController { def index = { } def login = { def user = User.findWhere(username:params['username'], password:params['password']) session.user = user if (user) { redirect(action:display) } else { redirect(url:"http://localhost:8080/simple-login/") } } def display = { def stream = getClass().classLoader.getResourceAsStream("grails-app/conf/sample.xml") return [data: XML.parse(stream)] } } </code></pre> <p><strong>myxml.gsp</strong></p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;p&gt;Please find the details below:&lt;/p&gt; &lt;p&gt;${data}&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>URLMappings.groovy</strong></p> <pre><code>class UrlMappings { static mappings = { "/user/login" (controller: "user" ,action: "login") "/user/display"(controller:"user" ,action:"display") "/"(view:"/index") "500"(view:'/error') } } </code></pre> <p>Now that I already have index.gsp as the first page that appears when user login, is it possible to specify more than one view in URLMappings? Also as suggested in one of the replies, if I have to define an action named "myxml" and direct to a url such as "/controller"/myxml where would that be? Please help! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload